Skip to content

Commit

Permalink
add CheckSteps
Browse files Browse the repository at this point in the history
  • Loading branch information
Yaromudr committed Nov 8, 2017
1 parent 0fd7da8 commit 54dba2b
Showing 1 changed file with 33 additions and 2 deletions.
35 changes: 33 additions & 2 deletions src/main/java/ru/colibri/ui/steps/general/CheckSteps.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package ru.colibri.ui.steps.general;

import org.hamcrest.CoreMatchers;
import org.jbehave.core.annotations.Named;
import org.jbehave.core.annotations.Then;
import org.openqa.selenium.WebElement;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -9,9 +11,11 @@
import ru.colibri.ui.settings.general.PropertyUtils;
import ru.yandex.qatools.allure.annotations.Step;

import java.util.List;

import static java.lang.String.format;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.hamcrest.Matchers.containsString;
import static org.junit.Assert.*;

@Component
public class CheckSteps extends AbsSteps {
Expand Down Expand Up @@ -45,4 +49,31 @@ public void stepCheckNotExistField(String fieldName) {
increaseImplicitlyWait();
assertEquals("Найден элемент на странице", 0, sizeOfList);
}

@Step
@Then("каждый элемент \"$elementName\" содержит значение \"$template\" без учета регистра")
public void eachElementContainsValue(@Named("$elementName") String elementName, @Named("$template") String template) {
IElement element = getCurrentPage().getElementByName(elementName);
List<WebElement> elementsFound = finder.findWebElements(element);
String expectedValue = propertyUtils.injectProperties(template);
elementsFound.forEach(elem -> {
assertThat("Элемент не содержит заданное значение", elem.getText().toLowerCase(), containsString(expectedValue.toLowerCase()));
});
}

@Step
@Then("каждый элемент \"$elementName\" содержит любое из значений \"$template1\" или \"$template2\" без учета регистра")
public void eachElementContainsOneOfTwoValues(@Named("$elementName") String elementName, @Named("$template1") String templateOne, @Named("$template2") String templateTwo) {
IElement element = getCurrentPage().getElementByName(elementName);
List<WebElement> elementsFound = finder.findWebElements(element);
String expectedValueOne = propertyUtils.injectProperties(templateOne);
String expectedValueTwo = propertyUtils.injectProperties(templateTwo);
elementsFound.forEach(elem -> {
assertThat("Элемент не содержит ни одно из заданных значений", elem.getText().toLowerCase(), CoreMatchers.anyOf(
containsString(expectedValueOne.toLowerCase()),
containsString(expectedValueTwo.toLowerCase())
));
});
}

}

0 comments on commit 54dba2b

Please sign in to comment.