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