diff --git a/docs/modules/plugins/pages/plugin-web-app.adoc b/docs/modules/plugins/pages/plugin-web-app.adoc index 0d275bb46e..ff798ec4ee 100644 --- a/docs/modules/plugins/pages/plugin-web-app.adoc +++ b/docs/modules/plugins/pages/plugin-web-app.adoc @@ -1114,6 +1114,64 @@ When I click on a button with the name 'Toggle element visibility with delay' Then element located by 'xpath(//div[@id='delayed'])' disappears in 'PT3S' ---- +==== Script Steps + +WARNING: These steps are deprecated and will be removed in VIVIDUS 0.8.0. + +The Script Steps checks for validate the presence of JavaScript files within the HTML source code of an active page. +These steps primarily focus on verifying the existence of specific JavaScript files based on Filename, Text and TextPart attributes. + +=== The script steps on FileName attributes. + +These step primarily focus on checking for the existence of certain JavaScript files based on Filename attributes. + +[source,gherkin] +---- +Then a javascript file with the name '$jsFileName' is included in the source code +---- + +* `$jsFileName` - The JavaScript FileName. In order to save a result return statement should be used. + +.Checks the script for the presence of a document by name +[source,gherkin] +---- +Then a javascript file with the name '$jsFileName' is included in the source code +---- + +=== The script steps on Text attributes. + +These step primarily focus on checking for the existence of certain JavaScript files based on Text attributes. + +[source,gherkin] +---- +Then a javascript with the text '$jsText' is included in the source code +---- + +* `$jsText` - The JavaScript Text. In order to save a result return statement should be used. + +.Checks the script for the presence of a document by text +[source,gherkin] +---- +Then a javascript with the text '$jsText' is included in the source code +---- + +=== The script steps on TextPart attributes. + +These step primarily focus on checking for the existence of certain JavaScript files based on TextPart attributes. + +[source,gherkin] +---- +Then a javascript file with the name '$jsTextPart' is included in the source code +---- + +* `$jsTextPart` - The JavaScript TextPart. In order to save a result return statement should be used. + +.Checks the script for the presence of a document by TextPart +[source,gherkin] +---- +Then a javascript file with the name '$jsTextPart' is included in the source code +---- + === Set Variable Steps ==== Save HTML table to the variable diff --git a/vividus-plugin-web-app/src/main/java/org/vividus/steps/ui/web/ScriptSteps.java b/vividus-plugin-web-app/src/main/java/org/vividus/steps/ui/web/ScriptSteps.java index ce359bf23b..ef303ec7e8 100644 --- a/vividus-plugin-web-app/src/main/java/org/vividus/steps/ui/web/ScriptSteps.java +++ b/vividus-plugin-web-app/src/main/java/org/vividus/steps/ui/web/ScriptSteps.java @@ -50,10 +50,10 @@ public class ScriptSteps @Then("a javascript file with the name '$jsFileName' is included in the source code") public WebElement thenJavascriptFileWithNameIsIncludedInTheSourceCode(String jsFileName) { - return baseValidations.assertIfElementExists(String.format("Script with the name '%s'", jsFileName), + return baseValidations.assertElementExists(String.format("Script with the name '%s'", jsFileName), new Locator(WebLocatorType.XPATH, new SearchParameters(XpathLocatorUtils.getXPath(".//script[contains(@src, %s)]", jsFileName), - Visibility.ALL))); + Visibility.ALL))).orElse(null); } /** @@ -75,10 +75,10 @@ public WebElement thenJavascriptFileWithNameIsIncludedInTheSourceCode(String jsF @Then("a javascript with the text '$jsText' is included in the source code") public WebElement thenJavascriptFileWithTextIsIncludedInTheSourceCode(String jsText) { - return baseValidations.assertIfElementExists(String.format("Script with text '%s'", jsText), + return baseValidations.assertElementExists(String.format("Script with text '%s'", jsText), new Locator(WebLocatorType.XPATH, new SearchParameters(XpathLocatorUtils.getXPath(".//script[text()=%s]", jsText), - Visibility.ALL))); + Visibility.ALL))).orElse(null); } /** @@ -100,9 +100,9 @@ public WebElement thenJavascriptFileWithTextIsIncludedInTheSourceCode(String jsT @Then("a javascript with the textpart '$jsTextPart' is included in the source code") public WebElement thenJavascriptWithTextPartIsIncludedInTheSourceCode(String jsTextPart) { - return baseValidations.assertIfElementExists(String.format("Script with the text part '%s'", jsTextPart), + return baseValidations.assertElementExists(String.format("Script with the text part '%s'", jsTextPart), new Locator(WebLocatorType.XPATH, new SearchParameters(XpathLocatorUtils.getXPath(".//script[contains(text(),%s)]", jsTextPart), - Visibility.ALL))); + Visibility.ALL))).orElse(null); } } diff --git a/vividus-plugin-web-app/src/test/java/org/vividus/steps/ui/web/ScriptStepsTests.java b/vividus-plugin-web-app/src/test/java/org/vividus/steps/ui/web/ScriptStepsTests.java index 82d3c8fd3f..2a39471a64 100644 --- a/vividus-plugin-web-app/src/test/java/org/vividus/steps/ui/web/ScriptStepsTests.java +++ b/vividus-plugin-web-app/src/test/java/org/vividus/steps/ui/web/ScriptStepsTests.java @@ -31,6 +31,8 @@ import org.vividus.ui.action.search.Visibility; import org.vividus.ui.web.action.search.WebLocatorType; +import java.util.Optional; + @ExtendWith(MockitoExtension.class) class ScriptStepsTests { @@ -48,30 +50,30 @@ class ScriptStepsTests @Test void testThenJavascriptFileWithNameIsIncludedInTheSourceCode() { - when(baseValidations.assertIfElementExists("Script with the name 'test'", + when(baseValidations.assertElementExists("Script with the name 'test'", new Locator(WebLocatorType.XPATH, new SearchParameters(".//script[contains(normalize-space(@src), \"test\")]", Visibility.ALL)))) - .thenReturn(mockedScript); + .thenReturn(Optional.of(mockedScript)); assertEquals(scriptSteps.thenJavascriptFileWithNameIsIncludedInTheSourceCode(TEST), mockedScript); } @Test void testThenJavascriptFileWithTextIsIncludedInTheSourceCode() { - when(baseValidations.assertIfElementExists("Script with text 'test'", + when(baseValidations.assertElementExists("Script with text 'test'", new Locator(WebLocatorType.XPATH, new SearchParameters(".//script[text()[normalize-space()=\"test\"]]", Visibility.ALL)))) - .thenReturn(mockedScript); + .thenReturn(Optional.of(mockedScript)); assertEquals(scriptSteps.thenJavascriptFileWithTextIsIncludedInTheSourceCode(TEST), mockedScript); } @Test void testThenJavascriptWithTextPartIsIncludedInTheSourceCode() { - when(baseValidations.assertIfElementExists("Script with the text part 'test'", + when(baseValidations.assertElementExists("Script with the text part 'test'", new Locator(WebLocatorType.XPATH, new SearchParameters(".//script[contains(normalize-space(text()),\"test\")]", Visibility.ALL)))) - .thenReturn(mockedScript); + .thenReturn(Optional.of(mockedScript)); assertEquals(scriptSteps.thenJavascriptWithTextPartIsIncludedInTheSourceCode(TEST), mockedScript); } }