Skip to content

Commit

Permalink
Add replacement annotation to deprecated script steps and add documen…
Browse files Browse the repository at this point in the history
…tation
  • Loading branch information
Khodyka Liubov authored and Khodyka Liubov committed Jan 8, 2024
1 parent 3916ac6 commit 17051b1
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 1 deletion.
85 changes: 85 additions & 0 deletions docs/modules/plugins/pages/plugin-web-app.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -1250,6 +1250,91 @@ When I wait until scroll is finished
Then page is scrolled to element located by `id(footerElement)`
----

=== Script Steps

The Script Steps verify the presence of JavaScript files in the HTML source code of an active page.

==== Check the presence of script resource

[WARNING]
====
This step is deprecated and will be removed in VIVIDUS 0.7.0.
Please see the replacement pattern below:
[source,gherkin]
----
Then number of elements found by `xpath(.//script[contains(@src()='<jsFileName>']):a` is equal to `1`
----
====

Checks script (an element with the `<script>` tag) with the specified path (`@src` attribute) is included on the page.

[source,gherkin]
----
Then a javascript file with the name '$jsFileName' is included in the source code
----

* `$jsFileName` - The part of the script resource URL from the `@src` attribute.

.Checks if the javascript with the 'script.js' filename exists in the page source code
[source,gherkin]
----
Then a javascript file with the name 'script.js' is included in the source code.
----

==== Check the presence of script code

[WARNING]
====
This step is deprecated and will be removed in VIVIDUS 0.7.0.
Please see the replacement pattern below:
[source,gherkin]
----
Then number of elements found by `xpath(.//script[text()='<jsText>']):a` is equal to `1`
----
====

Checks the page contains a script (an element with the '<script>' tag) whose content is equal to the specified text.

[source,gherkin]
----
Then a javascript with the text '$jsText' is included in the source code
----

* `$jsText` - The expected text to be equal to the text of a `<script>` tag.

.Checks if the JavaScript code equals to the expected one
[source,gherkin]
----
Then a javascript with the text 'document.getElementById("demo-for-script").innerHTML = "Hello JavaScript!";' is included in the source code
----

==== Check script contains code

[WARNING]
====
This step is deprecated and will be removed in VIVIDUS 0.7.0.
Please see the replacement pattern below:
[source,gherkin]
----
Then number of elements found by `xpath(.//script[contains(text(),'<jsTextPart>')]):a` is equal to `1`
----
====

Checks the page contains a script (an element with the '<script>' tag) whose content contains the specified text.

[source,gherkin]
----
Then a javascript with the textpart '$jsTextPart' is included in the source code
----

* `$jsTextPart` - The expected text to be contained in the text of a `<script>` tag.

.Checks if the JavaScript code contains 'Hello JavaScript'
[source,gherkin]
----
Then a javascript with the textpart 'Hello JavaScript' 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
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2023 the original author or authors.
* Copyright 2019-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -18,6 +18,7 @@

import org.jbehave.core.annotations.Then;
import org.openqa.selenium.WebElement;
import org.vividus.annotation.Replacement;
import org.vividus.selenium.locator.Locator;
import org.vividus.steps.ui.validation.IBaseValidations;
import org.vividus.ui.action.search.SearchParameters;
Expand Down Expand Up @@ -46,8 +47,14 @@ public class ScriptSteps
*
* @param jsFileName Value of the <i>src</i> attribute
* @return webElement found js script
* @deprecated Use step:
* "Then number of elements found by `xpath(.//script[contains(@src()='$jsFileName']):a` is equal to `1`" instead
*/
@Deprecated(since = "0.6.6", forRemoval = true)
@Then("a javascript file with the name '$jsFileName' is included in the source code")
@Replacement(versionToRemoveStep = "0.7.0",
replacementFormatPattern = "Then number of elements found by `xpath(.//script[contains(@src()='%1$s']):a` "
+ "is equal to `1`")
public WebElement thenJavascriptFileWithNameIsIncludedInTheSourceCode(String jsFileName)
{
return baseValidations.assertIfElementExists(String.format("Script with the name '%s'", jsFileName),
Expand All @@ -71,8 +78,14 @@ public WebElement thenJavascriptFileWithNameIsIncludedInTheSourceCode(String jsF
*
* @param jsText Content of the <i>{@literal <script>}</i> tag.
* @return webElement found js script
* @deprecated Use step:
* "Then number of elements found by `xpath(.//script[text()='$jsText']):a` is equal to `1`" instead
*/
@Deprecated(since = "0.6.6", forRemoval = true)
@Then("a javascript with the text '$jsText' is included in the source code")
@Replacement(versionToRemoveStep = "0.7.0",
replacementFormatPattern = "Then number of elements found by `xpath(.//script[text()='%1$s']):a` "
+ "is equal to `1`")
public WebElement thenJavascriptFileWithTextIsIncludedInTheSourceCode(String jsText)
{
return baseValidations.assertIfElementExists(String.format("Script with text '%s'", jsText),
Expand All @@ -96,8 +109,14 @@ public WebElement thenJavascriptFileWithTextIsIncludedInTheSourceCode(String jsT
*
* @param jsTextPart String which should be contained in the <i>{@literal <script>}</i> tag.
* @return webElement found js script
* @deprecated Use step:
* "Then number of elements found by `xpath(.//script[contains(text(),'$jsTextPart')]):a` is equal to `1`" instead
*/
@Deprecated(since = "0.6.6", forRemoval = true)
@Then("a javascript with the textpart '$jsTextPart' is included in the source code")
@Replacement(versionToRemoveStep = "0.7.0",
replacementFormatPattern = "Then number of elements found by `xpath(.//script[contains(text(),'%1$s')]):a` "
+ "is equal to `1`")
public WebElement thenJavascriptWithTextPartIsIncludedInTheSourceCode(String jsTextPart)
{
return baseValidations.assertIfElementExists(String.format("Script with the text part '%s'", jsTextPart),
Expand Down

0 comments on commit 17051b1

Please sign in to comment.