change search page
This commit is contained in:
parent
dce6fd4ccd
commit
d9b601b291
4
pom.xml
4
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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>selenium</groupId>
|
||||
<artifactId>selenium</artifactId>
|
||||
<groupId>tis-2017</groupId>
|
||||
<artifactId>tis-2017</artifactId>
|
||||
<version>1.0</version>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
|
@ -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<WebElement> 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();
|
||||
}
|
||||
}
|
0
src/main/resources/drivers/geckodriver
Normal file → Executable file
0
src/main/resources/drivers/geckodriver
Normal file → Executable file
@ -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<Boolean>() {
|
||||
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());
|
||||
}
|
||||
}
|
@ -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() {
|
||||
|
41
src/test/java/page/SearchPage.java
Normal file
41
src/test/java/page/SearchPage.java
Normal file
@ -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();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user