Улучшено тестирование поиска. Теперь проверяет элементы на странице. Версия 2.0

This commit is contained in:
Антон Скалкин 2018-05-13 18:28:40 +04:00
parent 224452000a
commit 76e1d98652
5 changed files with 62 additions and 25 deletions

View File

@ -36,7 +36,7 @@ public class SearchTests {
page.enterSearch();
SearchExtendedResultPage pageTo = PageFactory.initElements(context.getDriver(), SearchExtendedResultPage.class);//Корректно отображена выбранная страница
Assertions.assertTrue(pageTo.isFirstResultElementPresent());
Assertions.assertTrue(pageTo.isKomaFromResultElementPresent());
}
@Test
@ -50,7 +50,7 @@ public class SearchTests {
page.enterSearch();
SearchExtendedResultPage pageResult = PageFactory.initElements(context.getDriver(), SearchExtendedResultPage.class);//Корректно отображена выбранная страница
Assertions.assertTrue(pageResult.isFirstResultElementPresent());
Assertions.assertTrue(pageResult.isKomaFromResultElementPresent());
}
@Test
@ -66,7 +66,7 @@ public class SearchTests {
page.enterSearch();
SearchByCreatorsResultPage pageResult = PageFactory.initElements(context.getDriver(), SearchByCreatorsResultPage.class);//Корректно отображена выбранная страница
Assertions.assertTrue(pageResult.isFirstResultCreatorsPresent());
Assertions.assertTrue(pageResult.isBrigadaFromResultCreatorsPresent());
}
@Test
@ -78,7 +78,7 @@ public class SearchTests {
page.enterSearch();
SearchExtendedResultPage pageResult = PageFactory.initElements(context.getDriver(), SearchExtendedResultPage.class);//Корректно отображена выбранная страница
Assertions.assertTrue(pageResult.isActorResultElementPresent());
Assertions.assertTrue(pageResult.isBezrukovFromResultElementPresent());
}
@Test
@ -91,7 +91,8 @@ public class SearchTests {
SearchInTextResultPage pageResult = PageFactory.initElements(context.getDriver(), SearchInTextResultPage.class);//Корректно отображена выбранная страница
String str = pageResult.getNewsElementToString();
Assertions.assertTrue(pageResult.getNewsElementToString().contains("Веном"));
Assertions.assertTrue(pageResult.isListElementPresent("Веном"));
}
@Test

View File

@ -11,7 +11,7 @@ public class SearchByCreatorsResultPage {
private WebElement resultCreatorsElement;
@FindBy(xpath = "//a[@href='/film/brigada-2002-77039/sr/1/']")
private WebElement firstResultCreatorsElement;
private WebElement brigadaFromResultCreatorsElement;
@FindBy(xpath = "//a[@href='/film/garri-potter-i-filosofskiy-kamen-2001-689/sr/1/']")
private WebElement firstResultByWordElement;
@ -24,8 +24,8 @@ public class SearchByCreatorsResultPage {
return firstResultByWordElement.isDisplayed();
}
public boolean isFirstResultCreatorsPresent() {
return firstResultCreatorsElement.isDisplayed();
public boolean isBrigadaFromResultCreatorsPresent() {
return brigadaFromResultCreatorsElement.isDisplayed();
}
public boolean isResultCreatorsPresent() {

View File

@ -4,21 +4,32 @@ import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import java.util.List;
public class SearchByKeywordResultPage {
WebDriver driver;
@FindBy(css = ".news")
private WebElement newsElement;
@FindBy(css = ".all")
private WebElement firstResultElement;
@FindBy(xpath = "//*[@id=\'block_left_pad\']/div/table/tbody/tr/td/table[2]/tbody/tr/td/table[1]/tbody/tr")
private List<WebElement> listResultElement;
public SearchByKeywordResultPage(WebDriver driver) {
this.driver = driver;
}
public boolean isFirstResultElementPresent(String str) {
return firstResultElement.getText().toLowerCase().contains(str.toLowerCase());
public boolean isFirstResultElementPresent(String text) { //
boolean matched = true;
for (int i = 0; i < listResultElement.size()-1; i++) {
String str = listResultElement.get(i).getText();
if((i-2) % 3 == 0 && !str.toLowerCase().contains(text.toLowerCase())){
matched = false;
//break;
}
}
return matched;
}
public boolean isNewsElementPresent() {

View File

@ -4,6 +4,8 @@ import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import java.util.List;
public class SearchExtendedResultPage {
WebDriver driver;
@ -11,28 +13,38 @@ public class SearchExtendedResultPage {
private WebElement resultTopElement;
@FindBy(xpath = "//a[@href='/film/koma-2018-933208/sr/1/']")
private WebElement firstResultElement;
private WebElement komaFromResultElement;
@FindBy(xpath = "//a[@href='/name/224620/sr/1/']")
private WebElement actorResultElement;
private WebElement bezrukovFromResultElement;
@FindBy(css = ".element")
private List<WebElement> usersListResultElement;
@FindBy(css = ".gray")
private WebElement usersResultElement;
public SearchExtendedResultPage(WebDriver driver) {
this.driver = driver;
}
public boolean isUsersResultElementPresent(String str) {
return usersResultElement.getText().contains(str);
public boolean isUsersResultElementPresent(String text) {
boolean matched = true;
for (int i = 0; i < usersListResultElement.size(); i++) {
if(!usersListResultElement.get(i).getText().toLowerCase().contains(text.toLowerCase())){
matched = false;
break;
}
}
return matched;
}
public boolean isActorResultElementPresent() {
return actorResultElement.isDisplayed();
public boolean isBezrukovFromResultElementPresent() {
return bezrukovFromResultElement.isDisplayed();
}
public boolean isFirstResultElementPresent() {
return firstResultElement.isDisplayed();
public boolean isKomaFromResultElementPresent() {
return komaFromResultElement.isDisplayed();
}
public boolean isResultTopElementPresent() {

View File

@ -4,6 +4,9 @@ import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import java.lang.reflect.Method;
import java.util.List;
public class SearchInTextResultPage {
WebDriver driver;
@ -11,8 +14,10 @@ public class SearchInTextResultPage {
private WebElement headerElement;
@FindBy(css = ".news")
private WebElement newsElement;
private WebElement newsElement; //
@FindBy(xpath = "//*[@id='block_left_pad']/div/table/tbody/tr/td/table[2]/tbody/tr/td/table[2]/tbody/tr")
private List<WebElement> listNewsElement;
public SearchInTextResultPage(WebDriver driver) {
this.driver = driver;
@ -22,7 +27,15 @@ public class SearchInTextResultPage {
return newsElement.getText();
}
public boolean isHeaderElementPresent() {
return headerElement.isDisplayed();
public boolean isListElementPresent(String text) {
boolean matched = true;
for (int i = 4; i < listNewsElement.size(); i++) {
if((i-1) % 3 == 0 && !listNewsElement.get(i).getText().toLowerCase().contains(text.toLowerCase())){
matched = false;
break;
}
}
return matched;
}
}