|
|
@ -80,41 +80,13 @@ class Command: public QObject { |
|
|
|
QString result() { |
|
|
|
QString result() { |
|
|
|
return _result; |
|
|
|
return _result; |
|
|
|
} |
|
|
|
} |
|
|
|
protected: |
|
|
|
static void realMouseClick(QWebFrame* frame, QString selector) { |
|
|
|
void sleep(int s) { |
|
|
|
QWebElement element(find(frame, selector)); |
|
|
|
QTime dieTime= QTime::currentTime().addSecs(s); |
|
|
|
|
|
|
|
while (QTime::currentTime()<dieTime) |
|
|
|
|
|
|
|
QCoreApplication::processEvents(QEventLoop::AllEvents, 100); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
QWebElement find(QWebFrame* frame, QString selector, Logger& log, |
|
|
|
|
|
|
|
int repeat = 2, int sleepsec = 1) { |
|
|
|
|
|
|
|
QWebElement element; |
|
|
|
|
|
|
|
element = find1(frame, selector, log, repeat, sleepsec); |
|
|
|
|
|
|
|
if (!element.isNull()) return element; |
|
|
|
|
|
|
|
element = find1(frame->page()->currentFrame(), selector, log, repeat, sleepsec); |
|
|
|
|
|
|
|
if (!element.isNull()) return element; |
|
|
|
|
|
|
|
element = find1(frame->page()->mainFrame(), selector, log, repeat, sleepsec); |
|
|
|
|
|
|
|
if (!element.isNull()) return element; |
|
|
|
|
|
|
|
return element; |
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
QWebElement find1(QWebFrame* frame, QString selector, Logger& log, |
|
|
|
|
|
|
|
int repeat = 5, int sleepsec = 1) { |
|
|
|
|
|
|
|
QWebElement element; |
|
|
|
|
|
|
|
for (int i=0; i<repeat; ++i) { |
|
|
|
|
|
|
|
element = frame->findFirstElement(selector); |
|
|
|
|
|
|
|
if (!element.isNull()) return element; |
|
|
|
|
|
|
|
Q_FOREACH(QWebFrame* childFrame, frame->childFrames()) { |
|
|
|
|
|
|
|
element = find1(childFrame, selector, log, 1, 0); |
|
|
|
|
|
|
|
if (!element.isNull()) return element; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (sleepsec) sleep(sleepsec); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return element; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
void realMouseClick(QWebFrame* frame, QString selector, Logger& log) { |
|
|
|
|
|
|
|
QWebElement element(find(frame, selector, log)); |
|
|
|
|
|
|
|
if (element.isNull()) throw ElementNotFound(selector); |
|
|
|
if (element.isNull()) throw ElementNotFound(selector); |
|
|
|
QWidget* web(frame->page()->view()); |
|
|
|
realMouseClick(element); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
static void realMouseClick(const QWebElement& element) { |
|
|
|
|
|
|
|
QWidget* web(element.webFrame()->page()->view()); |
|
|
|
QRect elGeom=element.geometry(); |
|
|
|
QRect elGeom=element.geometry(); |
|
|
|
QPoint elPoint=elGeom.center(); |
|
|
|
QPoint elPoint=elGeom.center(); |
|
|
|
int elX=elPoint.x(); |
|
|
|
int elX=elPoint.x(); |
|
|
@ -129,8 +101,8 @@ class Command: public QObject { |
|
|
|
if (elY>webHeight) |
|
|
|
if (elY>webHeight) |
|
|
|
pixelsToScrolDown = //the +10 scrolls a bit further
|
|
|
|
pixelsToScrolDown = //the +10 scrolls a bit further
|
|
|
|
elY-webHeight+elGeom.height()/2+10; |
|
|
|
elY-webHeight+elGeom.height()/2+10; |
|
|
|
frame->setScrollBarValue(Qt::Horizontal, pixelsToScrolRight); |
|
|
|
element.webFrame()->setScrollBarValue(Qt::Horizontal, pixelsToScrolRight); |
|
|
|
frame->setScrollBarValue(Qt::Vertical, pixelsToScrolDown); |
|
|
|
element.webFrame()->setScrollBarValue(Qt::Vertical, pixelsToScrolDown); |
|
|
|
QPoint pointToClick(elX-pixelsToScrolRight, elY-pixelsToScrolDown); |
|
|
|
QPoint pointToClick(elX-pixelsToScrolRight, elY-pixelsToScrolDown); |
|
|
|
QMouseEvent pressEvent(QMouseEvent::MouseButtonPress, |
|
|
|
QMouseEvent pressEvent(QMouseEvent::MouseButtonPress, |
|
|
|
pointToClick, Qt::LeftButton, Qt::LeftButton, |
|
|
|
pointToClick, Qt::LeftButton, Qt::LeftButton, |
|
|
@ -142,6 +114,39 @@ class Command: public QObject { |
|
|
|
QCoreApplication::sendEvent(web, &releaseEvent); |
|
|
|
QCoreApplication::sendEvent(web, &releaseEvent); |
|
|
|
QCoreApplication::processEvents(); |
|
|
|
QCoreApplication::processEvents(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
static void sleep(int s) { |
|
|
|
|
|
|
|
QTime dieTime= QTime::currentTime().addSecs(s); |
|
|
|
|
|
|
|
while (QTime::currentTime()<dieTime) |
|
|
|
|
|
|
|
QCoreApplication::processEvents(QEventLoop::AllEvents, 100); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
public: |
|
|
|
|
|
|
|
static QWebElement find(QWebFrame* frame, QString selector, |
|
|
|
|
|
|
|
int repeat = 2, int sleepsec = 1) { |
|
|
|
|
|
|
|
QWebElement element; |
|
|
|
|
|
|
|
element = find1(frame, selector, repeat, sleepsec); |
|
|
|
|
|
|
|
if (!element.isNull()) return element; |
|
|
|
|
|
|
|
element = find1(frame->page()->currentFrame(), selector, |
|
|
|
|
|
|
|
repeat, sleepsec); |
|
|
|
|
|
|
|
if (!element.isNull()) return element; |
|
|
|
|
|
|
|
element = find1(frame->page()->mainFrame(), selector, |
|
|
|
|
|
|
|
repeat, sleepsec); |
|
|
|
|
|
|
|
if (!element.isNull()) return element; |
|
|
|
|
|
|
|
return element; |
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static QWebElement find1(QWebFrame* frame, QString selector, |
|
|
|
|
|
|
|
int repeat = 5, int sleepsec = 1) { |
|
|
|
|
|
|
|
QWebElement element; |
|
|
|
|
|
|
|
for (int i=0; i<repeat; ++i) { |
|
|
|
|
|
|
|
element = frame->findFirstElement(selector); |
|
|
|
|
|
|
|
if (!element.isNull()) return element; |
|
|
|
|
|
|
|
Q_FOREACH(QWebFrame* childFrame, frame->childFrames()) { |
|
|
|
|
|
|
|
element = find1(childFrame, selector, 1, 0); |
|
|
|
|
|
|
|
if (!element.isNull()) return element; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (sleepsec) sleep(sleepsec); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return element; |
|
|
|
|
|
|
|
} |
|
|
|
void log(Script*); |
|
|
|
void log(Script*); |
|
|
|
bool _log; |
|
|
|
bool _log; |
|
|
|
protected: |
|
|
|
protected: |
|
|
@ -715,7 +720,7 @@ class Do: public Command { |
|
|
|
} |
|
|
|
} |
|
|
|
bool execute(Script* script, QWebFrame* frame) { |
|
|
|
bool execute(Script* script, QWebFrame* frame) { |
|
|
|
Logger log(this, script); |
|
|
|
Logger log(this, script); |
|
|
|
QWebElement element(find(frame, _selector, log)); |
|
|
|
QWebElement element(find(frame, _selector)); |
|
|
|
if (element.isNull()) throw ElementNotFound(_selector); |
|
|
|
if (element.isNull()) throw ElementNotFound(_selector); |
|
|
|
_result = |
|
|
|
_result = |
|
|
|
element.evaluateJavaScript(script->replacevars(_javascript)).toString(); |
|
|
|
element.evaluateJavaScript(script->replacevars(_javascript)).toString(); |
|
|
@ -986,7 +991,7 @@ class Upload: public Command { |
|
|
|
if (files.size()==1) filename=files[0]; |
|
|
|
if (files.size()==1) filename=files[0]; |
|
|
|
} |
|
|
|
} |
|
|
|
page->setNextUploadFile(filename); |
|
|
|
page->setNextUploadFile(filename); |
|
|
|
realMouseClick(frame, script->replacevars(_selector), log); |
|
|
|
realMouseClick(frame, script->replacevars(_selector)); |
|
|
|
if (page->uploadPrepared()) |
|
|
|
if (page->uploadPrepared()) |
|
|
|
throw SetFileUploadFailed(script->replacevars(_selector), filename); |
|
|
|
throw SetFileUploadFailed(script->replacevars(_selector), filename); |
|
|
|
return true; |
|
|
|
return true; |
|
|
@ -1032,7 +1037,7 @@ class Exists: public Command { |
|
|
|
if (text.isEmpty()) return true; // just find element
|
|
|
|
if (text.isEmpty()) return true; // just find element
|
|
|
|
if (element.toOuterXml().indexOf(text)!=-1) return true; |
|
|
|
if (element.toOuterXml().indexOf(text)!=-1) return true; |
|
|
|
} |
|
|
|
} |
|
|
|
QWebElement element(find(frame, selector, log)); |
|
|
|
QWebElement element(find(frame, selector)); |
|
|
|
if (text.isEmpty()) |
|
|
|
if (text.isEmpty()) |
|
|
|
throw AssertionFailed("element not found: "+selector); |
|
|
|
throw AssertionFailed("element not found: "+selector); |
|
|
|
else if (element.isNull()) |
|
|
|
else if (element.isNull()) |
|
|
@ -1263,7 +1268,7 @@ class Click: public Command { |
|
|
|
} |
|
|
|
} |
|
|
|
bool execute(Script* script, QWebFrame* frame) { |
|
|
|
bool execute(Script* script, QWebFrame* frame) { |
|
|
|
Logger log(this, script); |
|
|
|
Logger log(this, script); |
|
|
|
realMouseClick(frame, script->replacevars(_selector), log); |
|
|
|
realMouseClick(frame, script->replacevars(_selector)); |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
private: |
|
|
|
private: |
|
|
|