new command: timeout-false

master
Marc Wäckerlin 4 years ago
parent 08252354cd
commit 7b9b1f379e
  1. 4
      configure.ac
  2. 2
      etc/wt-mode.el
  3. 77
      src/commands.hxx
  4. 2
      src/editor.hxx

@ -9,8 +9,8 @@
# change this:
m4_define(x_package_name, webtester) # project's name
m4_define(x_major, 3) # project's major version
m4_define(x_minor, 0) # project's minor version
m4_define(x_least_diff, 123)
m4_define(x_minor, 1) # project's minor version
m4_define(x_least_diff, 129)
# never edit this block:
m4_include(ax_init_standard_project.m4)

@ -25,7 +25,7 @@
;; echo $(webrunner -h | sed -n 's, COMMAND: ,,p') | sed 's, ,\\\\|,g'
(defconst wt-font-lock-keywords
(list
'("^ *\\(auth\\|ca-certificate\\|call\\|case\\|default\\|check\\|clear-cookies\\|click\\|clicktype\\|client-certificate\\|do\\|download\\|echo\\|execute\\|exists\\|exit\\|expect\\|fail\\|for\\|function\\|if\\|else\\|while\\|ignore\\|unignore\\|ignoreto\\|include\\|label\\|load\\|not\\|offline-storage-path\\|open\\|screenshot\\|set\\|setvalue\\|sleep\\|testcase\\|testsuite\\|timeout\\|unset\\|upload\\)\\b" . font-lock-builtin-face)
'("^ *\\(auth\\|ca-certificate\\|call\\|case\\|default\\|check\\|clear-cookies\\|click\\|clicktype\\|client-certificate\\|do\\|download\\|echo\\|execute\\|exists\\|exit\\|expect\\|fail\\|for\\|function\\|if\\|else\\|while\\|ignore\\|unignore\\|ignoreto\\|include\\|label\\|load\\|not\\|offline-storage-path\\|open\\|screenshot\\|set\\|setvalue\\|sleep\\|testcase\\|testsuite\\|timeout\\|timeout-false\\|unset\\|upload\\)\\b" . font-lock-builtin-face)
'("^ *#.*$" . font-lock-comment-face))
"Highlighting expressions for Webtester")

@ -495,7 +495,9 @@ class Script: public QObject {
public:
Script():
_step(0), _clicktype(JAVASCRIPT_CLICK),
_screenshots(true), _defaultTimeout(20) {
_screenshots(true),
_defaultTimeout(10),
_defaultTimeoutFalse(3) {
initPrototypes();
}
Script(const Script& o):
@ -599,6 +601,7 @@ class Script: public QObject {
_variables.clear();
_rvariables.clear();
_timeout = _defaultTimeout;
_timeoutFalse = _defaultTimeoutFalse;
_step = 0;
_clicktype = JAVASCRIPT_CLICK;
}
@ -651,7 +654,8 @@ class Script: public QObject {
bool res(true);
_step = 0;
_testsuites = testsuites;
_timeout = _defaultTimeout; // defaults to 20s
_timeout = _defaultTimeout;
_timeoutFalse = _defaultTimeoutFalse;
_ignoreSignalsUntil.clear();
addSignals(frame);
_screenshots = screenshots;
@ -929,7 +933,9 @@ class Script: public QObject {
_variables = o._variables;
_rvariables = o._rvariables;
_timeout = o._timeout;
_timeoutFalse = o._timeoutFalse;
_defaultTimeout = o._timeout;
_defaultTimeoutFalse = o._timeoutFalse;
_clicktype = o._clicktype;
_testsuites = o._testsuites;
_testclass = o._testclass;
@ -965,9 +971,18 @@ class Script: public QObject {
int timeout() {
return _timeout;
}
void timeoutFalse(int t) {
_timeoutFalse = t;
}
int timeoutFalse() {
return _timeoutFalse;
}
void defaultTimeout(int t) {
_defaultTimeout = t;
}
void defaultTimeoutFalse(int t) {
_defaultTimeoutFalse = t;
}
void auth(const QString& realm, const QString& username, const QString& password) {
if (!username.isEmpty() && !password.isEmpty())
_auth[realm] = {username, password};
@ -1202,7 +1217,9 @@ class Script: public QObject {
QMap<LenString, LenString> _rvariables; ///< reverse variable mapping
QMap<QString, std::shared_ptr<Function> > _functions;
int _timeout;
int _timeoutFalse;
int _defaultTimeout;
int _defaultTimeoutFalse;
ClickType _clicktype;
QString _targetdir;
std::shared_ptr<xml::Node> _testsuites; ///< only valid within run
@ -1664,8 +1681,7 @@ class Not: public Command {
Logger log(this, script);
QString selector(script->replacevars(_selector));
QString text(script->replacevars(_text));
QWebElement firstelement(find(frame, selector,
mrw::max(mrw::min(script->timeout()/3, 10), 2)));
QWebElement firstelement(find(frame, selector, script->timeoutFalse()-1));
for (QWebElement element: frame->findAllElements(selector)) {
if (text.isEmpty())
error(log, AssertionFailed("element must not exists: "+selector));
@ -1979,7 +1995,7 @@ class Timeout: public Command {
return
tag()+" <seconds>"
"\n\n--\n\n"
"Set the timeout in seconds (defaults to 10).";
"Set the timeout in seconds.";
}
QString command() const {
return tag()+" "+_timeout;
@ -1997,6 +2013,47 @@ class Timeout: public Command {
if (!ok) error(log, BadArgument(script->replacevars(_timeout)
+" should be a number of seconds"));
script->timeout(timeout);
script->defaultTimeout(timeout);
return true;
}
private:
QString _timeout;
};
class TimeoutFalse: public Command {
public:
QString tag() const {
return "timeout-false";
}
QString description() const {
return
tag()+" <seconds>"
"\n\n--\n\n"
"Set the timeout for negative testcases in seconds."
" Time to wait until a negative testcase is accepted. It is used in"
" commands such as not, if or while, where a fail is the expected or at"
" least a valid result. Normally, this timeout can be lower than the"
" normal timeout. This is, because to verify that something does not"
" exists, the test run has always to wait for the full timeout. So"
" setting this to a lower value increases the speed of the test run.";
}
QString command() const {
return tag()+" "+_timeout;
}
std::shared_ptr<Command> parse(Script*, QString args,
QStringList&, QString, int, int) {
std::shared_ptr<TimeoutFalse> cmd(new TimeoutFalse());
cmd->_timeout = args;
return cmd;
}
bool execute(Script* script, QWebFrame*) {
Logger log(this, script);
bool ok;
int timeout(script->replacevars(_timeout).toInt(&ok));
if (!ok) error(log, BadArgument(script->replacevars(_timeout)
+" should be a number of seconds"));
script->timeoutFalse(timeout);
script->defaultTimeoutFalse(timeout);
return true;
}
private:
@ -2371,8 +2428,7 @@ class If: public CommandContainer {
QString selector(script->replacevars(_variable));
bool check(false);
if (_cmp=="->") {
QWebElement firstelement(find(frame, selector,
mrw::max(mrw::min(script->timeout()/3, 10), 2)));
QWebElement firstelement(find(frame, selector, script->timeoutFalse()-1));
for (QWebElement element: frame->findAllElements(selector)) {
if (value.isEmpty() || // just find element
element.toOuterXml().indexOf(value)!=-1 ||
@ -2478,8 +2534,7 @@ class While: public CommandContainer {
for (bool check(true); check;) {
if (_cmp=="->") {
check = false;
QWebElement firstelement(find(frame, selector,
mrw::max(mrw::min(script->timeout()/3, 10), 2)));
QWebElement firstelement(find(frame, selector, script->timeoutFalse()-1));
for (QWebElement element: frame->findAllElements(selector)) {
if (value.isEmpty() || // just find element
element.toOuterXml().indexOf(value)!=-1 ||
@ -2942,8 +2997,7 @@ class Case: public Command {
log("terminate with default branch");
check = true;
} else if (condition.cmp=="->") {
QWebElement firstelement(find(frame, selector,
mrw::max(mrw::min(script->timeout()/3, 10), 2)));
QWebElement firstelement(find(frame, selector, script->timeoutFalse()-1));
for (QWebElement element: frame->findAllElements(selector)) {
if (value.isEmpty() || // just find element
element.toOuterXml().indexOf(value)!=-1 ||
@ -3283,6 +3337,7 @@ inline void Script::initPrototypes() {
add(new Set);
add(new UnSet);
add(new Timeout);
add(new TimeoutFalse);
add(new CaCertificate);
add(new ClientCertificate);
add(new ::ClickType);

@ -19,7 +19,7 @@ class Highlighter: public QSyntaxHighlighter {
void include(QString);
public:
Highlighter(QTextDocument *parent): QSyntaxHighlighter(parent) {
QString commands="auth|ca-certificate|call|case|default|check|clear-cookies|click|clicktype|client-certificate|do|download|echo|execute|exists|exit|expect|fail|for|function|if|else|while|ignore|unignore|ignoreto|include|label|load|not|offline-storage-path|open|screenshot|set|setvalue|sleep|testcase|testsuite|timeout|unset|upload";
QString commands="auth|ca-certificate|call|case|default|check|clear-cookies|click|clicktype|client-certificate|do|download|echo|execute|exists|exit|expect|fail|for|function|if|else|while|ignore|unignore|ignoreto|include|label|load|not|offline-storage-path|open|screenshot|set|setvalue|sleep|testcase|testsuite|timeout|timeout-false|unset|upload";
_expressions<<Expression("^ *("+commands+")\\b").weight(QFont::Bold).fg(Qt::darkBlue)
<<Expression("^ *#.*$").weight(QFont::Bold).fg(Qt::black);
}

Loading…
Cancel
Save