From d9b601b291e37ba9b8ef4617e07e2423798ae869 Mon Sep 17 00:00:00 2001 From: romanov73 Date: Sat, 17 Feb 2018 11:26:14 +0400 Subject: [PATCH] change search page --- pom.xml | 4 +- src/main/java/ru/ulstu/tis/SearchPage.java | 30 ------------- src/main/resources/drivers/geckodriver | Bin ...andexSearch.java => GithubUserSearch.java} | 29 +++++-------- src/test/java/context/Context.java | 3 +- src/test/java/page/SearchPage.java | 41 ++++++++++++++++++ 6 files changed, 56 insertions(+), 51 deletions(-) delete mode 100644 src/main/java/ru/ulstu/tis/SearchPage.java mode change 100644 => 100755 src/main/resources/drivers/geckodriver rename src/test/java/{YandexSearch.java => GithubUserSearch.java} (53%) create mode 100644 src/test/java/page/SearchPage.java diff --git a/pom.xml b/pom.xml index 4b647d9..756ca36 100644 --- a/pom.xml +++ b/pom.xml @@ -3,8 +3,8 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - selenium - selenium + tis-2017 + tis-2017 1.0 UTF-8 diff --git a/src/main/java/ru/ulstu/tis/SearchPage.java b/src/main/java/ru/ulstu/tis/SearchPage.java deleted file mode 100644 index 8310c7f..0000000 --- a/src/main/java/ru/ulstu/tis/SearchPage.java +++ /dev/null @@ -1,30 +0,0 @@ -package ru.ulstu.tis; - -import java.util.List; -import org.openqa.selenium.WebElement; -import org.openqa.selenium.support.FindBy; -import org.openqa.selenium.support.FindBys; - -public class SearchPage { - @FindBy(xpath = "//*[@id='text']") - private WebElement inputField; - - @FindBy(xpath="/html/body/table/tbody/tr[2]/td/form/div[2]/button") - private WebElement startSearchButton; - - @FindBys(@FindBy(xpath = "//div[@class='main__content']//a")) - private List links; - - public SearchPage setSearchString(String text){ - inputField.sendKeys(text); - return this; - } - - public void clickSubmitButton() { - startSearchButton.click(); - } - - public boolean isResultContainsText(String text) { - return links.stream().filter(link -> link.getText().contains(text)).findAny().isPresent(); - } -} diff --git a/src/main/resources/drivers/geckodriver b/src/main/resources/drivers/geckodriver old mode 100644 new mode 100755 diff --git a/src/test/java/YandexSearch.java b/src/test/java/GithubUserSearch.java similarity index 53% rename from src/test/java/YandexSearch.java rename to src/test/java/GithubUserSearch.java index c93c3cc..1d31169 100644 --- a/src/test/java/YandexSearch.java +++ b/src/test/java/GithubUserSearch.java @@ -2,50 +2,43 @@ import context.ChromeContext; import context.Context; import context.FirefoxContext; import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; +import org.openqa.selenium.Dimension; import org.openqa.selenium.WebDriver; import org.openqa.selenium.support.PageFactory; import org.openqa.selenium.support.ui.ExpectedCondition; import org.openqa.selenium.support.ui.WebDriverWait; -import ru.ulstu.tis.SearchPage; +import page.SearchPage; -public class YandexSearch { - private final static String APP_URL = "http://ya.ru"; +public class GithubUserSearch { + private final static String APP_URL = "https://github.com/"; private static Context context; @BeforeAll public static void setup() { - context = new FirefoxContext(); + context = new ChromeContext(); context.start(); + context.getDriver().manage().window().setSize(new Dimension(1600,900)); } @AfterAll public static void quit() { - context.close();; + context.close(); } @Test public void testResultPageHeader() { context.getDriver().get(APP_URL); - String searchString = "QA automation"; + String searchString = "romanov73"; SearchPage page = PageFactory.initElements(context.getDriver(), SearchPage.class); page.setSearchString(searchString); page.clickSubmitButton(); - - System.out.println("Page title is: " + context.getDriver().getTitle()); - - - (new WebDriverWait(context.getDriver(), 10)).until(new ExpectedCondition() { - public Boolean apply(WebDriver d) { - return d.getTitle().toLowerCase().startsWith("qa"); - } - }); - System.out.println("Page contains result? " + page.isResultContainsText(searchString)); - - System.out.println("Page title is: " + context.getDriver().getTitle()); + page.clickUsersLink(); + Assertions.assertTrue(page.isUserPresent()); } } diff --git a/src/test/java/context/Context.java b/src/test/java/context/Context.java index 8c7d88a..928d5dd 100644 --- a/src/test/java/context/Context.java +++ b/src/test/java/context/Context.java @@ -18,7 +18,8 @@ public abstract class Context { public void start() { System.setProperty(getDriverType(), getDriverExecutablePath()); createDriver(); - driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS); + // это плохая инструкция для автотестов, т.к. лучше задавать для конкретного элемента или кейса + driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); } public void close() { diff --git a/src/test/java/page/SearchPage.java b/src/test/java/page/SearchPage.java new file mode 100644 index 0000000..d358cfe --- /dev/null +++ b/src/test/java/page/SearchPage.java @@ -0,0 +1,41 @@ +package page; + +import java.util.List; + +import org.openqa.selenium.By; +import org.openqa.selenium.Keys; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.FindBy; +import org.openqa.selenium.support.FindBys; + +public class SearchPage { + WebDriver driver; + + @FindBy(xpath = "/html/body/div[1]/header/div/div[2]/div/div/div/form/label/input[1]") + private WebElement inputField; + + @FindBy(xpath = "//*[@id=\"js-pjax-container\"]/div/div[1]/div[1]/nav/a[7]/span") + private WebElement usersLink; + + public SearchPage(WebDriver driver) { + this.driver = driver; + } + + public SearchPage setSearchString(String text){ + inputField.sendKeys(text); + return this; + } + + public void clickSubmitButton() { + inputField.sendKeys(Keys.RETURN); + } + + public void clickUsersLink() { + usersLink.click(); + } + + public boolean isUserPresent() { + return driver.findElement(By.cssSelector(".user-list-info")).isDisplayed(); + } +}