все 20 тестов

This commit is contained in:
Lisyra 2018-09-28 20:26:04 +04:00
parent 375b49eeae
commit 964ead1751
7 changed files with 435 additions and 4 deletions

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

@ -8,8 +8,10 @@ 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
@ -63,6 +65,44 @@ public class FilterTests
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

View File

@ -11,9 +11,6 @@ import context.Context;
import page.MainPage;
public class NavigationTests
{
@ -111,7 +108,6 @@ public class NavigationTests
public static void setup() {
context = new ChromeContext();
context.start();
//context.getDriver().manage().window().setSize(new Dimension(1366, 768));
}
@AfterAll

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

@ -17,6 +17,9 @@ public class GamePage
@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;
@ -30,6 +33,7 @@ public class GamePage
public void clickDownloadTorrentLink() {
downloadTorrentLink.click();
}
public void clickAddToFavoritesGameButton() { addToFavoritesGameButton.click(); }
public static boolean isDownloadPagePresent() {
try {
@ -52,6 +56,16 @@ public class GamePage
}
}
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

@ -36,6 +36,30 @@ public class MainPage {
@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;
}
@ -53,6 +77,14 @@ public class MainPage {
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 {
@ -132,4 +164,52 @@ public class MainPage {
}
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;
}
}
}