Laba2v1
This commit is contained in:
parent
ad6da28d39
commit
c8b5fa7356
156
Vasin/.gitignore
vendored
Normal file
156
Vasin/.gitignore
vendored
Normal file
@ -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/
|
2
Vasin/README.md
Normal file
2
Vasin/README.md
Normal file
@ -0,0 +1,2 @@
|
||||
Selenium WebDriver example project
|
||||
|
49
Vasin/pom.xml
Normal file
49
Vasin/pom.xml
Normal file
@ -0,0 +1,49 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
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>tis-2017</groupId>
|
||||
<artifactId>tis-2017</artifactId>
|
||||
<version>1.0</version>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
|
||||
<dependency>
|
||||
<groupId>org.seleniumhq.selenium</groupId>
|
||||
<artifactId>selenium-java</artifactId>
|
||||
<version>3.6.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-api</artifactId>
|
||||
<version>5.1.0-RC1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>2.4</version>
|
||||
<configuration>
|
||||
<archive>
|
||||
<index>true</index>
|
||||
<manifest>
|
||||
<addClasspath>true</addClasspath>
|
||||
<classpathPrefix>lib/</classpathPrefix>
|
||||
<mainClass>ru.ulstu.tis.Main</mainClass>
|
||||
</manifest>
|
||||
<manifestEntries>
|
||||
<Class-Path>lib/</Class-Path>
|
||||
</manifestEntries>
|
||||
</archive>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
7
Vasin/src/main/java/ru/ulstu/tis/Main.java
Normal file
7
Vasin/src/main/java/ru/ulstu/tis/Main.java
Normal file
@ -0,0 +1,7 @@
|
||||
package ru.ulstu.tis;
|
||||
|
||||
public class Main {
|
||||
|
||||
public static void main(String[] args) {
|
||||
}
|
||||
}
|
BIN
Vasin/src/main/resources/drivers/chromedriver
Normal file
BIN
Vasin/src/main/resources/drivers/chromedriver
Normal file
Binary file not shown.
BIN
Vasin/src/main/resources/drivers/chromedriver.exe
Normal file
BIN
Vasin/src/main/resources/drivers/chromedriver.exe
Normal file
Binary file not shown.
BIN
Vasin/src/main/resources/drivers/geckodriver
Normal file
BIN
Vasin/src/main/resources/drivers/geckodriver
Normal file
Binary file not shown.
BIN
Vasin/src/main/resources/drivers/geckodriver.exe
Normal file
BIN
Vasin/src/main/resources/drivers/geckodriver.exe
Normal file
Binary file not shown.
39
Vasin/src/test/java/Filters.java
Normal file
39
Vasin/src/test/java/Filters.java
Normal file
@ -0,0 +1,39 @@
|
||||
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 Filters {
|
||||
private final static String APP_URL_MVideo = "https://www.mvideo.ru/";
|
||||
|
||||
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 testSearch() {
|
||||
context.getDriver().get(APP_URL_MVideo);
|
||||
String searchString = "телевизор samsung";
|
||||
|
||||
SearchPage page = PageFactory.initElements(context.getDriver(), SearchPage.class);
|
||||
page.setSearchString(searchString);
|
||||
page.clickSubmitButton();
|
||||
page.clickLogo();
|
||||
}
|
||||
}
|
41
Vasin/src/test/java/GithubUserSearch.java
Normal file
41
Vasin/src/test/java/GithubUserSearch.java
Normal file
@ -0,0 +1,41 @@
|
||||
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());
|
||||
}
|
||||
}
|
82
Vasin/src/test/java/NavigationTest.java
Normal file
82
Vasin/src/test/java/NavigationTest.java
Normal file
@ -0,0 +1,82 @@
|
||||
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 NavigationTest {
|
||||
private final static String APP_URL_MVideo = "https://www.mvideo.ru/";
|
||||
|
||||
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 testLogo() {
|
||||
context.getDriver().get(APP_URL_MVideo);
|
||||
SearchPage page = PageFactory.initElements(context.getDriver(), SearchPage.class);
|
||||
|
||||
page.clickLogo();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNavigationMainMenu() {
|
||||
context.getDriver().get(APP_URL_MVideo);
|
||||
SearchPage page = PageFactory.initElements(context.getDriver(), SearchPage.class);
|
||||
|
||||
page.clickMainMenu();
|
||||
page.clickLogo();
|
||||
}
|
||||
|
||||
//not visible
|
||||
@Test
|
||||
public void testNavigationSubMenu() {
|
||||
context.getDriver().get(APP_URL_MVideo);
|
||||
SearchPage page = PageFactory.initElements(context.getDriver(), SearchPage.class);
|
||||
|
||||
page.clickSubMenu();
|
||||
page.clickLogo();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNavigationFooterMenu() {
|
||||
context.getDriver().get(APP_URL_MVideo);
|
||||
SearchPage page = PageFactory.initElements(context.getDriver(), SearchPage.class);
|
||||
|
||||
page.clickFooterMenu();
|
||||
page.clickLogo();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNavigationReadMore() {
|
||||
context.getDriver().get(APP_URL_MVideo);
|
||||
SearchPage page = PageFactory.initElements(context.getDriver(), SearchPage.class);
|
||||
|
||||
page.clickReadMore();
|
||||
page.clickLogo();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNavigationSocialLink() {
|
||||
context.getDriver().get(APP_URL_MVideo);
|
||||
SearchPage page = PageFactory.initElements(context.getDriver(), SearchPage.class);
|
||||
|
||||
page.clickSocialLink();
|
||||
page.clickLogo();
|
||||
}
|
||||
}
|
24
Vasin/src/test/java/context/ChromeContext.java
Normal file
24
Vasin/src/test/java/context/ChromeContext.java
Normal file
@ -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;
|
||||
}
|
||||
}
|
43
Vasin/src/test/java/context/Context.java
Normal file
43
Vasin/src/test/java/context/Context.java
Normal file
@ -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");
|
||||
}
|
||||
}
|
24
Vasin/src/test/java/context/FirefoxContext.java
Normal file
24
Vasin/src/test/java/context/FirefoxContext.java
Normal file
@ -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;
|
||||
}
|
||||
}
|
97
Vasin/src/test/java/page/SearchPage.java
Normal file
97
Vasin/src/test/java/page/SearchPage.java
Normal file
@ -0,0 +1,97 @@
|
||||
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 java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class SearchPage {
|
||||
WebDriver driver;
|
||||
|
||||
@FindBy(css = ".header-search-input")
|
||||
private WebElement inputField;
|
||||
|
||||
@FindBy(xpath = "//*[@class='menu border']/a[7]")
|
||||
private WebElement usersLink;
|
||||
|
||||
@FindBy(css = ".header-nav-item-link")
|
||||
private WebElement mainMenu;
|
||||
|
||||
@FindBy(css = ".header-nav-drop-down-list-item-link")
|
||||
private WebElement subMenu;
|
||||
|
||||
@FindBy(css = ".footer-nav-link")
|
||||
private WebElement footerMenu;
|
||||
|
||||
@FindBy(css = ".header-logo")
|
||||
private WebElement mVideoLogo;
|
||||
|
||||
@FindBy(css = ".shop-service-item")
|
||||
private WebElement readMore;
|
||||
|
||||
@FindBy(css = ".socials-link")
|
||||
private WebElement socialLink;
|
||||
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
public void clickMainMenu() {
|
||||
mainMenu.sendKeys(Keys.RETURN);
|
||||
}
|
||||
|
||||
public void clickSubMenu() {
|
||||
Actions builder = new Actions(driver);
|
||||
builder.moveToElement(mainMenu).perform();
|
||||
try {
|
||||
Thread.sleep(20000L);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
subMenu.sendKeys(Keys.RETURN);
|
||||
}
|
||||
|
||||
public void clickFooterMenu() {
|
||||
footerMenu.sendKeys(Keys.RETURN);
|
||||
}
|
||||
|
||||
public void clickLogo() {
|
||||
mVideoLogo.sendKeys(Keys.RETURN);
|
||||
}
|
||||
|
||||
public void clickReadMore() {
|
||||
readMore.sendKeys(Keys.RETURN);
|
||||
}
|
||||
|
||||
public void clickSocialLink() {
|
||||
String base = driver.getWindowHandle();
|
||||
|
||||
socialLink.sendKeys(Keys.RETURN);
|
||||
|
||||
//driver.close();
|
||||
driver.switchTo().window(base);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user