This commit is contained in:
romanov73 2018-02-16 17:00:44 +04:00
parent 7a08e1ec83
commit 22bad673df
6 changed files with 54 additions and 14 deletions

View File

@ -21,6 +21,7 @@ public class Main {
Main m = new Main();
WebDriver driver;
System.setProperty(DRIVER_TYPE, m.getDriverExecutable());
driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);

View File

@ -8,8 +8,10 @@ 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;
private WebElement startSearchButton;
@FindBys(@FindBy(xpath = "//div[@class='main__content']//a"))
private List<WebElement> links;

0
src/main/resources/drivers/chromedriver Normal file → Executable file
View File

View File

@ -3,38 +3,51 @@ import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import ru.ulstu.tis.Main;
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 utils.TestingUtils;
import java.util.concurrent.TimeUnit;
public class YandexSearch {
private final static String APP_URL = "http://ya.ru";
private final static String DRIVER_TYPE = "webdriver.chrome.driver";
private final static String DRIVER_LOCATION = "drivers/%s";
private final static String WINDOWS_CHROME_DRIVER = "chromedriver.exe";
private final static String LINUX_CHROME_DRIVER = "chromedriver";
private static WebDriver driver;
@BeforeAll
public static void setup() {
System.setProperty(DRIVER_TYPE, getDriverExecutable());
System.setProperty(DRIVER_TYPE, TestingUtils.getDriverExecutablePath());
driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);
}
@Test
public void testGetFreeEmployeesNextUnits() {
public void testResultPageHeader() {
driver.get(APP_URL);
String searchString = "QA automation";
SearchPage page = PageFactory.initElements(driver, SearchPage.class);
page.setSearchString(searchString);
page.clickSubmitButton();
System.out.println("Page title is: " + driver.getTitle());
(new WebDriverWait(driver, 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: " + driver.getTitle());
}
@AfterAll
public static void quit() {
driver.quit();
}
private static String getDriverExecutable() {
return YandexSearch.class.getClassLoader().getResource(String.format(DRIVER_LOCATION, WINDOWS_CHROME_DRIVER)).getFile();
}
}

View File

@ -0,0 +1,8 @@
package utils;
public class SystemUtils {
public static boolean isWindows() {
return System.getProperty("os.name").toLowerCase().contains("windows");
}
}

View File

@ -0,0 +1,16 @@
package utils;
import static utils.SystemUtils.isWindows;
public class TestingUtils {
private final static String DRIVER_LOCATION = "drivers/%s";
private final static String WINDOWS_CHROME_DRIVER = "chromedriver.exe";
private final static String LINUX_CHROME_DRIVER = "chromedriver";
public static String getDriverExecutablePath() {
return TestingUtils.class.getClassLoader().getResource(
String.format(DRIVER_LOCATION, isWindows()
? WINDOWS_CHROME_DRIVER
: LINUX_CHROME_DRIVER)).getFile();
}
}