Skip to content

Commit

Permalink
Add document and change the syntax on the Script Steps
Browse files Browse the repository at this point in the history
  • Loading branch information
Khodyka Liubov authored and Khodyka Liubov committed Nov 28, 2023
1 parent 74c1327 commit 158ce16
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 12 deletions.
58 changes: 58 additions & 0 deletions docs/modules/plugins/pages/plugin-web-app.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand All @@ -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);
}

/**
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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);
}
}

0 comments on commit 158ce16

Please sign in to comment.