From 964ead17516931e931907e94ed1327cb25ef35bd Mon Sep 17 00:00:00 2001 From: Lisyra <33213966+Lisyra@users.noreply.github.com> Date: Fri, 28 Sep 2018 20:26:04 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B2=D1=81=D0=B5=2020=20=D1=82=D0=B5=D1=81?= =?UTF-8?q?=D1=82=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kurnaev/src/test/java/AccountTests.java | 212 ++++++++++++++++++ kurnaev/src/test/java/FilterTests.java | 40 ++++ kurnaev/src/test/java/NavigationTests.java | 4 - .../src/test/java/page/AllGiveupsPage.java | 41 ++++ kurnaev/src/test/java/page/GamePage.java | 14 ++ kurnaev/src/test/java/page/MainPage.java | 80 +++++++ kurnaev/src/test/java/page/SearchPage.java | 48 ++++ 7 files changed, 435 insertions(+), 4 deletions(-) create mode 100644 kurnaev/src/test/java/AccountTests.java create mode 100644 kurnaev/src/test/java/page/AllGiveupsPage.java create mode 100644 kurnaev/src/test/java/page/SearchPage.java diff --git a/kurnaev/src/test/java/AccountTests.java b/kurnaev/src/test/java/AccountTests.java new file mode 100644 index 0000000..58a8f30 --- /dev/null +++ b/kurnaev/src/test/java/AccountTests.java @@ -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(); + } +} diff --git a/kurnaev/src/test/java/FilterTests.java b/kurnaev/src/test/java/FilterTests.java index b361e69..2ce8494 100644 --- a/kurnaev/src/test/java/FilterTests.java +++ b/kurnaev/src/test/java/FilterTests.java @@ -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 diff --git a/kurnaev/src/test/java/NavigationTests.java b/kurnaev/src/test/java/NavigationTests.java index 4df0c6d..0a23c05 100644 --- a/kurnaev/src/test/java/NavigationTests.java +++ b/kurnaev/src/test/java/NavigationTests.java @@ -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 diff --git a/kurnaev/src/test/java/page/AllGiveupsPage.java b/kurnaev/src/test/java/page/AllGiveupsPage.java new file mode 100644 index 0000000..6951381 --- /dev/null +++ b/kurnaev/src/test/java/page/AllGiveupsPage.java @@ -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; + } + + } +} diff --git a/kurnaev/src/test/java/page/GamePage.java b/kurnaev/src/test/java/page/GamePage.java index 6fd16b4..d8e878a 100644 --- a/kurnaev/src/test/java/page/GamePage.java +++ b/kurnaev/src/test/java/page/GamePage.java @@ -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; + } + + } } diff --git a/kurnaev/src/test/java/page/MainPage.java b/kurnaev/src/test/java/page/MainPage.java index 60baf3c..54302ac 100644 --- a/kurnaev/src/test/java/page/MainPage.java +++ b/kurnaev/src/test/java/page/MainPage.java @@ -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; + } + + + } + } diff --git a/kurnaev/src/test/java/page/SearchPage.java b/kurnaev/src/test/java/page/SearchPage.java new file mode 100644 index 0000000..de47bbb --- /dev/null +++ b/kurnaev/src/test/java/page/SearchPage.java @@ -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; + } + + } + + + +} \ No newline at end of file