Skip to content

Commit

Permalink
[vividus-plugin-web-app] Add ability to work with invisible elements …
Browse files Browse the repository at this point in the history
…in nested steps
  • Loading branch information
web-flow committed Mar 10, 2022
1 parent 547a4af commit 9ac7a16
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 18 deletions.
29 changes: 29 additions & 0 deletions docs/modules/plugins/pages/plugin-web-app.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -760,3 +760,32 @@ Then `${info.duration}` is > `1000`
Then `${info.networkState}` is = `2`
Then `${info.src}` matches `.+youtube.+`
----

=== Perform steps for all elements

Executes the steps against all elements found by locator.

[source,gherkin]
----
When I find $comparisonRule `$number` elements by `$locator` and for each element do$stepsToExecute
----

Alias:
[source,gherkin]
----
When I find $comparisonRule '$number' elements by $locator and for each element do$stepsToExecute
----

* `$comparisonRule` - xref:parameters:comparison-rule.adoc[The comparison rule].
* `$number` - The number of elements to find.
* `$locator` - <<_locator>>.
* `$stepsToExecute` - The `ExamplesTable` with a single column containing the steps to execute.

.Script type check
[source,gherkin]
----
When I find = `5` elements by `By.xpath(//script):a` and for each element do
|step |
|When I set 'type' attribute value of the context element to the 'scenario' variable 'type'|
|Then `${type}` is equal to `text/javascript` |
----
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2021 the original author or authors.
* Copyright 2019-2022 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 Down Expand Up @@ -29,6 +29,7 @@
import org.vividus.steps.SubSteps;
import org.vividus.steps.ui.validation.IBaseValidations;
import org.vividus.ui.action.search.Locator;
import org.vividus.ui.action.search.SearchParameters;
import org.vividus.ui.context.IUiContext;
import org.vividus.ui.context.SearchContextSetter;
import org.vividus.ui.web.action.ICssSelectorFactory;
Expand Down Expand Up @@ -97,9 +98,11 @@ public void performAllStepsForElementIfFound(ComparisonRule comparisonRule, int
stepsToExecute.execute(Optional.empty());
});
IntStream.range(1, cssSelectors.size()).forEach(i -> {
SearchParameters searchParameters = new SearchParameters(cssSelectors.get(i),
locator.getSearchParameters().getVisibility());
WebElement element = baseValidations
.assertIfElementExists("An element for iteration " + (i + 1),
new Locator(WebLocatorType.CSS_SELECTOR, cssSelectors.get(i)));
new Locator(WebLocatorType.CSS_SELECTOR, searchParameters));
runStepsWithContextReset(() ->
{
uiContext.putSearchContext(element, () -> { });
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2021 the original author or authors.
* Copyright 2019-2022 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 Down Expand Up @@ -42,6 +42,8 @@
import org.vividus.steps.SubSteps;
import org.vividus.steps.ui.validation.IBaseValidations;
import org.vividus.ui.action.search.Locator;
import org.vividus.ui.action.search.SearchParameters;
import org.vividus.ui.action.search.Visibility;
import org.vividus.ui.context.IUiContext;
import org.vividus.ui.context.SearchContextSetter;
import org.vividus.ui.web.action.ICssSelectorFactory;
Expand Down Expand Up @@ -72,8 +74,9 @@ void testPerformAllStepsForElementIfFound()
ComparisonRule.EQUAL_TO)).thenReturn(Arrays.asList(first, second));
when(cssSelectorFactory.getCssSelectors(List.of(first, second)))
.thenReturn(List.of(FIRST_XPATH, SECOND_XPATH).stream());
Locator secondLocator = new Locator(WebLocatorType.CSS_SELECTOR,
SECOND_XPATH);
SearchParameters searchParameters = new SearchParameters(SECOND_XPATH, Visibility.ALL);
when(locator.getSearchParameters()).thenReturn(searchParameters);
Locator secondLocator = new Locator(WebLocatorType.CSS_SELECTOR, searchParameters);
when(baseValidations.assertIfElementExists("An element for iteration 2",
secondLocator)).thenReturn(second);
SearchContextSetter searchContextSetter = mockSearchContextSetter();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Description: Integration tests for GenericNestedSteps class.

Meta:
@epic vividus-extension-selenium


Scenario: Verify step: When I find $comparisonRule `$number` elements `$locator` and while they exist do up to $iterationLimit iteration of$stepsToExecute
Meta:
@requirementId 2054

Given I am on a page with the URL '${vividus-test-site-url}/elementState.html'
When I find > `0` elements `id(element-to-hide)` and while they exist do up to 10 iteration of
|step |
|When I click on element located `id(button-hide)`|
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
Description: Integration tests for GenericNestedSteps class.

Meta:
@epic vividus-extension-selenium


Scenario: Verify step: When I find $comparisonRule `$number` elements `$locator` and while they exist do up to $iterationLimit iteration of$stepsToExecute
Meta:
@requirementId 2054

Given I am on a page with the URL '${vividus-test-site-url}/elementState.html'
When I find > `0` elements `id(element-to-hide)` and while they exist do up to 10 iteration of
|step |
|When I click on element located `id(button-hide)`|
@epic vividus-plugin-web-app

Scenario: Verify step "When I find $comparisonRule '$number' elements by $locator and for each element do$stepsToExecute"
Given I am on a page with the URL 'https://demo.guru99.com/'
When I find = `5` elements by `By.xpath(//head/link[contains(@href,'V4/css')]):a` and for each element do
|step |
|When I set 'rel' attribute value of the context element to the 'scenario' variable 'relValue' |
|Then `${relValue}` is equal to `stylesheet` |

0 comments on commit 9ac7a16

Please # to comment.