Compare commits

...

7 Commits

19 changed files with 1240 additions and 0 deletions

156
kurnaev/.gitignore vendored Normal file
View 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
kurnaev/README.md Normal file
View File

@ -0,0 +1,2 @@
Selenium WebDriver example project

49
kurnaev/pom.xml Normal file
View 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>

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,212 @@
import org.openqa.selenium.support.PageFactory;
import java.util.concurrent.TimeUnit;
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 context.ChromeContext;
import context.Context;
import page.MainPage;
import page.GamePage;
public class AccountTests
{
private final static String APP_URL = "http://gmt-max.net/";
private static Context context;
@Test
public void logIn()
{
Context.getDriver().get(APP_URL);
MainPage page = PageFactory.initElements(context.getDriver(), MainPage.class);
context.wait(10);
if(MainPage.isLoggedIn())
{
page.clickLogOutButton();
context.wait(5);
}
page.clickLoginButton();
context.wait(5);
page.enterTextToLoginField("g35hfsd");
page.enterTextToPasswordField("hfgn53fgb");
context.wait(3);
page.clickloginConfirmButton();
context.wait(5);
Assertions.assertTrue(MainPage.isLoggedIn());
}
@Test
public void logOut()
{
Context.getDriver().get(APP_URL);
MainPage page = PageFactory.initElements(context.getDriver(), MainPage.class);
context.wait(10);
if(!MainPage.isLoggedIn())
{
page.clickLoginButton();
context.wait(5);
page.enterTextToLoginField("g35hfsd");
page.enterTextToPasswordField("hfgn53fgb");
context.wait(3);
page.clickloginConfirmButton();
context.wait(5);
}
page.clickLogOutButton();
context.wait(5);
Assertions.assertTrue(MainPage.isLoggedOut());
}
@Test
public void registration()
{
Context.getDriver().get(APP_URL);
MainPage page = PageFactory.initElements(context.getDriver(), MainPage.class);
context.wait(10);
if(MainPage.isLoggedIn())
{
page.clickLogOutButton();
context.wait(5);
}
page.clickRegistrationButton();
context.wait(5);
Assertions.assertTrue(MainPage.isRegistrationPagePresent());
}
@Test
public void logInWithOnlyPassword()
{
Context.getDriver().get(APP_URL);
MainPage page = PageFactory.initElements(context.getDriver(), MainPage.class);
context.wait(10);
if(MainPage.isLoggedIn())
{
page.clickLogOutButton();
context.wait(5);
}
page.clickLoginButton();
context.wait(5);
page.enterTextToPasswordField("hfgn53fgb");
context.wait(3);
page.clickloginConfirmButton();
context.wait(5);
Assertions.assertTrue(MainPage.isNotLoggedIn());
}
@Test
public void logInWithOnlyName()
{
Context.getDriver().get(APP_URL);
MainPage page = PageFactory.initElements(context.getDriver(), MainPage.class);
context.wait(10);
if(MainPage.isLoggedIn())
{
page.clickLogOutButton();
context.wait(5);
}
page.clickLoginButton();
context.wait(5);
page.enterTextToLoginField("g35hfsd");
context.wait(3);
page.clickloginConfirmButton();
context.wait(5);
Assertions.assertTrue(MainPage.isNotLoggedIn());
}
@Test
public void logInWithLongNameAndCorrectPassword()
{
Context.getDriver().get(APP_URL);
MainPage page = PageFactory.initElements(context.getDriver(), MainPage.class);
context.wait(10);
if(MainPage.isLoggedIn())
{
page.clickLogOutButton();
context.wait(5);
}
page.clickLoginButton();
context.wait(5);
page.enterTextToLoginField("g35hfsdg54ytgh657435635gdhhhhe546yghf");
page.enterTextToPasswordField("hfgn53fgb");
context.wait(3);
page.clickloginConfirmButton();
context.wait(5);
Assertions.assertTrue(MainPage.isNotLoggedIn());
}
@Test
public void addToFavorites()
{
Context.getDriver().get(APP_URL);
MainPage page = PageFactory.initElements(context.getDriver(), MainPage.class);
GamePage page1 = PageFactory.initElements(context.getDriver(), GamePage.class);
context.wait(10);
if(!MainPage.isLoggedIn())
{
page.clickLoginButton();
context.wait(5);
page.enterTextToLoginField("g35hfsd");
page.enterTextToPasswordField("hfgn53fgb");
context.wait(3);
page.clickloginConfirmButton();
context.wait(5);
}
page.clickPreviewLink();
context.wait(5);
if(GamePage.isAddedToFavorites())
{
page1.clickAddToFavoritesGameButton();
context.wait(3);
}
page1.clickAddToFavoritesGameButton();
context.wait(5);
Assertions.assertTrue(GamePage.isAddedToFavorites());
}
@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();
}
}

View File

@ -0,0 +1,53 @@
import org.openqa.selenium.support.PageFactory;
import java.util.concurrent.TimeUnit;
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 context.ChromeContext;
import context.Context;
import page.MainPage;
import page.GamePage;
public class DownloadTests
{
private final static String APP_URL = "http://gmt-max.net/";
private static Context context;
@Test
public void downloadTorrent()
{
Context.getDriver().get(APP_URL);
MainPage page = PageFactory.initElements(context.getDriver(), MainPage.class);
GamePage page1 = PageFactory.initElements(context.getDriver(), GamePage.class);
context.wait(10);
page.clickPreviewLink();
context.wait(5);
page1.clickDownloadLink();
context.switchTab(1);
context.wait(10);
page1.clickDownloadTorrentLink();
context.wait(15);
Assertions.assertTrue(GamePage.isDownloadPagePresent());
context.switchTab(0);
}
@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();
}
}

View File

@ -0,0 +1,119 @@
import org.openqa.selenium.support.PageFactory;
import java.util.concurrent.TimeUnit;
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 context.ChromeContext;
import context.Context;
import page.AllGiveupsPage;
import page.MainPage;
import page.GamePage;
import page.SearchPage;
public class FilterTests
{
private final static String APP_URL = "http://gmt-max.net/";
private static Context context;
@Test
public void searchWordOnSite()
{
Context.getDriver().get(APP_URL);
MainPage page = PageFactory.initElements(context.getDriver(), MainPage.class);
context.wait(10);
page.search("Skyrim");
context.wait(5);
Assertions.assertTrue(MainPage.isSearchResultsPresent());
}
@Test
public void searchNothingOnSite()
{
Context.getDriver().get(APP_URL);
MainPage page = PageFactory.initElements(context.getDriver(), MainPage.class);
context.wait(10);
page.search("");
context.wait(5);
Assertions.assertTrue(MainPage.isSearchResultsPresent());
}
@Test
public void sortByMMORPGLink()
{
Context.getDriver().get(APP_URL);
MainPage page = PageFactory.initElements(context.getDriver(), MainPage.class);
context.wait(10);
page.clickSideMenuLink();
context.wait(5);
page.clickSideMenuSubLink();
context.wait(5);
Assertions.assertTrue(MainPage.isSideMenuLinkPresent());
}
@Test
public void advancedFilterByUser()
{
Context.getDriver().get(APP_URL);
MainPage page = PageFactory.initElements(context.getDriver(), MainPage.class);
SearchPage page1 = PageFactory.initElements(context.getDriver(), SearchPage.class);
context.wait(10);
page.search("Skyrim");
context.wait(5);
page1.clickMoreSearchLink();
context.wait(5);
page1.searchByUser("Max");
context.wait(5);
Assertions.assertTrue(SearchPage.isAdvancedSearchByUserCorrect());
}
@Test
public void allGiveupsFilter()
{
Context.getDriver().get(APP_URL);
MainPage page = PageFactory.initElements(context.getDriver(), MainPage.class);
AllGiveupsPage page1 = PageFactory.initElements(context.getDriver(), AllGiveupsPage.class);
context.wait(10);
page.clickAllGiveupsLink();
context.wait(5);
page1.changeStatusDropdownMenuToDied();
context.wait(5);
Assertions.assertTrue(AllGiveupsPage.isChangedStatusCorrectly());
}
@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();
}
}

View File

@ -0,0 +1,46 @@
import org.openqa.selenium.support.PageFactory;
import java.util.concurrent.TimeUnit;
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 context.ChromeContext;
import context.Context;
import page.MainPage;
import page.GamePage;
public class MultimediaTests
{
private final static String APP_URL = "http://gmt-max.net/";
private static Context context;
@Test
public void checkPictures()
{
Context.getDriver().get(APP_URL);
MainPage page = PageFactory.initElements(context.getDriver(), MainPage.class);
GamePage page1 = PageFactory.initElements(context.getDriver(), GamePage.class);
context.wait(10);
page.clickPreviewLink();
context.wait(5);
Assertions.assertTrue(GamePage.isPicturePresent());
}
@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();
}
}

View File

@ -0,0 +1,119 @@
import org.openqa.selenium.support.PageFactory;
import java.util.concurrent.TimeUnit;
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 context.ChromeContext;
import context.Context;
import page.MainPage;
public class NavigationTests
{
private final static String APP_URL = "http://gmt-max.net/";
private static Context context;
@Test
public void rulesLink()
{
Context.getDriver().get(APP_URL);
MainPage page = PageFactory.initElements(context.getDriver(), MainPage.class);
context.wait(10);
page.clickRulesLink();
context.wait(5);
Assertions.assertTrue(MainPage.isRulesPresent());
}
@Test
public void previewLink()
{
Context.getDriver().get(APP_URL);
MainPage page = PageFactory.initElements(context.getDriver(), MainPage.class);
context.wait(10);
page.clickPreviewLink();
context.wait(5);
Assertions.assertTrue(MainPage.isPreviewPresent());
}
@Test
public void popularGiveup()
{
Context.getDriver().get(APP_URL);
MainPage page = PageFactory.initElements(context.getDriver(), MainPage.class);
context.wait(10);
page.clickpopularGiveup();
context.wait(5);
Assertions.assertTrue(MainPage.isPopularGiveupPresent());
}
@Test
public void externalLinks()
{
Context.getDriver().get(APP_URL);
MainPage page = PageFactory.initElements(context.getDriver(), MainPage.class);
context.wait(10);
page.clickexternalLink();
context.wait(5);
Assertions.assertTrue(MainPage.isExternalLinkPresent());
}
@Test
public void lastMessageLink()
{
Context.getDriver().get(APP_URL);
MainPage page = PageFactory.initElements(context.getDriver(), MainPage.class);
context.wait(10);
page.clicklastMessageLink();
context.wait(5);
Assertions.assertTrue(MainPage.islastMessageLinkPresent());
}
@Test
public void sideMenuLink()
{
Context.getDriver().get(APP_URL);
MainPage page = PageFactory.initElements(context.getDriver(), MainPage.class);
context.wait(10);
page.clickSideMenuLink();
context.wait(5);
page.clickSideMenuSubLink();
context.wait(5);
Assertions.assertTrue(MainPage.isSideMenuLinkPresent());
}
@BeforeAll
public static void setup() {
context = new ChromeContext();
context.start();
}
@AfterAll
public static void quit() {
context.close();
}
}

View File

@ -0,0 +1,25 @@
package context;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
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;
}
}

View File

@ -0,0 +1,60 @@
package context;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import java.util.ArrayList;
import java.util.concurrent.TimeUnit;
//import java.nio.file.*;
//import java.io.File;
public abstract class Context {
private final static String DRIVER_LOCATION = "drivers/%s";
protected static WebDriver driver;
public static WebDriver getDriver() {
if (driver != null) {
return driver;
}
throw new IllegalStateException("WebDriver is not initialized");
}
public void start() {
System.setProperty(getDriverType(), getDriverExecutablePath());
//driver = new ChromeDriver();
createDriver();
driver.manage().window().maximize();
// это плохая инструкция для автотестов, т.к. лучше задавать для конкретного элемента или кейса
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
}
public void close() {
driver.quit();
}
public void wait(int sec) {
try {
TimeUnit.SECONDS.sleep(sec);
} catch (InterruptedException e) {
}
}
public void switchTab(int tabNum) { driver.switchTo().window(new ArrayList<String>(driver.getWindowHandles()).get(tabNum).toString()); }
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");
}
}

View 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;
}
}

View File

@ -0,0 +1,41 @@
package page;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.By;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.Select;
public class AllGiveupsPage
{
static WebDriver driver;
@FindBy(name = "status")
private WebElement statusDropdownMenu;
public AllGiveupsPage(WebDriver driver) {
this.driver = driver;
}
public void changeStatusDropdownMenuToDied() {
new Select(statusDropdownMenu).selectByIndex(4);
}
public static boolean isChangedStatusCorrectly() {
try {
return driver.findElement(By.name("status")).getText().indexOf("Мёртвые") >= 0;
}
catch (Exception e)
{
return false;
}
}
}

View File

@ -0,0 +1,71 @@
package page;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.By;
import org.openqa.selenium.interactions.Actions;
public class GamePage
{
static WebDriver driver;
@FindBy(xpath = "//a[starts-with(@href,'/go.php?url=https://downloads-torrent.ru')]")
private WebElement downloadLink;
@FindBy(xpath = "//html/body[@class='rectangles']/main[@class='fill']/section[@class='section section--fill']/div[@class='container no-index']/div[@class='block block-download']/a[@id='btn--download']")
private WebElement downloadTorrentLink;
@FindBy(xpath = "//html/body/div[@class='content_main']/div[@class='main_center_col blocks']/div[@id='dle-content']/div[@class='full_news_title']/div[@class='edit_news_block']/a[@id='fav-id-12362']")
private WebElement addToFavoritesGameButton;
public GamePage(WebDriver driver) {
this.driver = driver;
}
public void clickDownloadLink() {
downloadLink.click();
}
public void clickDownloadTorrentLink() {
downloadTorrentLink.click();
}
public void clickAddToFavoritesGameButton() { addToFavoritesGameButton.click(); }
public static boolean isDownloadPagePresent() {
try {
return driver.findElement(By.xpath("//html/body")).getText().indexOf("СКАЧАТЬ ТОРРЕНТ") >= 0;
}
catch (Exception e)
{
return false;
}
}
public static boolean isPicturePresent() {
try {
return driver.findElement(By.xpath("//html/body/div[@class='content_main']/div[@class='main_center_col blocks']")).getAttribute("innerHTML").indexOf("<img src=\"http://paypic.kz/allimage/") >= 0;
}
catch (Exception e)
{
return false;
}
}
public static boolean isAddedToFavorites() {
try {
return driver.findElement(By.xpath("//html/body/div[@class='content_main']/div[@class='main_center_col blocks']/div[@id='dle-content']/div[@class='full_news_title']/div[@class='edit_news_block']")).getAttribute("innerHTML").indexOf("minus_fav.gif") >= 0;
}
catch (Exception e)
{
return false;
}
}
}

View File

@ -0,0 +1,215 @@
package page;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.By;
import org.openqa.selenium.interactions.Actions;
public class MainPage {
static WebDriver driver;
@FindBy(xpath = "//html/body/div[@class='main_head']/div[@id='overview']/div[@class='subnav']/div[@class='content']/ul[@class='navigation']/li[4]/a")
private WebElement rulesLink;
@FindBy(xpath = "//html/body/div[@class='content_main']/div[@class='main_center_col blocks']/div[@id='dle-content']/div[@class='short_news_title'][1]/div[@class='short_news_title_center']/a")
private WebElement previewLinkContainer;
@FindBy(xpath = "//html/body/div[@class='content_main']/div[@class='main_right_col blocks']/a[@class='popular_torrents'][2]")
private WebElement popularGiveup;
@FindBy(xpath = "//a[@href='/forum/']")
private WebElement externalLink;
@FindBy(xpath = "//html/body/div[@class='content'][1]/div[@class='forum_block']/div[@class='forum_msg_block']/div[@class='ltContent']/table/tbody/tr[7]/td[@class='topicInfo']/a[@class='topicLink']")
private WebElement lastMessageLink;
@FindBy(xpath = "//html/body/div[@class='content_main']/div[@class='main_left_col blocks']/div[@id='firstpane'][2]/p[@class='menu_head1'][3]")
private WebElement sideMenuLink;
@FindBy(xpath = "//html/body/div[@class='content_main']/div[@class='main_left_col blocks']/div[@id='firstpane'][2]/div[@class='menu_body'][3]/a[2]")
private WebElement sideMenuSubLink;
@FindBy(id = "story")
private WebElement searchField;
@FindBy(xpath = "//html/body/div[@class='main_head']/div[@id='overview']/div[@class='subnav']/div[@class='content']/ul[@class='navigation']/li[5]/a")
private WebElement allGiveupsLink;
@FindBy(xpath = "//html/body/div[@class='main_head']/div[@class='content']/div[@class='login_block']/span/a[@id='loginlinkreg']")
private WebElement loginButton;
@FindBy(id = "login_name")
private WebElement loginNameField;
@FindBy(id = "login_password")
private WebElement loginPasswordField;
@FindBy(xpath = "//html/body/div[@class='ui-dialog ui-widget ui-widget-content ui-corner-all ui-draggable']/div[@id='logindialogreg']/center/form/button[@class='fbutton']")
private WebElement loginConfirmButton;
@FindBy(xpath = "//html/body/div[@class='main_head']/div[@class='content']/div[@class='login_block']/a")
private WebElement logOutButton;
@FindBy(xpath = "//html/body/div[@class='main_head']/div[@class='content']/div[@class='login_block']/span/a[2]")
private WebElement registrationButton;
public MainPage(WebDriver driver) {
this.driver = driver;
}
public void clickRulesLink() {
rulesLink.click();
}
public void clickPreviewLink() { previewLinkContainer.click(); }
public void clickpopularGiveup() { popularGiveup.click(); }
public void clickexternalLink() { externalLink.click(); }
public void clicklastMessageLink() { lastMessageLink.click(); }
public void clickSideMenuLink() { sideMenuLink.click(); }
public void clickSideMenuSubLink() { sideMenuSubLink.click(); }
public void search(String word) {searchField.sendKeys(word + "\n");}
public void clickAllGiveupsLink() { allGiveupsLink.click(); }
public void clickLoginButton() { loginButton.click(); }
public void enterTextToLoginField(String name) { loginNameField.sendKeys(name); }
public void enterTextToPasswordField(String pass) { loginPasswordField.sendKeys(pass); }
public void clickloginConfirmButton() { loginConfirmButton.click(); }
public void clickLogOutButton() { logOutButton.click(); }
public void clickRegistrationButton() { registrationButton.click(); }
public static boolean isRulesPresent() {
try {
return driver.findElement(By.xpath("//html/body")).getText().indexOf("ОСНОВНЫЕ ПРАВИЛА ТРЕКЕРА И ФОРУМА - GMT-MAX.NET")>=0;
}
catch (Exception e)
{
return false;
}
}
public static boolean isPreviewPresent() {
try {
return driver.findElement(By.xpath("//html/body/div[@class='content_main']/div[@class='main_center_col blocks']/div[@id='dle-content']/div[@class='full_news_content']")).getText().indexOf("Год выпуска:")>=0;
}
catch (Exception e)
{
return false;
}
}
public static boolean isPopularGiveupPresent() {
try {
return driver.findElement(By.xpath("//html/body/div[@class='content_main']/div[@class='main_right_col blocks']")).getText().indexOf(driver.findElement(By.xpath("//html/body/div[@class='content_main']/div[@class='main_center_col blocks']/div[@id='dle-content']/div[@class='full_news_title']/div[@class='full_news_title_center']/h1")).getText()) >= 0;
}
catch (Exception e)
{
return false;
}
}
public static boolean isExternalLinkPresent() {
try {
return driver.findElement(By.xpath("//html/body")).getText().indexOf("Форум") >= 0;
}
catch (Exception e)
{
return false;
}
}
public static boolean islastMessageLinkPresent() {
try {
return driver.findElement(By.xpath("//html/body")).getText().indexOf("СООБЩЕНИЙ В ТЕМЕ") >= 0;
}
catch (Exception e)
{
return false;
}
}
public static boolean isSideMenuLinkPresent() {
try {
return driver.findElement(By.xpath("//html/body/div[@class='content_main']/div[@class='main_content_nav']")).getText().indexOf("Rpg") >= 0;
}
catch (Exception e)
{
return false;
}
}
public static boolean isSearchResultsPresent() {
try {
return driver.findElement(By.xpath("//html/body/div[@class='content_main']/div[@class='main_center_col blocks']/div[@id='dle-content']/div[@class='dpad radial infoblock']")).getAttribute("innerHTML").indexOf("value=\"Начать поиск\"") >= 0;
}
catch (Exception e)
{
return false;
}
}
public static boolean isLoggedIn() {
try {
return driver.findElement(By.xpath("//html/body/div[@class='main_head']/div[@class='content']/div[@class='login_block']/span")).getText().indexOf("Привет") >= 0;
}
catch (Exception e)
{
return false;
}
}
public static boolean isLoggedOut() {
try {
return driver.findElement(By.xpath("//html/body/div[@class='main_head']/div[@class='content']/div[@class='login_block']/span")).getText().indexOf("Вход") >= 0;
}
catch (Exception e)
{
return false;
}
}
public static boolean isRegistrationPagePresent() {
try {
return driver.findElement(By.xpath("//html/body")).getText().indexOf("ОСНОВНЫЕ ПРАВИЛА ТРЕКЕРА И ФОРУМА - GMT-MAX.NET") >= 0 || driver.findElement(By.xpath("//html/body")).getText().indexOf("Регистрация нового пользователя") >= 0;
}
catch (Exception e)
{
return false;
}
}
public static boolean isNotLoggedIn() {
try {
return driver.findElement(By.xpath("//html/body/div[@class='content_main']/div[@class='main_center_col blocks']/div[@class='info_block']")).getText().indexOf("Ошибка авторизации") >= 0;
}
catch (Exception e)
{
return false;
}
}
}

View File

@ -0,0 +1,48 @@
package page;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.By;
import org.openqa.selenium.interactions.Actions;
public class SearchPage
{
static WebDriver driver;
@FindBy(xpath = "//html/body/div[@class='content_main']/div[@class='main_center_col blocks']/div[@id='dle-content']/div[@class='dpad radial infoblock']/div[@id='searchtable']/form[@id='fullsearch']/table/tbody/tr/td[@class='search']/div/input[@id='dofullsearch']")
private WebElement moreSearchLink;
@FindBy(id = "searchuser")
private WebElement userSearchField;
public SearchPage(WebDriver driver) {
this.driver = driver;
}
public void clickMoreSearchLink() {
moreSearchLink.click();
}
public void searchByUser(String user) {
userSearchField.sendKeys(user + "\n");
}
public static boolean isAdvancedSearchByUserCorrect() {
try {
return driver.findElement(By.xpath("//html/body/div[@class='content_main']/div[@class='main_center_col blocks']/div[@id='dle-content']/div[@class='dpad radial infoblock']")).getText().indexOf("Имя пользователя:") >= 0;
}
catch (Exception e)
{
return false;
}
}
}