some smaller fixes and improvements for joomla testing

master
Marc Wäckerlin 8 years ago
parent aca1ed69b1
commit 1340c1efe5
  1. 25
      src/commands.hxx
  2. 7
      src/testgui.hxx

@ -1382,9 +1382,12 @@ class Exists: public Command {
Logger log(this, script);
QString selector(script->replacevars(_selector));
QString text(script->replacevars(_text));
QStringList notfound;
Q_FOREACH(QWebElement element, frame->findAllElements(selector)) {
if (text.isEmpty()) return true; // just find element
if (element.toOuterXml().indexOf(text)!=-1) return true;
if (element.toPlainText().indexOf(text)!=-1) return true;
notfound += element.toOuterXml();
}
QWebElement element(find(frame, selector));
if (text.isEmpty())
@ -1394,7 +1397,7 @@ class Exists: public Command {
+selector);
else
throw AssertionFailed("not found \""+text+"\" in \""
+element.toOuterXml()+"\" on "+selector);
+notfound.join("\", \"")+"\" on "+selector);
return true; // never reached due to throw above
}
private:
@ -2082,8 +2085,8 @@ class If: public Command {
" <...>\n"
"\n\n"
"Execute commands conditionally. "
"The comparision <cmp> can be = ^ ~ < >, "
"which means equal, different, match, "
"The comparision <cmp> can be = ^ . ~ < >, "
"which means equal, different, contains, match, "
"less (as integer), bigger (as integer). "
"Match allows a regular expression. "
"There is an optional else part.";
@ -2096,7 +2099,7 @@ class If: public Command {
QStringList& in, QString file, int line,
int indent) {
std::shared_ptr<If> cmd(new If());
int pos(args.indexOf(QRegularExpression("[=^~<>]")));
int pos(args.indexOf(QRegularExpression("[=^.~<>]")));
if (pos<0) throw BadArgument(tag()+" needs a comparision, not: "+args);
cmd->_variable = args.left(pos).trimmed();
cmd->_cmp = args[pos].toLatin1();
@ -2119,6 +2122,8 @@ class If: public Command {
break;
case '^': check = script->variable(_variable)!=value;
break;
case '.': check = script->variable(_variable).contains(value);
break;
case '~': check =
script->variable(_variable).contains(QRegularExpression(value));
break;
@ -2216,8 +2221,8 @@ class Check: public Command {
" output, such as <do>, which returns the result of JavaScript or"
" <execute>, which returns the output of the executed command, or"
" <call>, which returns the result of the last command. "
"The comparision <cmp> can be = ^ ~ < >, "
"which means equal, different, match, "
"The comparision <cmp> can be = ^ . ~ < >, "
"which means equal, different, contains match, "
"less (as integer), bigger (as integer). "
"Match allows a regular expression. "
" less than < (integers), larger than > (integers)";
@ -2233,7 +2238,7 @@ class Check: public Command {
int indent) {
std::shared_ptr<Check> cmd(new Check());
cmd->_next = 0;
int pos(args.indexOf(QRegularExpression("[=^~<>]")));
int pos(args.indexOf(QRegularExpression("[=^.~<>]")));
if (pos<0) throw BadArgument(tag()+" needs a comparision, not: "+args);
cmd->_value1 = args.left(pos).trimmed();
cmd->_cmp = args[pos].toLatin1();
@ -2256,6 +2261,7 @@ class Check: public Command {
switch (_cmp) {
case '=': check = value1==value2; break;
case '^': check = value1!=value2; break;
case '.': check = value1.contains(value2); break;
case '~': check = value1.contains(QRegularExpression(value2)); break;
case '<': check = value1.toInt()<value2.toInt(); break;
case '>': check = value1.toInt()>value2.toInt(); break;
@ -2302,7 +2308,7 @@ class For: public Command {
if (!args.size()) throw BadArgument(tag()+" requires a <variable>");
QStringList allargs(args.split("->"));
cmd->_variable = allargs.takeFirst().trimmed();
cmd->_vals = commaSeparatedList(allargs.join(' '));
cmd->_vals = commaSeparatedList(allargs.join("->"));
cmd->_script = std::shared_ptr<Script>(new Script);
cmd->_script->parse(subCommandBlock(in), file, line+1, indent+1);
return cmd;
@ -2372,6 +2378,9 @@ class OfflineStoragePath: public Command {
}
bool execute(Script* script, QWebFrame* frame) {
Logger log(this, script);
QDir path(_path);
if (!path.exists() && !path.mkpath(_path))
throw DirectoryCannotBeCreated(_path);
TestWebPage* page(dynamic_cast<TestWebPage*>(frame->page()));
page->settings()->setOfflineStoragePath(_path);
return true;

@ -155,6 +155,7 @@ class TestGUI: public QMainWindow, protected Ui::TestGUI {
}
void on__jsExecute_clicked() {
enterText(true);
qDebug()<<"on__jsExecute_clicked"<<selector()<<_javascriptCode->toPlainText();
_jsResult->setText(execute(selector(), _javascriptCode->toPlainText()));
}
void on__web_linkClicked(const QUrl& url) {
@ -607,8 +608,10 @@ class TestGUI: public QMainWindow, protected Ui::TestGUI {
}
QString execute(const QString& selector, const QString& code) {
javascript(selector, code);
return _web->page()->mainFrame()->documentElement().findFirst(selector)
.evaluateJavaScript(code).toString();
QVariant res(_web->page()->mainFrame()->documentElement().findFirst(selector)
.evaluateJavaScript(code));
qDebug()<<"EXECUTE"<<selector<<res;
return res.toString();
}
void setLinks() {
QWebElementCollection links(_web->page()->mainFrame()->documentElement()

Loading…
Cancel
Save