From 7e349a72ecd6ad8ca0aacfd0acbcffaa4ce5f110 Mon Sep 17 00:00:00 2001 From: alexandrakrav Date: Thu, 11 Oct 2018 20:27:06 +0400 Subject: [PATCH] bugfix --- Kravchenko/src/test/java/ExternalLinks.java | 5 +++- Kravchenko/src/test/java/Search.java | 16 +++++------ .../src/test/java/page/AboutCompanyPage.java | 26 +++++++++--------- Kravchenko/src/test/java/page/MainPage.java | 27 ++++++++++--------- Kravchenko/src/test/java/page/SearchPage.java | 12 +++------ 5 files changed, 42 insertions(+), 44 deletions(-) diff --git a/Kravchenko/src/test/java/ExternalLinks.java b/Kravchenko/src/test/java/ExternalLinks.java index 869bc92..c9ac217 100644 --- a/Kravchenko/src/test/java/ExternalLinks.java +++ b/Kravchenko/src/test/java/ExternalLinks.java @@ -24,7 +24,7 @@ public class ExternalLinks { context.close(); } @Test - public void OpenMapTest() + public void OpenMapTest() { context.getDriver().get(APP_URL); MainPage page = PageFactory.initElements(context.getDriver(), MainPage.class); @@ -52,6 +52,9 @@ public class ExternalLinks { AboutCompanyPage aboutPage = PageFactory.initElements(context.getDriver(), AboutCompanyPage.class); aboutPage.clickShareElement(); aboutPage.isPageDisplaySubmitButton(); + Assertions.assertTrue(aboutPage.isPageDisplaySubmitButton()); + + } diff --git a/Kravchenko/src/test/java/Search.java b/Kravchenko/src/test/java/Search.java index a890f1f..33f609f 100644 --- a/Kravchenko/src/test/java/Search.java +++ b/Kravchenko/src/test/java/Search.java @@ -12,7 +12,7 @@ import page.*; public class Search { private final static String APP_URL = "http://www.sberbank-ast.ru/"; private static Context context; - + String search = "Поставка"; @BeforeAll public static void setup() { @@ -29,31 +29,31 @@ public class Search { public void searchHeaderTest() { context.getDriver().get(APP_URL); MainPage page = PageFactory.initElements(context.getDriver(), MainPage.class); - page.insertSearchHeaderText("Поставка"); + page.insertSearchHeaderText(search); page.submitSearchHeader(); SearchPage searchPage = PageFactory.initElements(context.getDriver(), SearchPage.class); - Assertions.assertTrue(searchPage.checkSearch()); + Assertions.assertTrue(searchPage.checkSearch(search)); } @Test - public void searchHeaderTestWithFilter() { + public void searchHeaderTestWithFilter() throws RuntimeException{ context.getDriver().get(APP_URL); MainPage page = PageFactory.initElements(context.getDriver(), MainPage.class); - page.insertSearchHeaderText("Поставка"); + page.insertSearchHeaderText(search); page.submitSearchHeader(); SearchPage searchPage = PageFactory.initElements(context.getDriver(), SearchPage.class); searchPage.clickSearchFilter(); - Assertions.assertTrue(searchPage.checkSearch()); + Assertions.assertTrue(searchPage.checkSearch(search)); Assertions.assertTrue(searchPage.checkFilter()); } @Test public void searchHeaderTestWithSorting() { context.getDriver().get(APP_URL); MainPage page = PageFactory.initElements(context.getDriver(), MainPage.class); - page.insertSearchHeaderText("Поставка"); + page.insertSearchHeaderText(search); page.submitSearchHeader(); SearchPage searchPage = PageFactory.initElements(context.getDriver(), SearchPage.class); searchPage.clickSearchSortingElement(); - Assertions.assertTrue(searchPage.checkSearch()); + Assertions.assertTrue(searchPage.checkSearch(search)); } @Test diff --git a/Kravchenko/src/test/java/page/AboutCompanyPage.java b/Kravchenko/src/test/java/page/AboutCompanyPage.java index 31f021d..a82a29d 100644 --- a/Kravchenko/src/test/java/page/AboutCompanyPage.java +++ b/Kravchenko/src/test/java/page/AboutCompanyPage.java @@ -4,30 +4,35 @@ import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.FindBy; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; +import org.openqa.selenium.support.ui.ExpectedConditions; public class AboutCompanyPage { - WebDriver driver; + private WebDriver driver ; + private WebDriverWait wait; + public AboutCompanyPage(WebDriver driver) { + this.driver = driver; + wait = new WebDriverWait(driver,30,500); + } + @FindBy(xpath = "//*[@id=\"blockFacebook\"]/div/span/iframe") private WebElement shareFrame; @FindBy(css = "#u_0_3 > button") private WebElement shareButton; - public void clickShareElement() { + public void clickShareElement(){ + wait.until(ExpectedConditions.visibilityOf(shareFrame)); driver.switchTo().frame(shareFrame); - sleep(); shareButton.click(); - sleep(); for (String winHandle : driver.getWindowHandles()) { driver.switchTo().window(winHandle); } } - public AboutCompanyPage(WebDriver driver) { - this.driver = driver; - } public boolean isPageDisplayQuality() { return driver.findElement(By.cssSelector("#ctl00_phWorkZone_ContentItem_lblbody")).isDisplayed(); @@ -38,12 +43,5 @@ public class AboutCompanyPage { return driver.findElement(By.cssSelector("#u_0_0")).isDisplayed(); } - public void sleep() { - try { - Thread.sleep(5000); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } } diff --git a/Kravchenko/src/test/java/page/MainPage.java b/Kravchenko/src/test/java/page/MainPage.java index beb6a0c..ab06864 100644 --- a/Kravchenko/src/test/java/page/MainPage.java +++ b/Kravchenko/src/test/java/page/MainPage.java @@ -4,10 +4,13 @@ import org.junit.jupiter.api.Assertions; import org.openqa.selenium.*; import org.openqa.selenium.interactions.Actions; import org.openqa.selenium.support.FindBy; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; public class MainPage { String headline = ""; WebDriver driver; + private WebDriverWait wait; @FindBy(css = "#response_slider_wrap iframe") private WebElement feedbackFrame; @@ -119,6 +122,7 @@ public class MainPage { private WebElement documentsSubmenuElement; public MainPage(WebDriver driver) { this.driver = driver; + wait = new WebDriverWait(driver,30,5000); } public void clickMoreInformation() { @@ -160,13 +164,10 @@ public class MainPage { } public void clickFeedbackElement() { FeedbackElement.click(); - try { - Thread.sleep(5000); - driver.switchTo().frame(feedbackFrame); - AllFeedbackElement.click(); - } catch (InterruptedException e) { - e.printStackTrace(); - } + wait.until(ExpectedConditions.visibilityOf(feedbackFrame)); + driver.switchTo().frame(feedbackFrame); + AllFeedbackElement.click(); + } @@ -259,11 +260,11 @@ public class MainPage { } - public boolean isPageDisplayTender() - { - String checkNumber = checkNumberElement.getText(); - return checkNumber.equals(clickFzElement()); - } + public boolean isPageDisplayTender() + { + String checkNumber = checkNumberElement.getText(); + return checkNumber.equals(clickFzElement()); + } public boolean isPageDisplayArticle() @@ -288,7 +289,7 @@ public class MainPage { " > div > h2:nth-child(2)")).isDisplayed(); } public boolean isPageDisplayMain() { - try { + try { Thread.sleep(5000); } catch (InterruptedException e) { e.printStackTrace(); diff --git a/Kravchenko/src/test/java/page/SearchPage.java b/Kravchenko/src/test/java/page/SearchPage.java index e4e853c..ef74d99 100644 --- a/Kravchenko/src/test/java/page/SearchPage.java +++ b/Kravchenko/src/test/java/page/SearchPage.java @@ -56,15 +56,12 @@ public class SearchPage { } - - public void clickSearchSortingElement() { searchSortingElement.click(); } - public boolean checkSearch() { + public boolean checkSearch(String strSearch) { boolean checkSearch = false; int count = listResultSearch.size(); - String strSearch = searchHeaderElement.getAttribute("value"); for (int i = 0; i < count - 1; i++) { if (listResultSearch.get(i).getText().contains(strSearch)) checkSearch = true; @@ -75,10 +72,9 @@ public class SearchPage { public boolean checkFilter() { - double b = Math.round(Double.parseDouble(resultElement.getText().replaceAll(" ", ""))); - if (b > pr) - return true; - else return false; + double b = Math.round(Double.parseDouble(resultElement.getText().replaceAll(" ", ""))); + return b > pr; + }