From 4f4a722696917febb59d804e6177992cf152f556 Mon Sep 17 00:00:00 2001 From: Branko Juric Date: Mon, 23 Sep 2024 11:58:14 +1000 Subject: [PATCH] Add file based DSL steps --- CHANGELOG | 45 +++++++-- build.sbt | 4 +- src/main/resources/gwen-web.dsl | 91 ++++++++----------- src/main/scala/gwen/web/eval/WebEngine.scala | 12 ++- src/test/features/file/FileAsserts.feature | 25 +++++ src/test/features/file/file2.txt | 0 src/test/features/flow/IfCondition.feature | 30 ++++++ .../features/flow/RepeatUntilFile.feature | 74 +++++++++++++++ .../features/flow/RepeatWhileFile.feature | 85 +++++++++++++++++ src/test/features/flow/WaitUntilFile.feature | 46 ++++++++++ src/test/scala/gwen/web/eval/WebDslTest.scala | 4 +- .../scala/gwen/web/eval/WebEngineTest.scala | 28 ------ 12 files changed, 347 insertions(+), 97 deletions(-) create mode 100644 src/test/features/file/FileAsserts.feature create mode 100644 src/test/features/file/file2.txt create mode 100644 src/test/features/flow/RepeatUntilFile.feature create mode 100644 src/test/features/flow/RepeatWhileFile.feature create mode 100644 src/test/features/flow/WaitUntilFile.feature diff --git a/CHANGELOG b/CHANGELOG index 4be70848..0b0512be 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,34 @@ +3.75.0 +====== +23 September 2024 +- Deprecated DSL steps: + - `I wait second[s] when is ` + - `I wait until when is ` +- Update Gwen core from v3.63.2 to v[3.64.0](https://github.com/gwen-interpreter/gwen/releases/tag/v3.64.0) + - Add file based DSL steps + - ` if "" file[ not] exists` + - ` if "" file does not exist` + - ` if [ not] exists` + - ` if does not exist` + - ` if "" file is[ not] empty` + - ` if is[ not] empty` + - ` "" file[ not] exists` + - ` "" file does not exist` + - ` [ not] exists` + - ` does not exist` + - ` "" file is[ not] empty` + - ` is[ not] empty` + - `I wait until "" file[ not] exists` + - `I wait until "" file does not exist` + - `I wait until [ not] exists` + - `I wait until does not exist` + - `I wait until "" file is[ not] empty` + - `I wait until is[ not] empty` + - `"" file should[ not] exist` + - ` should[ not] exist` + - `"" file should[ not] be empty` + - ` should[ not] be empty` + 3.74.3 ====== 21 September 2024 @@ -487,9 +518,9 @@ Oct 28, 2023 Oct 24, 2023 - Add DSLs for downloading files from a URL - `I download "" to ""` - - `I download "" to ` + - `I download "" to ` - `I download the current URL to ""` - - `I download the current URL to ` + - `I download the current URL to ` - Update selenium from v4.14.0 to v4.14.1 - Update Gwen core from v3.49.2 to v[3.50.0](https://github.com/gwen-interpreter/gwen/releases/tag/v3.50.0) @@ -1256,9 +1287,9 @@ Aug 24, 2022 - Update Gwen core from v3.26.1 to v[3.27.0](https://github.com/gwen-interpreter/gwen/releases/tag/v3.27.0) - Introduce CSV lookup DSLs: - `I lookup in the "" file where ""` - - `I lookup in file where ""` + - `I lookup in file where ""` - `I lookup in the "" file as where ""` - - `I lookup in file as where ""` + - `I lookup in file as where ""` 3.29.1 ====== @@ -1339,9 +1370,9 @@ Jul 21, 2022 - `I "" to "" file` - `I to "" file` - `I new line to "" file` - - `I "" to file` - - `I to file` - - `I new line to file` + - `I "" to file` + - `I to file` + - `I new line to file` 3.24.0 ====== diff --git a/build.sbt b/build.sbt index 82bad4ed..ebe06025 100644 --- a/build.sbt +++ b/build.sbt @@ -1,8 +1,8 @@ enablePlugins(GitVersioning) // gwen core & web versions -val gwenVersion = "3.63.2" -val gwenWebVersion = "3.74.3" +val gwenVersion = "3.64.0" +val gwenWebVersion = "3.75.0" git.baseVersion := gwenWebVersion git.useGitDescribe := true diff --git a/src/main/resources/gwen-web.dsl b/src/main/resources/gwen-web.dsl index d0e44bdf..dfcc8ad1 100644 --- a/src/main/resources/gwen-web.dsl +++ b/src/main/resources/gwen-web.dsl @@ -516,51 +516,6 @@ I untick of I move to of I send "" I send "" to -I wait 1 second when is clicked -I wait 1 second when is right clicked -I wait 1 second when is double clicked -I wait 1 second when is moved to -I wait 1 second when is submitted -I wait 1 second when is checked -I wait 1 second when is ticked -I wait 1 second when is unchecked -I wait 1 second when is unticked -I wait 1 second when is selected -I wait 1 second when is deselected -I wait 1 second when is typed -I wait 1 second when is entered -I wait 1 second when is tabbed -I wait 1 second when is cleared -I wait seconds when is clicked -I wait seconds when is right clicked -I wait seconds when is double clicked -I wait seconds when is moved to -I wait seconds when is submitted -I wait seconds when is checked -I wait seconds when is ticked -I wait seconds when is unchecked -I wait seconds when is unticked -I wait seconds when is selected -I wait seconds when is deselected -I wait seconds when is typed -I wait seconds when is entered -I wait seconds when is tabbed -I wait seconds when is cleared -I wait until when is clicked -I wait until when is right clicked -I wait until when is double clicked -I wait until when is moved to -I wait until when is submitted -I wait until when is checked -I wait until when is ticked -I wait until when is unchecked -I wait until when is unticked -I wait until when is selected -I wait until when is deselected -I wait until when is typed -I wait until when is entered -I wait until when is tabbed -I wait until when is cleared I wait until "" I wait until I wait until is displayed @@ -579,6 +534,16 @@ I wait until is not unchecked I wait until is not unticked I wait until is not enabled I wait until is not disabled +I wait until "" file exists +I wait until exists +I wait until "" file not exists +I wait until not exists +I wait until "" file does not exist +I wait until does not exist +I wait until "" file is empty +I wait until is empty +I wait until "" file is not empty +I wait until is not empty I wait 1 second I wait seconds I highlight @@ -630,6 +595,16 @@ I base64 decode while is not enabled until is not disabled while is not disabled + while "" file exists + until exists + while "" file not exists + until not exists + while "" file does not exist + until does not exist + while "" file is empty + until is empty + while "" file is not empty + until is not empty I close the current browser I close the browser I start a new browser @@ -815,6 +790,16 @@ I maximise the window if does not match json path "" if does not match template "" if does not match template file "" + if "" file exists + if "" file not exists + if "" file does not exist + if "" file is empty + if "" file is not empty + if exists + if not exists + if does not exist + if is empty + if is not empty for each in delimited by "" for each in array I drag and drop to @@ -826,19 +811,19 @@ I attach "" as I write "" to "" file I write to "" file I write new line to "" file -I write "" to file -I write to file -I write new line to file +I write "" to +I write to +I write new line to I append "" to "" file I append to "" file I append new line to "" file -I append "" to file -I append to file -I append new line to file +I append "" to +I append to +I append new line to I download "" to "" -I download "" to +I download "" to I download the current URL to "" -I download the current URL to +I download the current URL to should be % similar to "" should be less than % similar to "" should be at most % similar to "" diff --git a/src/main/scala/gwen/web/eval/WebEngine.scala b/src/main/scala/gwen/web/eval/WebEngine.scala index 3d827295..fde7c1e8 100644 --- a/src/main/scala/gwen/web/eval/WebEngine.scala +++ b/src/main/scala/gwen/web/eval/WebEngine.scala @@ -142,8 +142,10 @@ class WebEngine extends EvalEngine[WebContext] { case r"""I wait for (.+?)$element""" => new WaitForElement(element, None) case r"""I wait ([0-9]+?)$duration second(?:s?) when (.+?)$element is (clicked|right clicked|double clicked|submitted|checked|ticked|unchecked|unticked|selected|deselected|typed|entered|tabbed|cleared|moved to)$event""" => + Deprecation.log("DSL step", "I wait second[s] when is ", None) new WaitForElementOnEvent(element, ElementEvent.valueOf(event), duration.toLong) case r"""I wait until (.+?)$condition when (.+?)$element is (clicked|right clicked|double clicked||submitted|checked|ticked|unchecked|unticked|selected|deselected|typed|entered|tabbed|cleared|moved to)$event""" => + Deprecation.log("DSL step", "I wait until when is ", None) new WaitForConditionOnEvent(element, ElementEvent.valueOf(event), condition) case r"""I wait until "(.+?)$javascript" using (.+?)$delayPeriod (second|millisecond)$delayUnit delay and (.+?)$timeoutPeriod (minute|second|millisecond)$timeoutUnit timeout""" => Deprecation.log("Overloaded step", s"using $delayPeriod $delayUnit delay and $timeoutPeriod $timeoutUnit timeout", Some(s"@Delay('$delayPeriod${Map("second" -> "s", "millisecond" -> "ms")(delayUnit)}') @Timeout('$timeoutPeriod${Map("minute" -> "m", "second" -> "s", "millisecond" -> "ms")(timeoutUnit)}') annotations")) @@ -167,7 +169,7 @@ class WebEngine extends EvalEngine[WebContext] { case r"""I wait until (.+?)$condition using (.+?)$timeoutPeriod (minute|second|millisecond)$timeoutUnit timeout""" => Deprecation.log("Overloaded step", s"using $timeoutPeriod $timeoutUnit timeout", Some(s"@Timeout('$timeoutPeriod${Map("minute" -> "m", "second" -> "s", "millisecond" -> "ms")(timeoutUnit)}') annotation")) new WaitForBoundCondition(condition, step.delayOpt.map(_.toMillis), Some(Duration(timeoutPeriod.toLong, timeoutUnit).toSeconds)) - case r"""I wait until (.+?)$condition""" => + case r"""I wait until (.+?)$condition""" if !condition.matches(".+ file (exists|not exists|does not exist|is empty|is not empty)") => new WaitForBoundCondition(condition, step.delayOpt.map(_.toMillis), step.timeoutOpt.map(_.toSeconds)) case r"""I am on the (.+?)$page""" => new CreatePageScope(page) @@ -329,13 +331,13 @@ class WebEngine extends EvalEngine[WebContext] { new CompareValueOrSelectionToValue(element, Option(selection).map(_.trim).map(DropdownSelection.valueOf), expression, ComparisonOperator.valueOf(operator), Option(negation).isDefined, step.message, Some(Duration.create(timeout.toLong, TimeUnit.SECONDS)), step.isTrim, step.isIgnoreCase) case r"""(.+?)$element( text| value)?$selection should( not)?$negation (be|contain|start with|end with|match regex|match xpath|match json path|match template|match template file)$operator "(.*?)"$expression""" if !element.matches(".+at (json path|xpath).+") => new CompareValueOrSelectionToValue(element, Option(selection).map(_.trim).map(DropdownSelection.valueOf), step.orDocString(expression), ComparisonOperator.valueOf(operator), Option(negation).isDefined, step.message, step.timeoutOpt, step.isTrim, step.isIgnoreCase) - case r"""(.+?)$element( text| value)?$selection should( not)?$negation (be|contain|start with|end with|match regex|match xpath|match json path)$operator (.+?)$attribute with no (timeout|wait)$timeoutLiteral""" if attribute != "absent" && attribute != "defined" && !element.matches(".+at (json path|xpath).+") && !attribute.contains("% similar to ") && attribute != "no accumulated errors" && !attribute.contains('"') => + case r"""(.+?)$element( text| value)?$selection should( not)?$negation (be|contain|start with|end with|match regex|match xpath|match json path)$operator (.+?)$attribute with no (timeout|wait)$timeoutLiteral""" if !attribute.matches("(absent|defined|empty|no accumulated errors)") && !attribute.contains("% similar to ") && !attribute.contains('"') && !element.matches(".+at (json path|xpath).+") => Deprecation.log("Overloaded step", s"with no $timeoutLiteral", Some("@Timeout('0s') annotation")) new CompareValueOrSelectionToBoundValue(element, Option(selection).map(_.trim).map(DropdownSelection.valueOf), attribute, ComparisonOperator.valueOf(operator), Option(negation).isDefined, step.message, Some(Duration.Zero), step.isTrim, step.isIgnoreCase) - case r"""(.+?)$element( text| value)?$selection should( not)?$negation (be|contain|start with|end with|match regex|match xpath|match json path)$operator (.+?)$attribute with (\d+)$timeout second (timeout|wait)$timeoutLiteral""" if attribute != "absent" && attribute != "defined" && !element.matches(".+at (json path|xpath).+") && !attribute.contains("% similar to ") && attribute != "no accumulated errors" && !attribute.contains('"') => + case r"""(.+?)$element( text| value)?$selection should( not)?$negation (be|contain|start with|end with|match regex|match xpath|match json path)$operator (.+?)$attribute with (\d+)$timeout second (timeout|wait)$timeoutLiteral""" if !attribute.matches("(absent|defined|empty|no accumulated errors)") && !attribute.contains("% similar to ") && !attribute.contains('"') && !element.matches(".+at (json path|xpath).+") => Deprecation.log("Overloaded step", s"with $timeout second $timeoutLiteral", Some(s"@Timeout('${timeout}s') annotation")) new CompareValueOrSelectionToBoundValue(element, Option(selection).map(_.trim).map(DropdownSelection.valueOf), attribute, ComparisonOperator.valueOf(operator), Option(negation).isDefined, step.message, Some(Duration.create(timeout.toLong, TimeUnit.SECONDS)), step.isTrim, step.isIgnoreCase) - case r"""(.+?)$element( text| value)?$selection should( not)?$negation (be|contain|start with|end with|match regex|match xpath|match json path)$operator (.+?)$attribute""" if attribute != "absent" && attribute != "defined" && !element.matches(".+at (json path|xpath).+") && !attribute.contains("% similar to ") && attribute != "no accumulated errors" && !attribute.contains('"') => + case r"""(.+?)$element( text| value)?$selection should( not)?$negation (be|contain|start with|end with|match regex|match xpath|match json path)$operator (.+?)$attribute""" if !attribute.matches("(absent|defined|empty|no accumulated errors)") && !attribute.contains("% similar to ") && !attribute.contains('"') && !element.matches(".+at (json path|xpath).+") => new CompareValueOrSelectionToBoundValue(element, Option(selection).map(_.trim).map(DropdownSelection.valueOf), attribute, ComparisonOperator.valueOf(operator), Option(negation).isDefined, step.message, step.timeoutOpt, step.isTrim, step.isIgnoreCase) case r"""I capture (.+?)$attribute (?:of|on|in) (.+?)$element by (?:javascript|js) "(.+?)"$expression""" => new CaptureElementAttribute(element, attribute, step.orDocString(expression)) @@ -447,7 +449,7 @@ class WebEngine extends EvalEngine[WebContext] { new AppendNewLineToElement(element) case r"""I download the current URL to "(.+?)"$filepath""" => new DownloadCurrentUrlToFile(Some(filepath), None, defaultConditionTimeoutSecs) - case r"""I download the current URL to (.+?)$filepathRef""" => + case r"""I download the current URL to (.+? file)$filepathRef""" => new DownloadCurrentUrlToFile(None, Some(filepathRef), defaultConditionTimeoutSecs) case _ => diff --git a/src/test/features/file/FileAsserts.feature b/src/test/features/file/FileAsserts.feature new file mode 100644 index 00000000..ae231a8a --- /dev/null +++ b/src/test/features/file/FileAsserts.feature @@ -0,0 +1,25 @@ +Feature: File assertions + + Scenario: Assert file exists + Given the file is defined by js "'src/test/features/file/file.txt'" + When I capture the file + Then "src/test/features/file" file should exist + And the file should exist + + Scenario: Assert file does not exist + Given the file is defined by js "'src/test/features/file/missing.txt'" + When I capture the file + Then "src/test/features/file/missing.txt" file should not exist + And the file should not exist + + Scenario: Assert file shoud be empty + Given the file is defined by js "'src/test/features/file/file2.txt'" + When I capture the file + Then "src/test/features/file/file2.txt" file should be empty + And the file should be empty + + Scenario: Assert file shoud not be empty + Given the file is defined by js "'src/test/features/file/file.txt'" + When I capture the file + Then "src/test/features/file/file.txt" file should not be empty + And the file should not be empty diff --git a/src/test/features/file/file2.txt b/src/test/features/file/file2.txt new file mode 100644 index 00000000..e69de29b diff --git a/src/test/features/flow/IfCondition.feature b/src/test/features/flow/IfCondition.feature index d105a412..518ff023 100644 --- a/src/test/features/flow/IfCondition.feature +++ b/src/test/features/flow/IfCondition.feature @@ -105,3 +105,33 @@ Feature: If Conditionals Given the state code is "QLD" When I navigate to "https://example.com/?state=Other" if the state code does not match regex "(VIC|NSW)" Then the current URL should be "https://example.com/?state=Other" + + Scenario: Perform this if filepath exists + Given the target is "this" + When I perform this if "gwen.conf" file exists + And I perform that if "gwen.conf" file does not exist + Then the called step should be "this step" + And the called step should not be "that step" + + Scenario: Perform this if fileref exists + Given the target is "that" + And the file is "gwen.conf" + When I perform that if the file exists + And I perform this if the file not exists + Then the called step should be "that step" + And the called step should not be "this step" + + Scenario: Perform this if file empty or not + Given the target is "this" + When I perform this if "gwen.conf" file is not empty + And I perform that if "gwen.conf" file is empty + Then the called step should be "this step" + And the called step should not be "that step" + + Scenario: Perform this if fileref emtpy or not + Given the target is "that" + And the file is "gwen.conf" + When I perform that if the file is not empty + And I perform this if the file is empty + Then the called step should be "that step" + And the called step should not be "this step" diff --git a/src/test/features/flow/RepeatUntilFile.feature b/src/test/features/flow/RepeatUntilFile.feature new file mode 100644 index 00000000..853c8cb1 --- /dev/null +++ b/src/test/features/flow/RepeatUntilFile.feature @@ -0,0 +1,74 @@ +Feature: Repeat until file examples + + @StepDef + @Action + Scenario: I increment counter + Given counter is defined by javascript "${counter} + 1" + + Scenario: Increment counter until filepath does not exist + Given counter is "0" + When @Delay('100ms') @Timeout('1s') I increment counter until "gwen.json" file not exists + Then counter should be "1" + + Scenario: Increment counter until filepath does not exist with if condition + Given counter is "-1" + When @Delay('100ms') @Timeout('1s') I increment counter until "gwen.json" file does not exist if "gwen.conf" file exists + Then counter should be "0" + + Scenario: Increment counter until filepathref does not exist + Given counter is "0" + And the json file is "gwen.json" + When @Delay('100ms') @Timeout('1s') I increment counter until the json file not exists + Then counter should be "1" + + Scenario: Increment counter until filepathref does not exist with if condition + Given counter is "-1" + And the conf file is "gwen.conf" + And the json file is "gwen.json" + When @Delay('100ms') @Timeout('1s') I increment counter until the json file does not exist if the conf file exists + Then counter should be "0" + + Scenario: Increment counter until filepath exists + Given counter is "0" + When @Delay('100ms') @Timeout('1s') I increment counter until "gwen.conf" file exists + Then counter should be "1" + + Scenario: Increment counter until filepath exists with if condition + Given counter is "-1" + When @Delay('100ms') @Timeout('1s') I increment counter until "gwen.conf" file exists if "gwen.json" file not exists + Then counter should be "0" + + Scenario: Increment counter until filepathref exists + Given counter is "0" + And the conf file is "gwen.conf" + When @Delay('100ms') @Timeout('1s') I increment counter until the conf file exists + Then counter should be "1" + + Scenario: Increment counter until filepathref exists with if condition + Given counter is "-1" + And the conf file is "gwen.conf" + And the json file is "gwen.json" + When @Delay('100ms') @Timeout('1s') I increment counter until the conf file exists if the json file does not exist + Then counter should be "0" + + Scenario: Increment counter until filepath is not empty + Given counter is "0" + When @Delay('100ms') @Timeout('1s') I increment counter until "gwen.conf" file is not empty + Then counter should be "1" + + Scenario: Increment counter until filepath is not empty with if condition + Given counter is "-1" + When @Delay('100ms') @Timeout('1s') I increment counter until "gwen.conf" file is not empty if "gwen.conf" file is not empty + Then counter should be "0" + + Scenario: Increment counter until filepathref is not empty + Given counter is "0" + And the conf file is "gwen.conf" + When @Delay('100ms') @Timeout('1s') I increment counter until the conf file is not empty + Then counter should be "1" + + Scenario: Increment counter until filepathref is not empty with if condition + Given counter is "-1" + And the conf file is "gwen.conf" + When @Delay('100ms') @Timeout('1s') I increment counter until the conf file is not empty if the conf file exists + Then counter should be "0" diff --git a/src/test/features/flow/RepeatWhileFile.feature b/src/test/features/flow/RepeatWhileFile.feature new file mode 100644 index 00000000..79b563f4 --- /dev/null +++ b/src/test/features/flow/RepeatWhileFile.feature @@ -0,0 +1,85 @@ +Feature: Repeat while file examples + + @StepDef + @Action + Scenario: I increment counter + Given counter is defined by javascript "${counter} + 1" + + Scenario: Increment counter while filepath exists + Given counter is "0" + When @Try @Delay('100ms') @Timeout('1s') I increment counter while "gwen.conf" file exists + Then counter should not be "0" + + Scenario: Increment counter while filepath exists with if condition + Given counter is "-1" + When @Try @Delay('100ms') @Timeout('1s') I increment counter while "gwen.conf" file exists if "gwen.conf" file exists + Then counter should not be "-1" + + Scenario: Increment counter while filepathref not exists + Given counter is "0" + And the json file is "gwen.json" + When @Try @Delay('100ms') @Timeout('1s') I increment counter while the json file not exists + Then counter should not be "0" + + Scenario: Increment counter while filepathref not exists with if condition + Given counter is "-1" + And the conf file is "gwen.conf" + And the json file is "gwen.json" + When @Try @Delay('100ms') @Timeout('1s') I increment counter while the json file not exists if the conf file exists + Then counter should not be "-1" + + Scenario: Increment counter while filepath not exists + Given counter is "0" + When @Try @Delay('100ms') @Timeout('1s') I increment counter while "gwen.json" file not exists + Then counter should not be "0" + + Scenario: Increment counter while filepath not exists with if condition + Given counter is "-1" + When @Try @Delay('100ms') @Timeout('1s') I increment counter while "gwen.json" file not exists if "gwen.conf" file exists + Then counter should not be "-1" + + Scenario: Increment counter while filepathref exists + Given counter is "0" + And the conf file is "gwen.conf" + When @Try @Delay('100ms') @Timeout('1s') I increment counter while the conf file exists + Then counter should not be "0" + + Scenario: Increment counter while filepathref exists with if condition + Given counter is "-1" + And the conf file is "gwen.conf" + And the json file is "gwen.json" + When @Try @Delay('100ms') @Timeout('1s') I increment counter while the conf file exists if the json file not exists + Then counter should not be "-1" + + Scenario: Increment counter while filepath is not empty + Given counter is "0" + When @Try @Delay('100ms') @Timeout('1s') I increment counter while "gwen.conf" file is not empty + Then counter should not be "0" + + Scenario: Increment counter while filepath is not empty with if condition + Given counter is "-1" + When @Try @Delay('100ms') @Timeout('1s') I increment counter while "gwen.conf" file is not empty if "gwen.conf" file is not empty + Then counter should not be "-1" + + Scenario: Increment counter while filepathref is not empty + Given counter is "0" + And the conf file is "gwen.conf" + When @Try @Delay('100ms') @Timeout('1s') I increment counter while the conf file is not empty + Then counter should not be "0" + + Scenario: Increment counter while filepathref is not empty with if condition + Given counter is "-1" + And the conf file is "gwen.conf" + When @Try @Delay('100ms') @Timeout('1s') I increment counter while the conf file is not empty if the conf file exists + Then counter should not be "-1" + + Scenario: Increment counter while filepath is empty + Given counter is "-1" + When I increment counter while "gwen.conf" file is empty + Then counter should be "-1" + + Scenario: Increment counter while filepathref is empty with if condition + Given counter is "-1" + And the conf file is "gwen.conf" + When I increment counter while the conf file is empty if the conf file exists + Then counter should be "-1" diff --git a/src/test/features/flow/WaitUntilFile.feature b/src/test/features/flow/WaitUntilFile.feature new file mode 100644 index 00000000..07f1fd2d --- /dev/null +++ b/src/test/features/flow/WaitUntilFile.feature @@ -0,0 +1,46 @@ +Feature: Wait until file + + Scenario: Wait until filepath exists + Given counter is "0" + When I wait until "gwen.conf" file exists + Then counter should be "0" + + Scenario: Wait until filepathref exists + Given counter is "0" + And the conf file is "gwen.conf" + When I wait until the conf file exists + Then counter should be "0" + + Scenario: Wait until filepath does not exist + Given counter is "-1" + When @Timeout('1s') I wait until "gwen.json" file not exists if "gwen.conf" file exists + Then counter should be "-1" + + Scenario: Wait until filepathref does not exist + Given counter is "-1" + And the json file is "gwen.json" + When @Timeout('1s') I wait until the json file does not exist if the json file not exists + Then counter should be "-1" + + Scenario: Wait until filepath is not empty + Given counter is "0" + When I wait until "gwen.conf" file is not empty + Then counter should be "0" + + Scenario: Wait until filepathref is not empty + Given counter is "0" + And the conf file is "gwen.conf" + When I wait until the conf file is not empty + Then counter should be "0" + + Scenario: Wait until filepath is empty + Given counter is "-1" + When @Try @Timeout('1s') I wait until "gwen.conf" file is empty if "gwen.conf" file exists + Then counter should be "-1" + + Scenario: Wait until filepathref is emptyt + Given counter is "-1" + And the conf file is "gwen.conf" + And the json file is "gwen.json" + When @Try @Timeout('1s') I wait until the conf file is empty if the json file does not exist + Then counter should be "-1" diff --git a/src/test/scala/gwen/web/eval/WebDslTest.scala b/src/test/scala/gwen/web/eval/WebDslTest.scala index ae0cfb1b..9907acc8 100644 --- a/src/test/scala/gwen/web/eval/WebDslTest.scala +++ b/src/test/scala/gwen/web/eval/WebDslTest.scala @@ -67,8 +67,7 @@ class WebDslTest extends BaseTest with Matchers with MockitoSugar { envState.scopes.set("/locator", "id") envState.scopes.set("/locator/id", "id") envState.scopes.set("/file", "file.txt") - envState.scopes.set("", "file.txt") - envState.scopes.set(" file", "file.txt") + envState.scopes.set(" file", "file.txt") envState.scopes.set(" file", "src/test/features-data/TodoItems0.csv") envState.scopes.set(" file", "src/test/features-data/TodoItems0.json") envState.scopes.set("/locator", "css selector") @@ -106,6 +105,7 @@ class WebDslTest extends BaseTest with Matchers with MockitoSugar { .replace("", "2") .replace("", "100") .replace("", "80") + .replace("", " file") } foreach { dsl => val iStep = Step(None, StepKeyword.Given.toString, dsl.replaceAll("", """a is "b""""), Nil, None, Nil, None, Pending, Nil, Nil, Nil, None, Nil) engine.evaluateStep(parent, iStep, ctx).evalStatus match { diff --git a/src/test/scala/gwen/web/eval/WebEngineTest.scala b/src/test/scala/gwen/web/eval/WebEngineTest.scala index f5dea550..c26b317e 100644 --- a/src/test/scala/gwen/web/eval/WebEngineTest.scala +++ b/src/test/scala/gwen/web/eval/WebEngineTest.scala @@ -1342,34 +1342,6 @@ class WebEngineTest extends BaseTest with Matchers with MockitoSugar with Before verify(ctx, times(2)).sendKeys(Array("CONTROL", "C")) } - "I wait 1 second when is " should "evaluate" in { - val mockBinding = mock[LocatorBinding] - doReturn(mockBinding).when(ctx).getLocatorBinding("") - events.foreach { event => - evaluate(s"I wait 1 second when is $event") - verify(mockScopes).set(s"/${ElementEvent.actionOf(event)}/wait", "1") - } - } - - "I wait seconds when is " should "evaluate" in { - val mockBinding = mock[LocatorBinding] - doReturn(mockBinding).when(ctx).getLocatorBinding("") - events.foreach { event => - evaluate(s"I wait 2 seconds when is $event") - verify(mockScopes).set(s"/${ElementEvent.actionOf(event)}/wait", "2") - } - } - - "I wait until when is " should "evaluate" in { - val mockBinding = mock[LocatorBinding] - doReturn(mockBinding).when(ctx).getLocatorBinding("") - events.foreach { event => - evaluate(s"I wait until when is $event") - verify(mockScopes).set(s"/${ElementEvent.actionOf(event)}/condition", "") - } - verify(mockScopes, times(events.size)).get("/javascript") - } - """I wait until """"" should "evaluate" in { evaluate("""I wait until """"") }