Kochkaleva #12

Closed
Ekaterina_Kochkaleva wants to merge 5 commits from Kochkaleva into master
12 changed files with 220 additions and 177 deletions
Showing only changes of commit e8b00cbe09 - Show all commits

View File

@ -29,9 +29,9 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>junit</groupId> <groupId>org.junit.jupiter</groupId>
<artifactId>junit</artifactId> <artifactId>junit-jupiter-api</artifactId>
<version>4.12</version> <version>5.1.0-RC1</version>
</dependency> </dependency>
<dependency> <dependency>
@ -39,6 +39,18 @@
<artifactId>javafaker</artifactId> <artifactId>javafaker</artifactId>
<version>0.16</version> <version>0.16</version>
</dependency> </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> </dependencies>
</project> </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.FindBy;
import org.openqa.selenium.support.PageFactory; import org.openqa.selenium.support.PageFactory;
import java.security.Key;
public class Email { public class Email {

View File

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

View File

@ -1,30 +1,32 @@
package tests; package tests;
import org.junit.After; import helpers.ChromeContext;
import org.junit.Assert; import helpers.Context;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import pages.Email; 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; import java.util.concurrent.TimeUnit;
public class EmailTests { public class EmailTests {
private static WebDriver driver;
private static Email email; private static Email email;
private static Context context;
@Before @BeforeAll
public void setUp() { public static void setUp() {
System.setProperty("webdriver.chrome.driver", "src\\main\\resources\\chromedriver.exe");
driver = new ChromeDriver();
driver.manage().window().maximize(); context = new ChromeContext();
driver.get("https://ostin.com/"); context.start();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
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 @Test
@ -44,10 +46,17 @@ public class EmailTests {
@Test @Test
public void checkForLogIn() { public void checkForLogIn() {
boolean pass = false;
email.logInLinkCLick(); email.logInLinkCLick();
// В кавычках ниже заполнишь своими данными. // В кавычках ниже заполнить данными
email.fillFields("", ""); email.fillFields("lkdlfr@mail.ru", "jhbhjbjbj");
email.logInButtonClick(); email.logInButtonClick();
try {
email.logInButtonClick();
} catch (IllegalStateException e) {
pass = true;
}
Assert.assertTrue("login link is missing,successfully log", pass);
} }
@Test @Test
@ -55,14 +64,14 @@ public class EmailTests {
email.logInLinkCLick(); email.logInLinkCLick();
email.fillFields("asda@dasd.asd", "12312eqs"); email.fillFields("asda@dasd.asd", "12312eqs");
email.logInButtonClick(); 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 @After
public void quit() { 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 com.google.common.collect.Iterators;
import helpers.ChromeContext;
import helpers.Context;
import org.junit.After; import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import pages.Navigation; import pages.Navigation;
@ -17,32 +18,32 @@ import java.util.concurrent.TimeUnit;
public class NavigationTests { public class NavigationTests {
private static WebDriver driver; private static Context context;
private static Navigation navigation; private static Navigation navigation;
@Before @Before
public static void setUp() { public static void setUp() {
System.setProperty("webdriver.chrome.driver", "src\\main\\resources\\chromedriver.exe"); context = new ChromeContext();
driver = new ChromeDriver(); context.start();
driver.manage().window().maximize(); context.getDriver().manage().window().maximize();
driver.get("https://ostin.com/"); context.getDriver().get("https://ostin.com/");
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); context.getDriver().manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
navigation = new Navigation(driver); navigation = new Navigation((WebDriver) context);
} }
@Test @Test
public void checkForSaleRedirect() { public void checkForSaleRedirect() {
navigation.saleLinkClick(); navigation.saleLinkClick();
String url = driver.getCurrentUrl(); String url = context.getDriver().getCurrentUrl();
Assert.assertTrue(url.contains("https://ostin.com/ru/ru/catalog/sale/?m=SaleMarker")); Assert.assertTrue(url.contains("https://ostin.com/ru/ru/catalog/sale/?m=SaleMarker"));
} }
@Test @Test
public void checkForFemalesSaleRedirect() { public void checkForFemalesSaleRedirect() {
navigation.saleFemaleLinkClick(); navigation.saleFemaleLinkClick();
String url = driver.getCurrentUrl(); String url = context.getDriver().getCurrentUrl();
Assert.assertTrue(url Assert.assertTrue(url
.contains("https://ostin.com/ru/ru/catalog/jenskaya_odejda/jenskaya_odejda_sale/?m=SaleMarker")); .contains("https://ostin.com/ru/ru/catalog/jenskaya_odejda/jenskaya_odejda_sale/?m=SaleMarker"));
} }
@ -50,22 +51,22 @@ public class NavigationTests {
@Test @Test
public void checkForBasementLinkRedirect() { public void checkForBasementLinkRedirect() {
navigation.basementLinkClick(); navigation.basementLinkClick();
String url = driver.getCurrentUrl(); String url = context.getDriver().getCurrentUrl();
Assert.assertTrue(url.contains("https://ostin.com/ru/ru/pages/promo/")); Assert.assertTrue(url.contains("https://ostin.com/ru/ru/pages/promo/"));
} }
@Test @Test
public void checkForFollowSocialLink() { public void checkForFollowSocialLink() {
navigation.socialElementLinkClcik(); navigation.socialElementLinkClcik();
Set<String> tabs = driver.getWindowHandles(); Set<String> tabs = context.getDriver().getWindowHandles();
driver.switchTo().window(Iterators.getLast(tabs.iterator())); context.getDriver().switchTo().window(Iterators.getLast(tabs.iterator()));
String url = driver.getCurrentUrl(); String url = context.getDriver().getCurrentUrl();
Assert.assertTrue(url.contains("https://vk.com/club20367999")); Assert.assertTrue(url.contains("https://vk.com/club20367999"));
} }
@After @After
public void quit() { public void quit() {
driver.quit(); context.getDriver().quit();
} }
} }

View File

@ -1,48 +1,58 @@
package tests; package tests;
import helpers.ChromeContext;
import helpers.Context;
import pages.Email;
import pages.Recyclebin;
import org.junit.After; import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.jupiter.api.BeforeAll;
import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import pages.Recyclebin;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
public class RecylebinTests { public class RecylebinTests {
private static WebDriver driver;
private static Recyclebin recyclebin; private static Recyclebin recyclebin;
private static Context context;
@Before @BeforeAll
public void setUp() { public void setUp() {
System.setProperty("webdriver.chrome.driver", "src\\main\\resources\\chromedriver.exe"); context = new ChromeContext();
driver = new ChromeDriver(); context.start();
context.getDriver().manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.manage().window().maximize(); context.getDriver().manage().window().maximize();
driver context.getDriver()
.get("https://ostin.com/ru/ru/catalog/jenskaya_odejda/" + .get("https://ostin.com/ru/ru/catalog/jenskaya_odejda/" +
"jenskaya_verhnyaya_odejda/jenskie_kurtki_i_vetrovki/156777240299/?scId=19836410299"); "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 @Test
public void checkForAddItemToCart() { public void checkForAddItemToCart() {
boolean pass = false;
recyclebin.colorClick(); recyclebin.colorClick();
driver.manage().timeouts().pageLoadTimeout(10, TimeUnit.SECONDS); context.getDriver().manage().timeouts().pageLoadTimeout(10, TimeUnit.SECONDS);
recyclebin.pickSizeClick(); recyclebin.pickSizeClick();
try {
recyclebin.addToCartButtonClick(); recyclebin.addToCartButtonClick();
Assert.assertTrue("test passed", true); pass = true;
} catch (IllegalStateException e) {
e.printStackTrace();
}
Assert.assertTrue("test passed", pass);
} }
@Test @Test
public void checkForRemoveItem() { public void checkForRemoveItem() {
boolean pass = false; boolean pass = false;
recyclebin.toCartClick(); recyclebin.toCartClick();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); context.getDriver().manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
try { try {
recyclebin.removeItem(); recyclebin.removeItem();
pass = true; pass = true;
@ -54,7 +64,7 @@ public class RecylebinTests {
@After @After
public void quit() { 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; package tests;
import helpers.ChromeContext;
import helpers.Context;
import org.junit.After; import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import pages.Sort; import pages.Sort;
@ -14,63 +16,93 @@ import java.util.concurrent.TimeUnit;
public class SortTests { public class SortTests {
private static WebDriver driver; private static Context context;
private static Sort sort; private static Sort sort;
@Before @Before
public void setUp() { public void setUp() {
System.setProperty("webdriver.chrome.driver", "src\\main\\resources\\chromedriver.exe"); context = new ChromeContext();
driver = new ChromeDriver(); 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(); sort = new Sort((WebDriver) context);
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 @Test
public void checkForSorting() { public void checkForSorting() {
boolean pass = false;
sort.sortDropDownClick(); 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); Assert.assertTrue("test passed", true);
} }
@Test @Test
public void checkForSortingBt() { public void checkForSortingBt() {
boolean pass = false;
sort.sortDropDownClick(); sort.sortDropDownClick();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); context.getDriver().manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
try {
sort.sortBySalesClick(); sort.sortBySalesClick();
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); context.getDriver().manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
pass = true;
Assert.assertTrue("test passed", true); } catch (IllegalStateException e) {
e.printStackTrace();
}
Assert.assertTrue("test passed", pass);
} }
@Test @Test
public void checkForSizeFiltering() { public void checkForSizeFiltering() {
boolean pass = false;
try {
sort.sizeFilter(); sort.sizeFilter();
pass = true;
} catch (IllegalStateException e) {
e.printStackTrace();
}
Assert.assertEquals(true, pass);
} }
@Test @Test
public void checkForColorFiltering() { public void checkForColorFiltering() {
boolean pass = false;
try {
sort.colorFilter(); sort.colorFilter();
pass = true;
} catch (IllegalStateException e) {
e.printStackTrace();
}
Assert.assertFalse(!pass);
} }
@Test @Test
public void checkForCostFilter() { public void checkForCostFilter() {
boolean pass = false;
try {
sort.costFilter(); sort.costFilter();
pass = true;
} catch (IllegalStateException e) {
e.printStackTrace();
}
Assert.assertEquals(true, pass);
} }
@Test @Test
public void checkForSearch() { public void checkForSearch() {
sort.searching("куртка"); sort.searching("куртка");
driver.manage().timeouts().pageLoadTimeout(10, TimeUnit.SECONDS); context.getDriver().manage().timeouts().pageLoadTimeout(10, TimeUnit.SECONDS);
} }
@After @After
public void quit() { public void quit() {
driver.quit(); context.getDriver().quit();
} }
} }