Edit tests3

This commit is contained in:
Kochkaleva 2018-12-12 17:54:37 +04:00
parent d458c53a17
commit 50dac2dd23
8 changed files with 148 additions and 80 deletions

View File

@ -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();
}
}

View File

@ -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() {

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -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

View File

@ -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<String> 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

View File

@ -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

View File

@ -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