diff --git a/Skalkin/.gitignore b/Skalkin/.gitignore new file mode 100644 index 0000000..3bac491 --- /dev/null +++ b/Skalkin/.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/Skalkin/README.md b/Skalkin/README.md new file mode 100644 index 0000000..635e81b --- /dev/null +++ b/Skalkin/README.md @@ -0,0 +1,2 @@ +Selenium WebDriver example project + diff --git a/Skalkin/pom.xml b/Skalkin/pom.xml new file mode 100644 index 0000000..756ca36 --- /dev/null +++ b/Skalkin/pom.xml @@ -0,0 +1,49 @@ + + + 4.0.0 + tis-2017 + tis-2017 + 1.0 + + UTF-8 + 1.8 + 1.8 + + + + + org.seleniumhq.selenium + selenium-java + 3.6.0 + + + org.junit.jupiter + junit-jupiter-api + 5.1.0-RC1 + + + + + + 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/Skalkin/src/main/java/ru/ulstu/tis/Main.java b/Skalkin/src/main/java/ru/ulstu/tis/Main.java new file mode 100644 index 0000000..aa6f1d2 --- /dev/null +++ b/Skalkin/src/main/java/ru/ulstu/tis/Main.java @@ -0,0 +1,8 @@ +package ru.ulstu.tis; + +public class Main { + + public static void main(String[] args) { + System.out.println("666"); + } +} diff --git a/Skalkin/src/main/resources/drivers/chromedriver b/Skalkin/src/main/resources/drivers/chromedriver new file mode 100644 index 0000000..02ff671 Binary files /dev/null and b/Skalkin/src/main/resources/drivers/chromedriver differ diff --git a/Skalkin/src/main/resources/drivers/chromedriver.exe b/Skalkin/src/main/resources/drivers/chromedriver.exe new file mode 100644 index 0000000..28a4067 Binary files /dev/null and b/Skalkin/src/main/resources/drivers/chromedriver.exe differ diff --git a/Skalkin/src/main/resources/drivers/geckodriver b/Skalkin/src/main/resources/drivers/geckodriver new file mode 100644 index 0000000..ba1da8c Binary files /dev/null and b/Skalkin/src/main/resources/drivers/geckodriver differ diff --git a/Skalkin/src/main/resources/drivers/geckodriver.exe b/Skalkin/src/main/resources/drivers/geckodriver.exe new file mode 100644 index 0000000..6208aa8 Binary files /dev/null and b/Skalkin/src/main/resources/drivers/geckodriver.exe differ diff --git a/Skalkin/src/test/java/GithubUserSearch.java b/Skalkin/src/test/java/GithubUserSearch.java new file mode 100644 index 0000000..68e7ddd --- /dev/null +++ b/Skalkin/src/test/java/GithubUserSearch.java @@ -0,0 +1,40 @@ +import context.ChromeContext; +import context.Context; +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.support.PageFactory; +import page.SearchPage; + + +public class GithubUserSearch { + private final static String APP_URL = "https://github.com/"; + + private static Context context; + + @BeforeAll + public static void setup() { + context = new ChromeContext(); + context.start(); + context.getDriver().manage().window().setSize(new Dimension(1600, 900)); + } + + @AfterAll + public static void quit() { + context.close(); + } + + @Test + public void testResultPageHeader() { + context.getDriver().get(APP_URL); + String searchString = "romanov73"; + + SearchPage page = PageFactory.initElements(context.getDriver(), SearchPage.class); + page.setSearchString(searchString); + page.clickSubmitButton(); + page.clickUsersLink(); + Assertions.assertTrue(page.isUserPresent()); + } +} diff --git a/Skalkin/src/test/java/context/ChromeContext.java b/Skalkin/src/test/java/context/ChromeContext.java new file mode 100644 index 0000000..05d9cde --- /dev/null +++ b/Skalkin/src/test/java/context/ChromeContext.java @@ -0,0 +1,24 @@ +package context; + +import org.openqa.selenium.chrome.ChromeDriver; + +public class ChromeContext extends Context { + private final static String WINDOWS_DRIVER = "chromedriver.exe"; + private final static String LINUX_DRIVER = "chromedriver"; + private final static String DRIVER_TYPE = "webdriver.chrome.driver"; + + @Override + protected void createDriver() { + driver = new ChromeDriver(); + } + + @Override + protected String getDriverExecutable(boolean isWindows) { + return isWindows ? WINDOWS_DRIVER : LINUX_DRIVER; + } + + @Override + protected String getDriverType() { + return DRIVER_TYPE; + } +} diff --git a/Skalkin/src/test/java/context/Context.java b/Skalkin/src/test/java/context/Context.java new file mode 100644 index 0000000..928d5dd --- /dev/null +++ b/Skalkin/src/test/java/context/Context.java @@ -0,0 +1,43 @@ +package context; + +import org.openqa.selenium.WebDriver; + +import java.util.concurrent.TimeUnit; + +public abstract class Context { + private final static String DRIVER_LOCATION = "drivers/%s"; + protected WebDriver driver; + + public WebDriver getDriver() { + if (driver != null) { + return driver; + } + throw new IllegalStateException("WebDriver is not initialized"); + } + + public void start() { + System.setProperty(getDriverType(), getDriverExecutablePath()); + createDriver(); + // это плохая инструкция для автотестов, т.к. лучше задавать для конкретного элемента или кейса + driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); + } + + public void close() { + driver.quit(); + } + + protected abstract void createDriver(); + + protected abstract String getDriverType(); + + protected abstract String getDriverExecutable(boolean windows); + + private String getDriverExecutablePath() { + return Context.class.getClassLoader().getResource( + String.format(DRIVER_LOCATION, getDriverExecutable(isWindows()))).getFile(); + } + + private boolean isWindows() { + return System.getProperty("os.name").toLowerCase().contains("windows"); + } +} diff --git a/Skalkin/src/test/java/context/FirefoxContext.java b/Skalkin/src/test/java/context/FirefoxContext.java new file mode 100644 index 0000000..1d5c163 --- /dev/null +++ b/Skalkin/src/test/java/context/FirefoxContext.java @@ -0,0 +1,24 @@ +package context; + +import org.openqa.selenium.firefox.FirefoxDriver; + +public class FirefoxContext extends Context { + private final static String WINDOWS_DRIVER = "geckodriver.exe"; + private final static String LINUX_DRIVER = "geckodriver"; + private final static String DRIVER_TYPE = "webdriver.gecko.driver"; + + @Override + protected void createDriver() { + driver = new FirefoxDriver(); + } + + @Override + protected String getDriverExecutable(boolean isWindows) { + return isWindows ? WINDOWS_DRIVER : LINUX_DRIVER; + } + + @Override + protected String getDriverType() { + return DRIVER_TYPE; + } +} diff --git a/Skalkin/src/test/java/page/SearchPage.java b/Skalkin/src/test/java/page/SearchPage.java new file mode 100644 index 0000000..87f5b38 --- /dev/null +++ b/Skalkin/src/test/java/page/SearchPage.java @@ -0,0 +1,38 @@ +package page; + +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; + +public class SearchPage { + WebDriver driver; + + @FindBy(css = "input.header-search-input") + private WebElement inputField; + + @FindBy(xpath = "//*[@class='menu border']/a[7]") + 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(); + } +}