This commit is contained in:
Kochkaleva 2018-11-27 13:45:06 +04:00
parent 978bf399a8
commit e8b00cbe09
12 changed files with 220 additions and 177 deletions

View File

@ -29,9 +29,9 @@
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.1.0-RC1</version>
</dependency>
<dependency>
@ -39,6 +39,18 @@
<artifactId>javafaker</artifactId>
<version>0.16</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

Binary file not shown.

View File

@ -0,0 +1,25 @@
package helpers;
import org.openqa.selenium.chrome.ChromeDriver;
public class ChromeContext extends Context {
private final static String WINDOWS_DRIVER = "chromedriver.exe";
private final static String LINUX_DRIVER = "chromedriver";
private final static String DRIVER_TYPE = "webdriver.chrome.driver";
@Override
protected void createDriver() {
driver = new ChromeDriver();
}
@Override
protected String getDriverExecutable(boolean isWindows) {
return isWindows ? WINDOWS_DRIVER : LINUX_DRIVER;
}
@Override
protected String getDriverType() {
return DRIVER_TYPE;
}
}

View File

@ -0,0 +1,45 @@
package helpers;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
public abstract class Context {
private final static String DRIVER_LOCATION = "src\\main\\resources\\chromedriver.exe";
protected WebDriver driver;
public WebDriver getDriver() {
if (driver != null) {
return driver;
}
throw new IllegalStateException("WebDriver is not initialized");
}
public void start() {
System.setProperty("webdriver.chrome.driver", "src\\main\\resources\\chromedriver.exe");
driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
}
public void close() {
driver.quit();
}
protected abstract void createDriver();
protected abstract String getDriverType();
protected abstract String getDriverExecutable(boolean windows);
private String getDriverExecutablePath() {
System.setProperty("webdriver.chrome.driver", DRIVER_LOCATION);
return null;
}
private boolean isWindows() {
return System.getProperty("os.name").toLowerCase().contains("windows");
}
}

View File

@ -7,7 +7,6 @@ import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;
import java.security.Key;
public class Email {

View File

@ -62,6 +62,15 @@ public class Sort {
sortDropDown.click();
}
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 void sortBySalesClick() {
sortBySales.click();
}

View File

@ -1,30 +1,32 @@
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 helpers.ChromeContext;
import helpers.Context;
import pages.Email;
import org.junit.*;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.WebDriver;
import java.util.concurrent.TimeUnit;
public class EmailTests {
private static WebDriver driver;
private static Email email;
private static Context context;
@Before
public void setUp() {
System.setProperty("webdriver.chrome.driver", "src\\main\\resources\\chromedriver.exe");
driver = new ChromeDriver();
@BeforeAll
public static void setUp() {
driver.manage().window().maximize();
driver.get("https://ostin.com/");
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
context = new ChromeContext();
context.start();
email = new Email(driver);
context.getDriver().manage().window().maximize();
context.getDriver().get("https://ostin.com/");
context.getDriver().manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
email = new Email((WebDriver) context);
}
@Test
@ -44,10 +46,17 @@ public class EmailTests {
@Test
public void checkForLogIn() {
boolean pass = false;
email.logInLinkCLick();
// В кавычках ниже заполнишь своими данными.
email.fillFields("", "");
// В кавычках ниже заполнить данными
email.fillFields("lkdlfr@mail.ru", "jhbhjbjbj");
email.logInButtonClick();
try {
email.logInButtonClick();
} catch (IllegalStateException e) {
pass = true;
}
Assert.assertTrue("login link is missing,successfully log", pass);
}
@Test
@ -55,14 +64,14 @@ public class EmailTests {
email.logInLinkCLick();
email.fillFields("asda@dasd.asd", "12312eqs");
email.logInButtonClick();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
context.getDriver().manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
String url = context.getDriver().getCurrentUrl();
Assert.assertTrue(url.contains("https://ostin.com/#"));
}
@After
public void quit() {
driver.quit();
context.getDriver().quit();
}
}

View File

@ -1,82 +0,0 @@
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

@ -2,13 +2,14 @@ package tests;
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.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import pages.Navigation;
@ -17,32 +18,32 @@ import java.util.concurrent.TimeUnit;
public class NavigationTests {
private static WebDriver driver;
private static Context context;
private static Navigation navigation;
@Before
public static void setUp() {
System.setProperty("webdriver.chrome.driver", "src\\main\\resources\\chromedriver.exe");
driver = new ChromeDriver();
context = new ChromeContext();
context.start();
driver.manage().window().maximize();
driver.get("https://ostin.com/");
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
context.getDriver().manage().window().maximize();
context.getDriver().get("https://ostin.com/");
context.getDriver().manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
navigation = new Navigation(driver);
navigation = new Navigation((WebDriver) context);
}
@Test
public void checkForSaleRedirect() {
navigation.saleLinkClick();
String url = driver.getCurrentUrl();
String url = context.getDriver().getCurrentUrl();
Assert.assertTrue(url.contains("https://ostin.com/ru/ru/catalog/sale/?m=SaleMarker"));
}
@Test
public void checkForFemalesSaleRedirect() {
navigation.saleFemaleLinkClick();
String url = driver.getCurrentUrl();
String url = context.getDriver().getCurrentUrl();
Assert.assertTrue(url
.contains("https://ostin.com/ru/ru/catalog/jenskaya_odejda/jenskaya_odejda_sale/?m=SaleMarker"));
}
@ -50,22 +51,22 @@ public class NavigationTests {
@Test
public void checkForBasementLinkRedirect() {
navigation.basementLinkClick();
String url = driver.getCurrentUrl();
String url = context.getDriver().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();
Set<String> tabs = context.getDriver().getWindowHandles();
context.getDriver().switchTo().window(Iterators.getLast(tabs.iterator()));
String url = context.getDriver().getCurrentUrl();
Assert.assertTrue(url.contains("https://vk.com/club20367999"));
}
@After
public void quit() {
driver.quit();
context.getDriver().quit();
}
}

View File

@ -1,48 +1,58 @@
package tests;
import helpers.ChromeContext;
import helpers.Context;
import pages.Email;
import pages.Recyclebin;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeAll;
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;
private static Context context;
@Before
@BeforeAll
public void setUp() {
System.setProperty("webdriver.chrome.driver", "src\\main\\resources\\chromedriver.exe");
driver = new ChromeDriver();
driver.manage().window().maximize();
driver
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");
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
context.getDriver().manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
recyclebin = new Recyclebin(driver);
recyclebin = new Recyclebin((WebDriver) context);
}
@Test
public void checkForAddItemToCart() {
boolean pass = false;
recyclebin.colorClick();
driver.manage().timeouts().pageLoadTimeout(10, TimeUnit.SECONDS);
context.getDriver().manage().timeouts().pageLoadTimeout(10, TimeUnit.SECONDS);
recyclebin.pickSizeClick();
try {
recyclebin.addToCartButtonClick();
Assert.assertTrue("test passed", true);
pass = true;
} catch (IllegalStateException e) {
e.printStackTrace();
}
Assert.assertTrue("test passed", pass);
}
@Test
public void checkForRemoveItem() {
boolean pass = false;
recyclebin.toCartClick();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
context.getDriver().manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
try {
recyclebin.removeItem();
pass = true;
@ -54,7 +64,7 @@ public class RecylebinTests {
@After
public void quit() {
driver.quit();
context.getDriver().quit();
}
}

View File

@ -1,17 +0,0 @@
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

@ -1,12 +1,14 @@
package tests;
import helpers.ChromeContext;
import helpers.Context;
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;
@ -14,63 +16,93 @@ import java.util.concurrent.TimeUnit;
public class SortTests {
private static WebDriver driver;
private static Context context;
private static Sort sort;
@Before
public void setUp() {
System.setProperty("webdriver.chrome.driver", "src\\main\\resources\\chromedriver.exe");
driver = new ChromeDriver();
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);
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);
sort = new Sort((WebDriver) context);
}
@Test
public void checkForSorting() {
boolean pass = false;
sort.sortDropDownClick();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
context.getDriver().manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
try {
sort.checkForDisplayed();
pass = true;
} catch (IllegalStateException e) {
e.printStackTrace();
}
Assert.assertTrue("test passed", true);
}
@Test
public void checkForSortingBt() {
boolean pass = false;
sort.sortDropDownClick();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
context.getDriver().manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
try {
sort.sortBySalesClick();
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
Assert.assertTrue("test passed", true);
context.getDriver().manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
pass = true;
} catch (IllegalStateException e) {
e.printStackTrace();
}
Assert.assertTrue("test passed", pass);
}
@Test
public void checkForSizeFiltering() {
boolean pass = false;
try {
sort.sizeFilter();
pass = true;
} catch (IllegalStateException e) {
e.printStackTrace();
}
Assert.assertEquals(true, pass);
}
@Test
public void checkForColorFiltering() {
boolean pass = false;
try {
sort.colorFilter();
pass = true;
} catch (IllegalStateException e) {
e.printStackTrace();
}
Assert.assertFalse(!pass);
}
@Test
public void checkForCostFilter() {
boolean pass = false;
try {
sort.costFilter();
pass = true;
} catch (IllegalStateException e) {
e.printStackTrace();
}
Assert.assertEquals(true, pass);
}
@Test
public void checkForSearch() {
sort.searching("куртка");
driver.manage().timeouts().pageLoadTimeout(10, TimeUnit.SECONDS);
context.getDriver().manage().timeouts().pageLoadTimeout(10, TimeUnit.SECONDS);
}
@After
public void quit() {
driver.quit();
context.getDriver().quit();
}
}