From 50dac2dd23817a9dc415ebede85a58cba62576cf Mon Sep 17 00:00:00 2001 From: Kochkaleva Date: Wed, 12 Dec 2018 17:54:37 +0400 Subject: [PATCH] Edit tests3 --- Kochkaleva/src/test/java/pages/Email.java | 26 ++++++--- .../src/test/java/pages/Navigation.java | 24 ++++----- .../src/test/java/pages/Recyclebin.java | 23 +++++++- Kochkaleva/src/test/java/pages/Sort.java | 54 ++++++++++++++----- .../src/test/java/tests/EmailTests.java | 20 +++---- .../src/test/java/tests/NavigationTests.java | 25 ++++----- .../src/test/java/tests/RecylebinTests.java | 21 ++++---- Kochkaleva/src/test/java/tests/SortTests.java | 35 ++++++------ 8 files changed, 148 insertions(+), 80 deletions(-) diff --git a/Kochkaleva/src/test/java/pages/Email.java b/Kochkaleva/src/test/java/pages/Email.java index 08536d5..9eca1c7 100644 --- a/Kochkaleva/src/test/java/pages/Email.java +++ b/Kochkaleva/src/test/java/pages/Email.java @@ -1,16 +1,21 @@ package pages; import com.github.javafaker.Faker; +import helpers.Context; +import org.openqa.selenium.By; 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.support.PageFactory; +import java.util.concurrent.TimeUnit; + public class Email { private WebDriver driver; + private Context context; Faker faker = new Faker(); public Email(WebDriver driver) { @@ -52,11 +57,9 @@ public class Email { submitButton.click(); } - public void setSuccsessAlert() { - if (succsessAlert != null || succsessAlert.isDisplayed()) { - } else { - throw new IllegalStateException("something went wrong"); - } + public boolean setSuccsessAlert() { + return driver.findElement(By.xpath("//*[@id=\"subscribePopup\"]/div[1]")).isDisplayed(); + } public void logInLinkCLick() { @@ -68,5 +71,16 @@ public class Email { passwordField.sendKeys(password); } - public void logInButtonClick() {logInButton.click(); } + public void logInButtonClick() { + logInButton.click(); + context.getDriver().manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); + } + + public boolean canClickLogInButton() { + return driver.findElement(By.id("loginPopupButtonID")).isEnabled(); + } + + public boolean logInButtonDisplayed() { + return logInButton.isDisplayed(); + } } diff --git a/Kochkaleva/src/test/java/pages/Navigation.java b/Kochkaleva/src/test/java/pages/Navigation.java index 6a96fbf..7cddf8a 100644 --- a/Kochkaleva/src/test/java/pages/Navigation.java +++ b/Kochkaleva/src/test/java/pages/Navigation.java @@ -42,20 +42,20 @@ public class Navigation { @FindBy(xpath = "//*[@id=\"atg_store_content\"]/div/div[1]/div/div[1]/a") private WebElement womenSales; - public void setMainTitle() { - String title = mainTitle.getAttribute("InnerText"); - if (title.equals("Распродажа женской одежды O`STIN")) { - } else { - throw new IllegalStateException("something went wrong"); - } + public boolean womaneSalesLink() { + return womenSales.isDisplayed(); } - public void setPageName() { - String title = pageName.getAttribute("InnerText"); - if (title.equals("O'STIN | ОСТИН")) { - } else { - throw new IllegalStateException("something went wrong"); - } + public boolean setMainTitle() { + return mainTitle.isDisplayed(); + } + + public boolean setDisplayedPromo() { + return displayedPromo.isDisplayed(); + } + + public boolean setPageName() { + return pageName.isDisplayed(); } private void setCurrentCity() { diff --git a/Kochkaleva/src/test/java/pages/Recyclebin.java b/Kochkaleva/src/test/java/pages/Recyclebin.java index f1d2fbc..cfe8b7a 100644 --- a/Kochkaleva/src/test/java/pages/Recyclebin.java +++ b/Kochkaleva/src/test/java/pages/Recyclebin.java @@ -1,13 +1,18 @@ package pages; +import helpers.Context; +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.PageFactory; +import java.util.concurrent.TimeUnit; + public class Recyclebin { private WebDriver driver; + private Context context; public Recyclebin(WebDriver driver) { PageFactory.initElements(driver, this); @@ -40,11 +45,25 @@ public class Recyclebin { } public void colorClick() { color.click(); + context.getDriver().manage().timeouts().pageLoadTimeout(10, TimeUnit.SECONDS); } + public void addToCartButtonClick() { addToCartButton.click(); } - public void toCartClick() {followCart.click(); } - public void removeItem() { removeLink.click(); } + public boolean afterClick() { + return driver.findElement(By.xpath("//*[@id=\"cartPopup\"]/div[2]/div[2]/div[2]/a")).isDisplayed(); + } + + public void toCartClick() { + context.getDriver().manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); + toCart.click(); + context.getDriver().manage().timeouts().pageLoadTimeout(10, TimeUnit.SECONDS); + followCart.click(); + } + + public boolean removeItem() { + return !imagePoint.isDisplayed(); + } } diff --git a/Kochkaleva/src/test/java/pages/Sort.java b/Kochkaleva/src/test/java/pages/Sort.java index 3f2c133..35c6d72 100644 --- a/Kochkaleva/src/test/java/pages/Sort.java +++ b/Kochkaleva/src/test/java/pages/Sort.java @@ -1,5 +1,6 @@ package pages; +import helpers.Context; import org.openqa.selenium.By; import org.openqa.selenium.Keys; import org.openqa.selenium.WebDriver; @@ -7,9 +8,12 @@ import org.openqa.selenium.WebElement; import org.openqa.selenium.support.FindBy; import org.openqa.selenium.support.PageFactory; +import java.util.concurrent.TimeUnit; + public class Sort { private WebDriver driver; + private static Context context; public Sort(WebDriver driver) { PageFactory.initElements(driver, this); @@ -28,8 +32,8 @@ public class Sort { @FindBy(xpath = "//*[@id=\"atg_store_content\"]/div[2]/div[2]/div[2]/form/div[1]/i") private WebElement dropDownSize; - @FindBy(xpath = "//*[@id=\"atg_store_content\"]/div[2]/div[2]/div[2]/form/div[1]/div/" + - "div[2]/ul/div/div/li[1]/label/input") + @FindBy(xpath = "//*[@id=\"atg_store_content\"]/div[2]/div[2]/div[2]/form/div[1]/div/div[2]/ul/div/div/li[1]/" + + "label/input") private WebElement checkBoxSize; @FindBy(xpath = "//*[@id=\"atg_store_content\"]/div[2]/div[2]/div[2]/form/div[2]/i") @@ -71,19 +75,23 @@ public class Sort { public void sortDropDownClick() { sortDropDown.click(); + context.getDriver().manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); } - public void checkForDisplayed() { - WebElement displayedSort = driver.findElement(By - .xpath("//*[@id=\"atg_store_content\"]/div[2]/div[2]/div[1]/div/form/div/div/div[2]/ul/li[1]")); - if ( displayedSort != null) { - - } else { - throw new IllegalStateException("something went wrong"); - } + public boolean checkForDisplayed() { + return driver.findElement(By + .xpath("//*[@id=\"atg_store_content\"]/div[2]/div[2]/div[1]/div/form/div/div/div[2]/ul/li[1]")) + .isDisplayed(); } + public void sortBySalesClick() { sortBySales.click(); + context.getDriver().manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); + } + + public boolean checkForSalesDisplayed() { + return driver.findElement(By.xpath("//*[@id=\"atg_store_content\"]/div[2]/div[2]/div[1]/div/form/div/span")) + .isDisplayed(); } public String setSortLabel() { @@ -94,17 +102,29 @@ public class Sort { public void sizeFilter() { dropDownSize.click(); checkBoxSize.click(); - WebElement submit = driver.findElement(By.xpath("//*[@id=\"atg_store_content\"]/div[2]/div[2]/div[2]/form/div[1]/div/div[2]/a")); + WebElement submit = driver.findElement(By + .xpath("//*[@id=\"atg_store_content\"]/div[2]/div[2]/div[2]/form/div[1]/div/div[2]/a")); submit.click(); } + public boolean checkForSize() { + return driver.findElement(By.cssSelector("//*[@id=\"atg_store_content\"]" + + "/div[2]/div[2]/div[2]/form/div[1]/label")).isDisplayed(); + } + public void colorFilter() { dropDownColor.click(); checkBoxColor.click(); - WebElement submit = driver.findElement(By.xpath("//*[@id=\"atg_store_content\"]/div[2]/div[2]/div[2]/form/div[1]/div/div[2]/a")); + WebElement submit = driver.findElement(By + .xpath("//*[@id=\"atg_store_content\"]/div[2]/div[2]/div[2]/form/div[1]/div/div[2]/a")); submit.click(); } + public boolean checkForColor() { + return driver.findElement(By.xpath("//*[@id=\"atg_store_content\"]/div[2]/div[2]/div[2]/form/div[2]/i")) + .isDisplayed(); + } + public void costFilter() { int cost = random(1500, 5000); dropDownCost.click(); @@ -112,9 +132,19 @@ public class Sort { submitButton.click(); } + public boolean checkForCost() { + return driver.findElement(By.xpath("//*[@id=\"atg_store_content\"]/div[2]/div[2]/div[2]/form/div[3]/i")) + .isDisplayed(); + } + public void searching(String type) { searchButton.click(); searchField.sendKeys(type, Keys.RETURN); + context.getDriver().manage().timeouts().pageLoadTimeout(10, TimeUnit.SECONDS); + } + + public boolean checkForResultSearching() { + return driver.findElement(By.xpath("//*[@id=\"atg_store_content\"]/div[2]/div[2]/div[1]/h1")).isDisplayed(); } } diff --git a/Kochkaleva/src/test/java/tests/EmailTests.java b/Kochkaleva/src/test/java/tests/EmailTests.java index e74c914..779cf94 100644 --- a/Kochkaleva/src/test/java/tests/EmailTests.java +++ b/Kochkaleva/src/test/java/tests/EmailTests.java @@ -2,6 +2,8 @@ package tests; import helpers.ChromeContext; import helpers.Context; +import org.junit.jupiter.api.Assertions; +import org.openqa.selenium.support.PageFactory; import pages.Email; import org.junit.*; @@ -10,12 +12,12 @@ import org.junit.jupiter.api.Test; import org.openqa.selenium.WebDriver; -import java.util.concurrent.TimeUnit; public class EmailTests { private static Email email; private static Context context; + private final static String URL = "https://ostin.com/"; @BeforeAll public static void setUp() { @@ -24,8 +26,7 @@ public class EmailTests { context.start(); context.getDriver().manage().window().maximize(); - context.getDriver().get("https://ostin.com/"); - context.getDriver().manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); + context.getDriver().get(URL); email = new Email((WebDriver) context); } @@ -34,8 +35,8 @@ public class EmailTests { Thread.sleep(3000); email.emailService(); email.submitButtonClick(); - email.setSuccsessAlert(); - Assert.assertTrue("passed", true); + Email email = PageFactory.initElements(context.getDriver(), Email.class); + Assertions.assertTrue(email.setSuccsessAlert()); } @Test @@ -43,18 +44,17 @@ public class EmailTests { email.logInLinkCLick(); email.fillFields("lkdlfr@mail.ru", "jhbhjbjbj"); email.logInButtonClick(); - email.logInButtonClick(); - Assert.assertTrue("login link is missing, successfully log", true); + PageFactory.initElements(context.getDriver(), Email.class); + Assertions.assertTrue(email.canClickLogInButton()); } @Test public void checkForLogOut() { - boolean pass = false; email.logInLinkCLick(); email.fillFields("asda@dasd.asd", "12312eqs"); email.logInButtonClick(); - context.getDriver().manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); - Assert.assertTrue("test passed", pass); + PageFactory.initElements(context.getDriver(), Email.class); + Assertions.assertTrue(email.logInButtonDisplayed()); } @After diff --git a/Kochkaleva/src/test/java/tests/NavigationTests.java b/Kochkaleva/src/test/java/tests/NavigationTests.java index 285a80f..5bcc067 100644 --- a/Kochkaleva/src/test/java/tests/NavigationTests.java +++ b/Kochkaleva/src/test/java/tests/NavigationTests.java @@ -5,30 +5,29 @@ import com.google.common.collect.Iterators; import helpers.ChromeContext; import helpers.Context; import org.junit.After; -import org.junit.Assert; import org.junit.Before; import org.junit.Test; +import org.junit.jupiter.api.Assertions; import org.openqa.selenium.WebDriver; +import org.openqa.selenium.support.PageFactory; import pages.Navigation; import java.util.Set; -import java.util.concurrent.TimeUnit; public class NavigationTests { private static Context context; private static Navigation navigation; + private final static String URL = "https://ostin.com/"; @Before public static void setUp() { context = new ChromeContext(); context.start(); - context.getDriver().manage().window().maximize(); - context.getDriver().get("https://ostin.com/"); - context.getDriver().manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); + context.getDriver().get(URL); navigation = new Navigation((WebDriver) context); } @@ -36,21 +35,23 @@ public class NavigationTests { @Test public void checkForSaleRedirect() { navigation.saleLinkClick(); - Assert.assertTrue("test passed", true); + navigation.womaneSalesLink(); + PageFactory.initElements(context.getDriver(), Navigation.class); + Assertions.assertTrue(navigation.womaneSalesLink()); } @Test public void checkForFemalesSaleRedirect() { navigation.saleFemaleLinkClick(); - navigation.setMainTitle(); - Assert.assertTrue("passed", true); + PageFactory.initElements(context.getDriver(), Navigation.class); + Assertions.assertTrue(navigation.setMainTitle()); } @Test public void checkForBasementLinkRedirect() { - boolean pass = false; navigation.basementLinkClick(); - Assert.assertTrue("passed", true); + PageFactory.initElements(context.getDriver(), Navigation.class); + Assertions.assertTrue(navigation.setDisplayedPromo()); } @Test @@ -58,8 +59,8 @@ public class NavigationTests { navigation.socialElementLinkClcik(); Set tabs = context.getDriver().getWindowHandles(); context.getDriver().switchTo().window(Iterators.getLast(tabs.iterator())); - navigation.setPageName(); - Assert.assertTrue("passed", true); + PageFactory.initElements(context.getDriver(), Navigation.class); + Assertions.assertTrue(navigation.setPageName()); } @After diff --git a/Kochkaleva/src/test/java/tests/RecylebinTests.java b/Kochkaleva/src/test/java/tests/RecylebinTests.java index 54f6a57..8a080ed 100644 --- a/Kochkaleva/src/test/java/tests/RecylebinTests.java +++ b/Kochkaleva/src/test/java/tests/RecylebinTests.java @@ -2,49 +2,50 @@ package tests; import helpers.ChromeContext; import helpers.Context; -import pages.Email; +import org.junit.jupiter.api.Assertions; +import org.openqa.selenium.support.PageFactory; import pages.Recyclebin; import org.junit.After; -import org.junit.Assert; import org.junit.Test; import org.junit.jupiter.api.BeforeAll; import org.openqa.selenium.WebDriver; -import java.util.concurrent.TimeUnit; public class RecylebinTests { private static Recyclebin recyclebin; private static Context context; + private final static String URL = "https://ostin.com/ru/ru/catalog/jenskaya_odejda/" + + "jenskaya_verhnyaya_odejda/jenskie_kurtki_i_vetrovki/156777240299/?scId=19836410299"; @BeforeAll public void setUp() { context = new ChromeContext(); context.start(); - context.getDriver().manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); context.getDriver().manage().window().maximize(); - context.getDriver().get("https://ostin.com/ru/ru/catalog/jenskaya_odejda/" + "jenskaya_verhnyaya_odejda/jenskie_kurtki_i_vetrovki/156777240299/?scId=19836410299"); - context.getDriver().manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); + context.getDriver().get(URL); + recyclebin = new Recyclebin((WebDriver) context); } @Test public void checkForAddItemToCart() { recyclebin.colorClick(); - context.getDriver().manage().timeouts().pageLoadTimeout(10, TimeUnit.SECONDS); recyclebin.pickSizeClick(); recyclebin.addToCartButtonClick(); - Assert.assertTrue("test passed", true); + PageFactory.initElements(context.getDriver(), Recyclebin.class); + Assertions.assertTrue(recyclebin.afterClick()); } @Test public void checkForRemoveItem() { recyclebin.toCartClick(); - context.getDriver().manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); + recyclebin.removeItem(); - Assert.assertTrue("passed", true); + PageFactory.initElements(context.getDriver(), Recyclebin.class); + Assertions.assertTrue(recyclebin.removeItem()); } @After diff --git a/Kochkaleva/src/test/java/tests/SortTests.java b/Kochkaleva/src/test/java/tests/SortTests.java index 81cbea0..445bbde 100644 --- a/Kochkaleva/src/test/java/tests/SortTests.java +++ b/Kochkaleva/src/test/java/tests/SortTests.java @@ -4,71 +4,74 @@ import helpers.ChromeContext; import helpers.Context; import org.junit.After; -import org.junit.Assert; import org.junit.Before; import org.junit.Test; +import org.junit.jupiter.api.Assertions; import org.openqa.selenium.WebDriver; +import org.openqa.selenium.support.PageFactory; import pages.Sort; -import java.util.concurrent.TimeUnit; public class SortTests { private static Context context; private static Sort sort; + private final static String URL = "https://ostin.com/ru/ru/catalog/jenskaya_odejda/jenskaya_verhnyaya_odejda/"; + private final static String SEARCH_TYPE = "куртка"; @Before public void setUp() { context = new ChromeContext(); context.start(); - context.getDriver().get("https://ostin.com/ru/ru/catalog/jenskaya_odejda/jenskaya_verhnyaya_odejda/"); - context.getDriver().manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); + context.getDriver().get(URL); + sort = new Sort((WebDriver) context); } @Test public void checkForSorting() { sort.sortDropDownClick(); - context.getDriver().manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); - sort.checkForDisplayed(); - Assert.assertTrue("test passed", true); + PageFactory.initElements(context.getDriver(), Sort.class); + Assertions.assertTrue(sort.checkForDisplayed()); } @Test public void checkForSortingBt() { sort.sortDropDownClick(); - context.getDriver().manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); sort.sortBySalesClick(); - context.getDriver().manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); - Assert.assertTrue("test passed", true); + PageFactory.initElements(context.getDriver(), Sort.class); + Assertions.assertTrue(sort.checkForSalesDisplayed()); } @Test public void checkForSizeFiltering() { sort.sizeFilter(); - Assert.assertTrue("passed", true); + PageFactory.initElements(context.getDriver(), Sort.class); + Assertions.assertTrue(sort.checkForSize()); } @Test public void checkForColorFiltering() { sort.colorFilter(); - Assert.assertFalse(!true); + PageFactory.initElements(context.getDriver(), Sort.class); + Assertions.assertTrue(sort.checkForColor()); } @Test public void checkForCostFilter() { sort.costFilter(); - Assert.assertTrue("passed", true); + PageFactory.initElements(context.getDriver(), Sort.class); + Assertions.assertTrue(sort.checkForCost()); } @Test public void checkForSearch() { - sort.searching("куртка"); - context.getDriver().manage().timeouts().pageLoadTimeout(10, TimeUnit.SECONDS); + sort.searching(SEARCH_TYPE); sort.setSearchingRequset(); - Assert.assertTrue("passed", true); + PageFactory.initElements(context.getDriver(), Sort.class); + Assertions.assertTrue(sort.checkForResultSearching()); } @After