diff --git a/configure.ac b/configure.ac index d20a11c..22eba60 100644 --- a/configure.ac +++ b/configure.ac @@ -8,8 +8,9 @@ # change this: m4_define(x_package_name, webtester) # project's name -m4_define(x_major, 2) # project's major version -m4_define(x_minor, 2) # project's minor version +m4_define(x_major, 3) # project's major version +m4_define(x_minor, 0) # project's minor version +m4_define(x_least_diff, 123) # never edit this block: m4_include(ax_init_standard_project.m4) diff --git a/src/commands.hxx b/src/commands.hxx index ae5ed19..bf03959 100644 --- a/src/commands.hxx +++ b/src/commands.hxx @@ -278,7 +278,7 @@ class Empty: public Command { QString description() const { return "" - "\n\n" + "\n\n--\n\n" "Empty lines are allowed"; } QString command() const { @@ -306,7 +306,7 @@ class Comment: public Command { QString description() const { return "# comment" - "\n\n" + "\n\n--\n\n" "Comments are lines that start with #"; } QString command() const { @@ -383,7 +383,7 @@ class Screenshot: public Command { QString description() const { return tag()+" " - "\n\n" + "\n\n--\n\n" "Create a PNG screenshot of the actual web page and store it in the " "file .png. If not already opened, a browser window " "will pop up to take the screenshot."; @@ -450,6 +450,7 @@ class Script: public QObject { void logging(QString); void progress(QString, int, int, int); public: + typedef std::map> Prototypes; typedef std::pair Signal; enum ClickType { REAL_MOUSE_CLICK, @@ -500,57 +501,79 @@ class Script: public QObject { } QString syntax() const { return - "Script syntax is a text file that consists of list of commands. Each " + "Script syntax is a text file that consists of a list of commands. Each " "command starts at the begin of a new line. Empty lines are allowed. " "Lines that start with \"#\" are treated as comments." "\n\n" "Subcommands are indented. The first indented line defines the level of " - "indentation. All following lines must be indented by the same level." + "indentation. All following lines must be indented at least by the same level." "\n\n" "Note: When a selector is required as parameter, then the selector " "is a CSS selector." "\n\n" - "Thanks to the filter script doxygen-webtester.sed, you cab use the " + "Thanks to the filter script doxygen-webtester.sed, you can use the " "comments for producing doxygen documenation. Just start comments with " "\"##\" to import them to doxygen. This script is automatically configured, " "when you use the autotools bootstrap from:\n" - "https://dev.marc.waeckerlin.org/redmine/projects/bootstrap-build-environment"; + "https://mrw.sh/development/bootstrap-build-environment"; } /// set workdir void path(QString path) { _path = (path.size()?path:".")+QDir::separator(); } /// get workdir - QString path() { + QString path() const { return _path; } + /// get all command prototypes + const Prototypes& prototypes() const { + return _prototypes; + } QString commands(Formatting f = PLAIN) const { QString cmds; - for (auto it(_prototypes.begin()); it!=_prototypes.end(); ++it) - switch (f) { - case PLAIN: { + switch (f) { + case PLAIN: { + for (auto it(_prototypes.begin()); it!=_prototypes.end(); ++it) cmds+="\n\n\nCOMMAND: "+it->first+"\n\n"+it->second->description(); - } break; - case HTML: { - cmds+="

"+it->first+"

" - +it->second->description() - .replace("&", "&") - .replace("<", "<") - .replace(">", ">") - .replace(QRegularExpression("<([^ ]+)>"), - "\\1") - .replace(QRegularExpression("(\n[^ ][^\n]*)(\n +-)"), - "\\1

    \\2") - .replace(QRegularExpression("(\n +-[^\n]*\n)([^ ])"), - "\\1
\\2") - .replace(QRegularExpression("\n +- ([^\n]*)()?"), - "
  • \\1
  • \\2") - .replace("\n", "") - .replace("\n ", "\n  ") - .replace("\n\n", "

    ") - .replace("\n", "
    ") - +"

    "; - } break; + } break; + case HTML: { + auto format = [](QString s) { + return s + .replace("&", "&") + .replace("<", "<") + .replace(">", ">") + .replace(QRegularExpression("<([-_A-Za-z0-9]+)>"), "\\1") + .replace(QRegularExpression("(\n[^ ][^\n]*)(\n +-)"), "\\1
      \\2") + .replace(QRegularExpression("(\n +-[^\n]*\n)([^ ])"), "\\1
    \\2") + .replace(QRegularExpression("\n +- ([^\n]*)()?"), "
  • \\1
  • \\2") + .replace("\n", "") + .replace("\n ", "\n  ") + .replace("\n\n", "

    ") + .replace("\n", "
    ") + .replace(QRegularExpression("(http(s)?://[-/^a-z0-9.]+)"), "\\1"); + }; + cmds = "" + "

    Contents

    " + "

    Syntax

    " + +format(syntax())+ + "

    Commands

    "; + for (auto[name,command]: _prototypes) { + QStringList doc(command->description().split("\n\n--\n\n")); + assert(doc.size()==2); // description does not match expected format + QString usage(doc.takeFirst()); + QString description(doc.takeFirst()); + cmds += "

    "+name+"

    Usage

    " + + format(usage) + + "

    Description

    " + + format(description) + + "

    "; + } + } break; } return cmds.trimmed(); } @@ -1155,7 +1178,6 @@ class Script: public QObject { QString username; QString password; }; - typedef std::map> Prototypes; typedef std::vector> Commands; Prototypes _prototypes; Commands _script; @@ -1205,7 +1227,7 @@ class Do: public Command { QString description() const { return tag()+" []\n \n " - "\n\n" + "\n\n--\n\n" "Execute JavaScript on a CSS selected object. The object is the first " "object in the DOM tree that matches the given CSS selector. You can " "refere to the selected object within the scripy by \"this\". The " @@ -1248,7 +1270,7 @@ class Load: public Command { QString description() const { return tag()+" " - "\n\n" + "\n\n--\n\n" "Load an URL, the URL is given as parameter in full syntax."; } QString command() const { @@ -1277,7 +1299,7 @@ class Expect: public Command { QString description() const { return tag()+" []" - "\n\n" + "\n\n--\n\n" "Expect a signal. Signals are emitted by webkit and may contain " "parameter. If a parameter is given in the script, then the parameter " "must match exactly. If no parameter is given, then the signal must " @@ -1346,7 +1368,7 @@ class Open: public Command { QString description() const { return tag()+ - "\n\n" + "\n\n--\n\n" "Open the browser window, so you can follow the test steps visually."; } QString command() const { @@ -1372,7 +1394,7 @@ class Sleep: public Command { QString description() const { return tag()+" " - "\n\n" + "\n\n--\n\n" "Sleep for a certain amount of seconds. This helps, if you must wait " "for some javascript actions, i.e. AJAX or slow pages, and the " "excpeted signals are not sufficient."; @@ -1410,7 +1432,7 @@ class Exit: public Command { QString description() const { return tag()+ - "\n\n" + "\n\n--\n\n" "Successfully terminate script immediately. The following commands " "are not executed. This helps when you debug your scripts and you " "want the script stop at a certain point for investigations."; @@ -1437,7 +1459,7 @@ class IgnoreTo: public Command { QString description() const { return tag()+"