commit 178e4b87a948889ae46e72d70a7b5143b05258da Author: romanov73 Date: Fri Feb 16 13:59:20 2018 +0400 first import code diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3bac491 --- /dev/null +++ b/.gitignore @@ -0,0 +1,156 @@ + +# Created by https://www.gitignore.io/api/intellij,java,maven,gradle,eclipse,netbeans + +### Intellij ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm + +*.iml +nb-configuration.xml + +## Directory-based project format: +.idea/ +.target +# if you remove the above rule, at least ignore the following: + +# User-specific stuff: +# .idea/workspace.xml +# .idea/tasks.xml +# .idea/dictionaries +# .idea/shelf + +# Sensitive or high-churn files: +# .idea/dataSources.ids +# .idea/dataSources.xml +# .idea/sqlDataSources.xml +# .idea/dynamic.xml +# .idea/uiDesigner.xml + +# Gradle: +# .idea/gradle.xml +# .idea/libraries + +# Mongo Explorer plugin: +# .idea/mongoSettings.xml + +## File-based project format: +*.ipr +*.iws + +## Plugin-specific files: + +# IntelliJ +/out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + + +### Java ### +*.class + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.ear + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* + + +### Maven ### +target/ +pom.xml.tag +pom.xml.releaseBackup +pom.xml.versionsBackup +pom.xml.next +release.properties +dependency-reduced-pom.xml +buildNumber.properties +.mvn/timing.properties + + +### Gradle ### +.gradle +build/ + +# Ignore Gradle GUI config +gradle-app.setting + +# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) +!gradle-wrapper.jar + +# Cache of project +.gradletasknamecache + + +### Eclipse ### + +.metadata +bin/ +tmp/ +*.tmp +*.bak +*.swp +*~.nib +local.properties +.settings/ +.loadpath + +# Eclipse Core +.project + +# External tool builders +.externalToolBuilders/ + +# Locally stored "Eclipse launch configurations" +*.launch + +# PyDev specific (Python IDE for Eclipse) +*.pydevproject + +# CDT-specific (C/C++ Development Tooling) +.cproject + +# JDT-specific (Eclipse Java Development Tools) +.classpath + +# Java annotation processor (APT) +.factorypath + +# PDT-specific (PHP Development Tools) +.buildpath + +# sbteclipse plugin +.target + +# TeXlipse plugin +.texlipse + +# STS (Spring Tool Suite) +.springBeans + + +### NetBeans ### +nbproject/private/ +build/ +nbbuild/ +dist/ +nbdist/ +nbactions.xml +.nb-gradle/ + +*.log + +csv/ \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..f3ab0e1 --- /dev/null +++ b/pom.xml @@ -0,0 +1,44 @@ + + + 4.0.0 + selenium + selenium + 1.0 + + UTF-8 + 1.8 + 1.8 + + + + + org.seleniumhq.selenium + selenium-java + 3.6.0 + + + + + + org.apache.maven.plugins + maven-jar-plugin + 2.4 + + + true + + true + lib/ + ru.ulstu.tis.Main + + + lib/ + + + + + + + \ No newline at end of file diff --git a/src/main/java/ru/ulstu/tis/Main.java b/src/main/java/ru/ulstu/tis/Main.java new file mode 100644 index 0000000..972907e --- /dev/null +++ b/src/main/java/ru/ulstu/tis/Main.java @@ -0,0 +1,53 @@ +package ru.ulstu.tis; + +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.chrome.ChromeDriver; +import org.openqa.selenium.firefox.FirefoxDriver; +import org.openqa.selenium.support.PageFactory; +import org.openqa.selenium.support.ui.ExpectedCondition; +import org.openqa.selenium.support.ui.WebDriverWait; + +import java.util.concurrent.TimeUnit; + +public class Main { + private final static String APP_URL = "http://ya.ru"; + 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 final static String DRIVER_TYPE = "webdriver.chrome.driver"; + + public static void main(String[] args) { + + Main m = new Main(); + WebDriver driver; + System.setProperty(DRIVER_TYPE, m.getDriverExecutable()); + driver = new ChromeDriver(); + driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS); + + 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() { + 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()); + + + driver.quit(); + } + + private String getDriverExecutable() { + return Main.class.getClassLoader().getResource(String.format(DRIVER_LOCATION, WINDOWS_CHROME_DRIVER)).getFile(); + } +} diff --git a/src/main/java/ru/ulstu/tis/SearchPage.java b/src/main/java/ru/ulstu/tis/SearchPage.java new file mode 100644 index 0000000..07690d8 --- /dev/null +++ b/src/main/java/ru/ulstu/tis/SearchPage.java @@ -0,0 +1,28 @@ +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/chromedriver b/src/main/resources/drivers/chromedriver new file mode 100644 index 0000000..02ff671 Binary files /dev/null and b/src/main/resources/drivers/chromedriver differ diff --git a/src/main/resources/drivers/chromedriver.exe b/src/main/resources/drivers/chromedriver.exe new file mode 100644 index 0000000..28a4067 Binary files /dev/null and b/src/main/resources/drivers/chromedriver.exe differ