Kochkaleva #12

Closed
Ekaterina_Kochkaleva wants to merge 5 commits from Kochkaleva into master
12 changed files with 720 additions and 0 deletions
Showing only changes of commit 978bf399a8 - Show all commits

44
Kochkaleva/pom.xml Normal file
View File

@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>kochkaleva_labs</groupId>
<artifactId>kochkaleva_labs</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.7.1</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<dependency>
<groupId>com.github.javafaker</groupId>
<artifactId>javafaker</artifactId>
<version>0.16</version>
</dependency>
</dependencies>
</project>

Binary file not shown.

View File

@ -0,0 +1,76 @@
package pages;
import com.github.javafaker.Faker;
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.security.Key;
public class Email {
private WebDriver driver;
Faker faker = new Faker();
public Email(WebDriver driver) {
PageFactory.initElements(driver, this);
this.driver = driver;
}
@FindBy(name = "email")
private WebElement emailField;
@FindBy(xpath = "//*[@id=\"subscribe_submit\"]")
private WebElement submitButton;
@FindBy(xpath = "//*[@id=\"subscribePopup\"]/div[1]")
private WebElement succsessAlert;
@FindBy(id = "loginRef")
private WebElement logInLink;
@FindBy(name = "login")
private WebElement loginField;
@FindBy(name = "password")
private WebElement passwordField;
@FindBy(id = "loginPopupButtonID")
private WebElement logInButton;
public void emailService() {
String firstPart = faker.name().firstName();
String secondPart = faker.name().lastName();
String domen = faker.app().name();
emailField.sendKeys(Keys.chord(Keys.CONTROL, "v") + firstPart + secondPart + "@" + domen + ".com");
}
public void submitButtonClick() {
submitButton.click();
}
public void setSuccsessAlert() {
if (succsessAlert != null || succsessAlert.isDisplayed()) {
} else {
throw new IllegalStateException("something went wrong");
}
}
public void logInLinkCLick() {
logInLink.click();
}
public void fillFields(String email,String password) {
emailField.sendKeys(email);
passwordField.sendKeys(password);
}
public void logInButtonClick() {
logInButton.click();
}
}

View File

@ -0,0 +1,59 @@
package pages;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;
public class Navigation {
private WebDriver driver;
public Navigation(WebDriver driver) {
PageFactory.initElements(driver, this);
this.driver = driver;
}
@FindBy(xpath = "/html/body/div[7]/div[1]/div/div[4]/div/a[1]")
private WebElement yesCityButton;
@FindBy(xpath = "//*[@id=\"cat_cat308680401\"]/a")
private WebElement saleLink;
@FindBy(xpath = "//*[@id=\"cat_cat308680401\"]/div/div/div/div/ul/li[1]/a")
private WebElement saleFemaleLink;
@FindBy(xpath = "//*[@id=\"atg_store_footer\"]/div[2]/div/div/div/div[1]/a[2]")
private WebElement basementLink;
@FindBy(xpath = "//*[@id=\"atg_store_footer\"]/div[3]/div/ul/li[2]/div[1]/div/a[2]")
private WebElement socialElementLink;
private void setCurrentCity() {
if (yesCityButton != null) {
yesCityButton.click();
}
}
public void saleLinkClick() {
setCurrentCity();
saleLink.click();
}
public void saleFemaleLinkClick() {
setCurrentCity();
saleFemaleLink.click();
}
public void basementLinkClick() {
setCurrentCity();
basementLink.click();
}
public void socialElementLinkClcik() {
setCurrentCity();
socialElementLink.click();
}
}

View File

@ -0,0 +1,65 @@
package pages;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;
public class Recyclebin {
private WebDriver driver;
public Recyclebin(WebDriver driver) {
PageFactory.initElements(driver, this);
this.driver = driver;
}
@FindBy(xpath = "//*[@id=\"sc_19836410299\"]")
private WebElement color;
@FindBy(id = "size_170398140299")
private WebElement pickSize;
@FindBy(id = "addItemToOrderID")
private WebElement addToCartButton;
@FindBy(xpath = "//*[@id=\"headerCart\"]/a")
private WebElement toCart;
@FindBy(xpath = "//*[@id=\"cartPopup\"]/div[2]/div[2]/div[2]/a")
private WebElement followCart;
@FindBy(xpath = "//*[@id=\"atg_store_content\"]/div[9]/div[2]/div/div/ul/li[1]/div/a/img")
private WebElement imagePoint;
@FindBy(xpath = "//*[@id=\"atg_store_content\"]/div[9]/div[2]/div/div/a")
private WebElement removeLink;
public void pickSizeClick() {
pickSize.click();
}
public void colorClick() {
color.click();
}
public void addToCartButtonClick() {
addToCartButton.click();
}
public void toCartClick() {
toCart.click();
if (followCart != null) {
followCart.click();
}
}
public void removeItem() {
if (imagePoint == null) {
throw new IllegalStateException("Elements is missing," +
" look like a bad ELF magic!");
} else {
removeLink.click();
}
}
}

View File

@ -0,0 +1,102 @@
package pages;
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;
public class Sort {
private WebDriver driver;
public Sort(WebDriver driver) {
PageFactory.initElements(driver, this);
this.driver = driver;
}
@FindBy(xpath = "//*[@id=\"atg_store_content\"]/div[2]/div[2]/div[1]/div/form/div/i")
private WebElement sortDropDown;
@FindBy(xpath = "//*[@id=\"atg_store_content\"]/div[2]/div[2]/div[1]/div/form/div/div/div[2]/ul/li[4]")
private WebElement sortBySales;
@FindBy(xpath = "//*[@id=\"atg_store_content\"]/div[2]/div[2]/div[1]/div/form/div/span")
private WebElement sortLabel;
@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")
private WebElement checkBoxSize;
@FindBy(xpath = "//*[@id=\"atg_store_content\"]/div[2]/div[2]/div[2]/form/div[2]/i")
private WebElement dropDownColor;
@FindBy(xpath = "//*[@id=\"atg_store_content\"]/div[2]/div[2]/div[2]/form/div[2]/div/div[2]/ul/li[1]/label/span/i")
private WebElement checkBoxColor;
@FindBy(xpath = "//*[@id=\"atg_store_content\"]/div[2]/div[2]/div[2]/form/div[3]/i")
private WebElement dropDownCost;
@FindBy(xpath = "//*[@id=\"searchPriceSliderMin\"]")
private WebElement minCostField;
@FindBy(xpath = "//*[@id=\"atg_store_content\"]/div[2]/div[2]/div[2]/form/div[3]/div/div[2]/a")
private WebElement submitButton;
@FindBy(xpath = "//*[@id=\"searchForm\"]/a")
private WebElement searchButton;
@FindBy(id = "atg_store_searchInput")
private WebElement searchField;
public static int random(int lowerBound, int upperBound) {
return (lowerBound + (int) Math.round(Math.random()
* (upperBound - lowerBound)));
}
public void sortDropDownClick() {
sortDropDown.click();
}
public void sortBySalesClick() {
sortBySales.click();
}
public String setSortLabel() {
String labelText = sortLabel.getAttribute("innerText");
return labelText;
}
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"));
submit.click();
}
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"));
submit.click();
}
public void costFilter() {
int cost = random(1500, 5000);
dropDownCost.click();
minCostField.sendKeys(Integer.toString(cost));
submitButton.click();
}
public void searching(String type) {
searchButton.click();
searchField.sendKeys(type, Keys.RETURN);
}
}

View File

@ -0,0 +1,68 @@
package tests;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import pages.Email;
import java.util.concurrent.TimeUnit;
public class EmailTests {
private static WebDriver driver;
private static Email email;
@Before
public void setUp() {
System.setProperty("webdriver.chrome.driver", "src\\main\\resources\\chromedriver.exe");
driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("https://ostin.com/");
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
email = new Email(driver);
}
@Test
public void checkForFollow() throws InterruptedException {
boolean pass = false;
Thread.sleep(3000);
email.emailService();
email.submitButtonClick();
try {
email.setSuccsessAlert();
pass = true;
} catch (IllegalStateException e) {
e.printStackTrace();
}
Assert.assertTrue("passed", pass);
}
@Test
public void checkForLogIn() {
email.logInLinkCLick();
// В кавычках ниже заполнишь своими данными.
email.fillFields("", "");
email.logInButtonClick();
}
@Test
public void checkForLogOut() {
email.logInLinkCLick();
email.fillFields("asda@dasd.asd", "12312eqs");
email.logInButtonClick();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
}
@After
public void quit() {
driver.quit();
}
}

View File

@ -0,0 +1,82 @@
package tests;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.rules.TestRule;
import org.junit.rules.TestWatcher;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;
import java.awt.*;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.Locale;
public class JUnitTestReporter {
final static DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("EEEE MMM d, YYYY", Locale.CANADA);
static File junitReport;
static BufferedWriter junitWriter;
@BeforeClass
public void setUp() throws IOException {
DateFormat dateFormat = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss");
Date date = new Date();
String junitReportFile = System.getProperty("user.dir")
+ "\\ReportFile" + LocalDate.now().format(dateFormatter) + ".html";
junitReport = new File(junitReportFile);
junitWriter = new BufferedWriter(new FileWriter(junitReport, true));
junitWriter.write("<html><body>");
junitWriter.write("<h1>Test Execution Summary - " + dateFormat.format(date)
+ "</h1>");
}
@AfterClass
public static void tearDown() throws IOException {
junitWriter.write("</body></html>");
junitWriter.close();
Desktop.getDesktop().browse(junitReport.toURI());
}
@Rule
public TestRule junitWaiter = new TestWatcher() {
@Override
public Statement apply(Statement base, Description description) {
return super.apply(base, description);
}
@Override
protected void succeeded(Description description) {
try {
junitWriter.write(description.getDisplayName() + " "
+ "success!");
junitWriter.write("<br/>");
} catch (Exception e1) {
System.out.println(e1.getMessage());
}
}
@Override
protected void failed(Throwable e, Description description) {
try {
junitWriter.write(description.getDisplayName() + " "
+ e.getClass().getSimpleName());
junitWriter.write("<br/>");
} catch (Exception e2) {
System.out.println(e2.getMessage());
}
}
};
}

View File

@ -0,0 +1,71 @@
package tests;
import com.google.common.collect.Iterators;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import pages.Navigation;
import java.util.Set;
import java.util.concurrent.TimeUnit;
public class NavigationTests {
private static WebDriver driver;
private static Navigation navigation;
@Before
public static void setUp() {
System.setProperty("webdriver.chrome.driver", "src\\main\\resources\\chromedriver.exe");
driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("https://ostin.com/");
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
navigation = new Navigation(driver);
}
@Test
public void checkForSaleRedirect() {
navigation.saleLinkClick();
String url = driver.getCurrentUrl();
Assert.assertTrue(url.contains("https://ostin.com/ru/ru/catalog/sale/?m=SaleMarker"));
}
@Test
public void checkForFemalesSaleRedirect() {
navigation.saleFemaleLinkClick();
String url = driver.getCurrentUrl();
Assert.assertTrue(url
.contains("https://ostin.com/ru/ru/catalog/jenskaya_odejda/jenskaya_odejda_sale/?m=SaleMarker"));
}
@Test
public void checkForBasementLinkRedirect() {
navigation.basementLinkClick();
String url = driver.getCurrentUrl();
Assert.assertTrue(url.contains("https://ostin.com/ru/ru/pages/promo/"));
}
@Test
public void checkForFollowSocialLink() {
navigation.socialElementLinkClcik();
Set<String> tabs = driver.getWindowHandles();
driver.switchTo().window(Iterators.getLast(tabs.iterator()));
String url = driver.getCurrentUrl();
Assert.assertTrue(url.contains("https://vk.com/club20367999"));
}
@After
public void quit() {
driver.quit();
}
}

View File

@ -0,0 +1,60 @@
package tests;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import pages.Recyclebin;
import java.util.concurrent.TimeUnit;
public class RecylebinTests {
private static WebDriver driver;
private static Recyclebin recyclebin;
@Before
public void setUp() {
System.setProperty("webdriver.chrome.driver", "src\\main\\resources\\chromedriver.exe");
driver = new ChromeDriver();
driver.manage().window().maximize();
driver
.get("https://ostin.com/ru/ru/catalog/jenskaya_odejda/" +
"jenskaya_verhnyaya_odejda/jenskie_kurtki_i_vetrovki/156777240299/?scId=19836410299");
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
recyclebin = new Recyclebin(driver);
}
@Test
public void checkForAddItemToCart() {
recyclebin.colorClick();
driver.manage().timeouts().pageLoadTimeout(10, TimeUnit.SECONDS);
recyclebin.pickSizeClick();
recyclebin.addToCartButtonClick();
Assert.assertTrue("test passed", true);
}
@Test
public void checkForRemoveItem() {
boolean pass = false;
recyclebin.toCartClick();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
try {
recyclebin.removeItem();
pass = true;
} catch (IllegalStateException e) {
e.printStackTrace();
}
Assert.assertTrue("passed", pass);
}
@After
public void quit() {
driver.quit();
}
}

View File

@ -0,0 +1,17 @@
package tests;
import org.junit.runner.JUnitCore;
import org.junit.runner.Result;
import pages.Recyclebin;
public class RunTests {
public static void main(String[] args) {
Result result = JUnitCore
.runClasses(NavigationTests.class, SortTests.class, EmailTests.class, Recyclebin.class);
System.out.println("Total number of tests: " + result.getRunCount());
System.out.println("Total number of tests failed: " + result.getFailureCount());
}
}

View File

@ -0,0 +1,76 @@
package tests;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import pages.Sort;
import java.util.concurrent.TimeUnit;
public class SortTests {
private static WebDriver driver;
private static Sort sort;
@Before
public void setUp() {
System.setProperty("webdriver.chrome.driver", "src\\main\\resources\\chromedriver.exe");
driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("https://ostin.com/ru/ru/catalog/jenskaya_odejda/jenskaya_verhnyaya_odejda/");
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
sort = new Sort(driver);
}
@Test
public void checkForSorting() {
sort.sortDropDownClick();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
Assert.assertTrue("test passed", true);
}
@Test
public void checkForSortingBt() {
sort.sortDropDownClick();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
sort.sortBySalesClick();
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
Assert.assertTrue("test passed", true);
}
@Test
public void checkForSizeFiltering() {
sort.sizeFilter();
}
@Test
public void checkForColorFiltering() {
sort.colorFilter();
}
@Test
public void checkForCostFilter() {
sort.costFilter();
}
@Test
public void checkForSearch() {
sort.searching("куртка");
driver.manage().timeouts().pageLoadTimeout(10, TimeUnit.SECONDS);
}
@After
public void quit() {
driver.quit();
}
}