diff --git a/Stroeva/.gitignore b/Stroeva/.gitignore new file mode 100644 index 0000000..3bac491 --- /dev/null +++ b/Stroeva/.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/Stroeva/README.md b/Stroeva/README.md new file mode 100644 index 0000000..635e81b --- /dev/null +++ b/Stroeva/README.md @@ -0,0 +1,2 @@ +Selenium WebDriver example project + diff --git a/Stroeva/pom.xml b/Stroeva/pom.xml new file mode 100644 index 0000000..756ca36 --- /dev/null +++ b/Stroeva/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/Stroeva/src/main/java/ru/ulstu/tis/Main.java b/Stroeva/src/main/java/ru/ulstu/tis/Main.java new file mode 100644 index 0000000..aa6f1d2 --- /dev/null +++ b/Stroeva/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/Stroeva/src/main/resources/drivers/chromedriver b/Stroeva/src/main/resources/drivers/chromedriver new file mode 100644 index 0000000..02ff671 Binary files /dev/null and b/Stroeva/src/main/resources/drivers/chromedriver differ diff --git a/Stroeva/src/main/resources/drivers/chromedriver.exe b/Stroeva/src/main/resources/drivers/chromedriver.exe new file mode 100644 index 0000000..28a4067 Binary files /dev/null and b/Stroeva/src/main/resources/drivers/chromedriver.exe differ diff --git a/Stroeva/src/main/resources/drivers/geckodriver b/Stroeva/src/main/resources/drivers/geckodriver new file mode 100644 index 0000000..ba1da8c Binary files /dev/null and b/Stroeva/src/main/resources/drivers/geckodriver differ diff --git a/Stroeva/src/main/resources/drivers/geckodriver.exe b/Stroeva/src/main/resources/drivers/geckodriver.exe new file mode 100644 index 0000000..6208aa8 Binary files /dev/null and b/Stroeva/src/main/resources/drivers/geckodriver.exe differ diff --git a/Stroeva/src/test/java/NavigationTests.java b/Stroeva/src/test/java/NavigationTests.java new file mode 100644 index 0000000..6d9bbd9 --- /dev/null +++ b/Stroeva/src/test/java/NavigationTests.java @@ -0,0 +1,35 @@ +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.*; + +public class NavigationTests { + private final static String APP_URL = "http://amovies.cc/"; + + private static Context context; + + @BeforeAll + public static void setup() { + context = new ChromeContext(); + context.start(); + context.getDriver().manage().window().setSize(new Dimension(1366, 768)); + } + + @AfterAll + public static void quit() { + //context.close(); + } + + @Test + public void testLogo() { + context.getDriver().get(APP_URL); + MainPage page = PageFactory.initElements(context.getDriver(), MainPage.class); + page.clickLogo(); + Assertions.assertTrue(page.isUserPresent()); + } +} diff --git a/Stroeva/src/test/java/context/ChromeContext.java b/Stroeva/src/test/java/context/ChromeContext.java new file mode 100644 index 0000000..aa8c420 --- /dev/null +++ b/Stroeva/src/test/java/context/ChromeContext.java @@ -0,0 +1,25 @@ +package context; + +import org.openqa.selenium.chrome.ChromeDriver; +import org.openqa.selenium.firefox.FirefoxDriver; + +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/Stroeva/src/test/java/context/Context.java b/Stroeva/src/test/java/context/Context.java new file mode 100644 index 0000000..928d5dd --- /dev/null +++ b/Stroeva/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/Stroeva/src/test/java/context/FirefoxContext.java b/Stroeva/src/test/java/context/FirefoxContext.java new file mode 100644 index 0000000..1d5c163 --- /dev/null +++ b/Stroeva/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/Stroeva/src/test/java/page/MainPage.java b/Stroeva/src/test/java/page/MainPage.java new file mode 100644 index 0000000..9d04b22 --- /dev/null +++ b/Stroeva/src/test/java/page/MainPage.java @@ -0,0 +1,35 @@ +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.interactions.Actions; +import org.openqa.selenium.support.FindBy; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; + +import java.io.Console; +import java.util.concurrent.TimeUnit; + +public class MainPage { + WebDriver driver; + + @FindBy(css = ".logo") + private WebElement logoElement; + + @FindBy(css = ".nav-filter") + private WebElement filterElement; + + public MainPage(WebDriver driver) { + this.driver = driver; + } + + public void clickLogo() { + logoElement.click(); + } + + public boolean isUserPresent() { + return filterElement.isDisplayed(); + } +}