Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[vividus-plugin-web-app] Add ability to use visibility in nested steps #2563

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 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,36 @@ Then `${info.duration}` is > `1000`
Then `${info.networkState}` is = `2`
Then `${info.src}` matches `.+youtube.+`
----

=== Perform steps for each found element

Executes the steps against all elements found by locator. After a required number of elements is found,
search context switches in order for each found element and performs all steps on it.

[IMPORTANT]
If comparison rule mismatch steps will not be performed even if elements are found.

[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,12 @@
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
@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 '${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)`|
When I find = `2` elements by `By.xpath(//div):a` and for each element do
|step |
|When I set 'id' attribute value of the context element to the 'scenario' variable 'idValue' |
|Then `${idValue}` matches `element-to-.*` |