From 375b49eeae78fa2cda6ba6909d6aadafe033bdce Mon Sep 17 00:00:00 2001 From: Lisyra <33213966+Lisyra@users.noreply.github.com> Date: Wed, 26 Sep 2018 22:16:47 +0400 Subject: [PATCH] =?UTF-8?q?11=20=D1=82=D0=B5=D1=81=D1=82=D0=BE=D0=B2,=20?= =?UTF-8?q?=D0=BF=D0=BE=D1=81=D0=BC=D0=BE=D1=82=D1=80=D0=B8=D1=82=D0=B5=20?= =?UTF-8?q?=D0=BD=D0=BE=D1=80=D0=BC=D0=B0=D0=BB=D1=8C=D0=BD=D0=BE=20=D1=82?= =?UTF-8?q?=D0=B5=D0=BF=D0=B5=D1=80=D1=8C=20=D0=B2=D1=8B=D0=B3=D0=BB=D1=8F?= =?UTF-8?q?=D0=B4=D0=B8=D1=82=20=D0=BE=D0=B6=D0=B8=D0=B4=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5,=20=D1=82=D0=B0=D0=BA=20=D0=BC=D0=BE=D0=B6=D0=BD=D0=BE?= =?UTF-8?q?=20=D0=BE=D1=81=D1=82=D0=B0=D0=B2=D0=B8=D1=82=D1=8C=3F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kurnaev/src/test/java/DownloadTests.java | 28 ++------ kurnaev/src/test/java/FilterTests.java | 79 ++++++++++++++++++++++ kurnaev/src/test/java/MultimediaTests.java | 46 +++++++++++++ kurnaev/src/test/java/NavigationTests.java | 78 ++++----------------- kurnaev/src/test/java/context/Context.java | 7 ++ kurnaev/src/test/java/page/GamePage.java | 10 +++ kurnaev/src/test/java/page/MainPage.java | 16 +++++ 7 files changed, 175 insertions(+), 89 deletions(-) create mode 100644 kurnaev/src/test/java/FilterTests.java create mode 100644 kurnaev/src/test/java/MultimediaTests.java diff --git a/kurnaev/src/test/java/DownloadTests.java b/kurnaev/src/test/java/DownloadTests.java index 68a7d57..55b9275 100644 --- a/kurnaev/src/test/java/DownloadTests.java +++ b/kurnaev/src/test/java/DownloadTests.java @@ -25,35 +25,15 @@ public class DownloadTests MainPage page = PageFactory.initElements(context.getDriver(), MainPage.class); GamePage page1 = PageFactory.initElements(context.getDriver(), GamePage.class); - try { - TimeUnit.SECONDS.sleep(10); // Same as Thread.sleep(5000); - // The "main" thread will sleep - } catch (InterruptedException e) { - } + context.wait(10); page.clickPreviewLink(); - try { - TimeUnit.SECONDS.sleep(5); // Same as Thread.sleep(5000); - // The "main" thread will sleep - } catch (InterruptedException e) { - } + context.wait(5); page1.clickDownloadLink(); context.switchTab(1); - try { - TimeUnit.SECONDS.sleep(8); // Same as Thread.sleep(5000); - // The "main" thread will sleep - } catch (InterruptedException e) { - } + context.wait(10); page1.clickDownloadTorrentLink(); - - - try { - TimeUnit.SECONDS.sleep(15); // Same as Thread.sleep(5000); - // The "main" thread will sleep - } catch (InterruptedException e) { - } - + context.wait(15); Assertions.assertTrue(GamePage.isDownloadPagePresent()); - context.switchTab(0); diff --git a/kurnaev/src/test/java/FilterTests.java b/kurnaev/src/test/java/FilterTests.java new file mode 100644 index 0000000..b361e69 --- /dev/null +++ b/kurnaev/src/test/java/FilterTests.java @@ -0,0 +1,79 @@ +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 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()); + + + } + + @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/MultimediaTests.java b/kurnaev/src/test/java/MultimediaTests.java new file mode 100644 index 0000000..1aa494c --- /dev/null +++ b/kurnaev/src/test/java/MultimediaTests.java @@ -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(); + } +} diff --git a/kurnaev/src/test/java/NavigationTests.java b/kurnaev/src/test/java/NavigationTests.java index 12c05d9..4df0c6d 100644 --- a/kurnaev/src/test/java/NavigationTests.java +++ b/kurnaev/src/test/java/NavigationTests.java @@ -28,17 +28,9 @@ public class NavigationTests Context.getDriver().get(APP_URL); MainPage page = PageFactory.initElements(context.getDriver(), MainPage.class); - try { - TimeUnit.SECONDS.sleep(10); // Same as Thread.sleep(5000); - // The "main" thread will sleep - } catch (InterruptedException e) { - } + context.wait(10); page.clickRulesLink(); - try { - TimeUnit.SECONDS.sleep(5); // Same as Thread.sleep(5000); - // The "main" thread will sleep - } catch (InterruptedException e) { - } + context.wait(5); Assertions.assertTrue(MainPage.isRulesPresent()); @@ -50,17 +42,9 @@ public class NavigationTests Context.getDriver().get(APP_URL); MainPage page = PageFactory.initElements(context.getDriver(), MainPage.class); - try { - TimeUnit.SECONDS.sleep(10); // Same as Thread.sleep(5000); - // The "main" thread will sleep - } catch (InterruptedException e) { - } + context.wait(10); page.clickPreviewLink(); - try { - TimeUnit.SECONDS.sleep(5); // Same as Thread.sleep(5000); - // The "main" thread will sleep - } catch (InterruptedException e) { - } + context.wait(5); Assertions.assertTrue(MainPage.isPreviewPresent()); @@ -72,17 +56,9 @@ public class NavigationTests Context.getDriver().get(APP_URL); MainPage page = PageFactory.initElements(context.getDriver(), MainPage.class); - try { - TimeUnit.SECONDS.sleep(10); // Same as Thread.sleep(5000); - // The "main" thread will sleep - } catch (InterruptedException e) { - } + context.wait(10); page.clickpopularGiveup(); - try { - TimeUnit.SECONDS.sleep(5); // Same as Thread.sleep(5000); - // The "main" thread will sleep - } catch (InterruptedException e) { - } + context.wait(5); Assertions.assertTrue(MainPage.isPopularGiveupPresent()); @@ -94,17 +70,9 @@ public class NavigationTests Context.getDriver().get(APP_URL); MainPage page = PageFactory.initElements(context.getDriver(), MainPage.class); - try { - TimeUnit.SECONDS.sleep(10); // Same as Thread.sleep(5000); - // The "main" thread will sleep - } catch (InterruptedException e) { - } + context.wait(10); page.clickexternalLink(); - try { - TimeUnit.SECONDS.sleep(5); // Same as Thread.sleep(5000); - // The "main" thread will sleep - } catch (InterruptedException e) { - } + context.wait(5); Assertions.assertTrue(MainPage.isExternalLinkPresent()); @@ -116,17 +84,9 @@ public class NavigationTests Context.getDriver().get(APP_URL); MainPage page = PageFactory.initElements(context.getDriver(), MainPage.class); - try { - TimeUnit.SECONDS.sleep(10); // Same as Thread.sleep(5000); - // The "main" thread will sleep - } catch (InterruptedException e) { - } + context.wait(10); page.clicklastMessageLink(); - try { - TimeUnit.SECONDS.sleep(5); // Same as Thread.sleep(5000); - // The "main" thread will sleep - } catch (InterruptedException e) { - } + context.wait(5); Assertions.assertTrue(MainPage.islastMessageLinkPresent()); @@ -138,23 +98,11 @@ public class NavigationTests Context.getDriver().get(APP_URL); MainPage page = PageFactory.initElements(context.getDriver(), MainPage.class); - try { - TimeUnit.SECONDS.sleep(10); // Same as Thread.sleep(5000); - // The "main" thread will sleep - } catch (InterruptedException e) { - } + context.wait(10); page.clickSideMenuLink(); - try { - TimeUnit.SECONDS.sleep(5); // Same as Thread.sleep(5000); - // The "main" thread will sleep - } catch (InterruptedException e) { - } + context.wait(5); page.clickSideMenuSubLink(); - try { - TimeUnit.SECONDS.sleep(5); // Same as Thread.sleep(5000); - // The "main" thread will sleep - } catch (InterruptedException e) { - } + context.wait(5); Assertions.assertTrue(MainPage.isSideMenuLinkPresent()); diff --git a/kurnaev/src/test/java/context/Context.java b/kurnaev/src/test/java/context/Context.java index 13ebb4e..be00d1a 100644 --- a/kurnaev/src/test/java/context/Context.java +++ b/kurnaev/src/test/java/context/Context.java @@ -34,6 +34,13 @@ public abstract class Context { 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(driver.getWindowHandles()).get(tabNum).toString()); } protected abstract void createDriver(); diff --git a/kurnaev/src/test/java/page/GamePage.java b/kurnaev/src/test/java/page/GamePage.java index 6bd30dd..6fd16b4 100644 --- a/kurnaev/src/test/java/page/GamePage.java +++ b/kurnaev/src/test/java/page/GamePage.java @@ -42,6 +42,16 @@ public class GamePage } } + 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("= 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 12d6c4a..60baf3c 100644 --- a/kurnaev/src/test/java/page/MainPage.java +++ b/kurnaev/src/test/java/page/MainPage.java @@ -33,6 +33,9 @@ public class MainPage { @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; + public MainPage(WebDriver driver) { this.driver = driver; } @@ -49,6 +52,7 @@ public class MainPage { 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 static boolean isRulesPresent() { try { @@ -116,4 +120,16 @@ public class MainPage { } } + 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; + } + + } + }