diff --git a/kurnaev/src/test/java/NavigationTests.java b/kurnaev/src/test/java/NavigationTests.java index 76614a5..ea8a0cb 100644 --- a/kurnaev/src/test/java/NavigationTests.java +++ b/kurnaev/src/test/java/NavigationTests.java @@ -28,6 +28,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) { + } page.clickRulesLink(); try { TimeUnit.SECONDS.sleep(5); // Same as Thread.sleep(5000); @@ -45,6 +50,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) { + } page.clickPreviewLink(); try { TimeUnit.SECONDS.sleep(5); // Same as Thread.sleep(5000); @@ -54,6 +64,72 @@ public class NavigationTests Assertions.assertTrue(MainPage.isPreviewPresent()); + } + @Test + public void popularGiveup() + { + + 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) { + } + page.clickpopularGiveup(); + try { + TimeUnit.SECONDS.sleep(5); // Same as Thread.sleep(5000); + // The "main" thread will sleep + } catch (InterruptedException e) { + } + Assertions.assertTrue(MainPage.isPopularGiveupPresent()); + + + } + @Test + public void externalLinks() + { + + 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) { + } + page.clickexternalLink(); + try { + TimeUnit.SECONDS.sleep(5); // Same as Thread.sleep(5000); + // The "main" thread will sleep + } catch (InterruptedException e) { + } + Assertions.assertTrue(MainPage.isExternalLinkPresent()); + + + } + @Test + public void lastMessageLink() + { + + 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) { + } + page.clicklastMessageLink(); + try { + TimeUnit.SECONDS.sleep(5); // Same as Thread.sleep(5000); + // The "main" thread will sleep + } catch (InterruptedException e) { + } + Assertions.assertTrue(MainPage.islastMessageLinkPresent()); + + } @BeforeAll public static void setup() { diff --git a/kurnaev/src/test/java/context/ChromeContext.java b/kurnaev/src/test/java/context/ChromeContext.java index 05d9cde..6bdc910 100644 --- a/kurnaev/src/test/java/context/ChromeContext.java +++ b/kurnaev/src/test/java/context/ChromeContext.java @@ -1,6 +1,7 @@ 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"; diff --git a/kurnaev/src/test/java/context/Context.java b/kurnaev/src/test/java/context/Context.java index 9465b00..49d9782 100644 --- a/kurnaev/src/test/java/context/Context.java +++ b/kurnaev/src/test/java/context/Context.java @@ -20,8 +20,10 @@ public abstract class Context { public void start() { System.setProperty(getDriverType(), getDriverExecutablePath()); - driver = new ChromeDriver(new ChromeOptions().addArguments("--disable-notifications")); + //driver = new ChromeDriver(); + createDriver(); driver.manage().window().maximize(); + // это плохая инструкция для автотестов, т.к. лучше задавать для конкретного элемента или кейса driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); } diff --git a/kurnaev/src/test/java/page/MainPage.java b/kurnaev/src/test/java/page/MainPage.java index a3556e0..9bbfa35 100644 --- a/kurnaev/src/test/java/page/MainPage.java +++ b/kurnaev/src/test/java/page/MainPage.java @@ -15,9 +15,18 @@ public class MainPage { @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='main_head']/div[1]/div") + @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; + public MainPage(WebDriver driver) { this.driver = driver; } @@ -28,7 +37,10 @@ public class MainPage { public void clickRulesLink() { rulesLink.click(); } - public void clickPreviewLink() { new Actions(driver).moveToElement(previewLinkContainer,318,233).click().perform(); } + public void clickPreviewLink() { previewLinkContainer.click(); } + public void clickpopularGiveup() { popularGiveup.click(); } + public void clickexternalLink() { externalLink.click(); } + public void clicklastMessageLink() { lastMessageLink.click(); } public static boolean isRulesPresent() { try { @@ -52,4 +64,37 @@ public class MainPage { } } + 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; + } + + } }