diff --git a/Kochkaleva/pom.xml b/Kochkaleva/pom.xml
index 54b7d76..c1f1a82 100644
--- a/Kochkaleva/pom.xml
+++ b/Kochkaleva/pom.xml
@@ -29,9 +29,9 @@
- junit
- junit
- 4.12
+ org.junit.jupiter
+ junit-jupiter-api
+ 5.1.0-RC1
@@ -39,6 +39,18 @@
javafaker
0.16
+
+ org.junit.jupiter
+ junit-jupiter-api
+ RELEASE
+ test
+
+
+ junit
+ junit
+ 4.12
+ test
+
\ No newline at end of file
diff --git a/Kochkaleva/src/main/resources/chromedriver b/Kochkaleva/src/main/resources/chromedriver
new file mode 100644
index 0000000..02ff671
Binary files /dev/null and b/Kochkaleva/src/main/resources/chromedriver differ
diff --git a/Kochkaleva/src/test/java/helpers/ChromeContext.java b/Kochkaleva/src/test/java/helpers/ChromeContext.java
new file mode 100644
index 0000000..23f7d6c
--- /dev/null
+++ b/Kochkaleva/src/test/java/helpers/ChromeContext.java
@@ -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;
+ }
+}
+
diff --git a/Kochkaleva/src/test/java/helpers/Context.java b/Kochkaleva/src/test/java/helpers/Context.java
new file mode 100644
index 0000000..0eb27cf
--- /dev/null
+++ b/Kochkaleva/src/test/java/helpers/Context.java
@@ -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");
+ }
+}
diff --git a/Kochkaleva/src/test/java/pages/Email.java b/Kochkaleva/src/test/java/pages/Email.java
index f414b25..56abc84 100644
--- a/Kochkaleva/src/test/java/pages/Email.java
+++ b/Kochkaleva/src/test/java/pages/Email.java
@@ -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 {
diff --git a/Kochkaleva/src/test/java/pages/Sort.java b/Kochkaleva/src/test/java/pages/Sort.java
index c95bfab..8c1eba3 100644
--- a/Kochkaleva/src/test/java/pages/Sort.java
+++ b/Kochkaleva/src/test/java/pages/Sort.java
@@ -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();
}
diff --git a/Kochkaleva/src/test/java/tests/EmailTests.java b/Kochkaleva/src/test/java/tests/EmailTests.java
index 15c2cc8..8e2dc49 100644
--- a/Kochkaleva/src/test/java/tests/EmailTests.java
+++ b/Kochkaleva/src/test/java/tests/EmailTests.java
@@ -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();
}
}
diff --git a/Kochkaleva/src/test/java/tests/JUnitTestReporter.java b/Kochkaleva/src/test/java/tests/JUnitTestReporter.java
deleted file mode 100644
index 7d3706f..0000000
--- a/Kochkaleva/src/test/java/tests/JUnitTestReporter.java
+++ /dev/null
@@ -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("
");
- junitWriter.write("Test Execution Summary - " + dateFormat.format(date)
- + "
");
-
- }
-
- @AfterClass
- public static void tearDown() throws IOException {
-
- junitWriter.write("");
- 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("
");
- } 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("
");
- } catch (Exception e2) {
- System.out.println(e2.getMessage());
- }
- }
- };
-}
diff --git a/Kochkaleva/src/test/java/tests/NavigationTests.java b/Kochkaleva/src/test/java/tests/NavigationTests.java
index 5d15dba..204a73d 100644
--- a/Kochkaleva/src/test/java/tests/NavigationTests.java
+++ b/Kochkaleva/src/test/java/tests/NavigationTests.java
@@ -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 tabs = driver.getWindowHandles();
- driver.switchTo().window(Iterators.getLast(tabs.iterator()));
- String url = driver.getCurrentUrl();
+ Set 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();
}
}
diff --git a/Kochkaleva/src/test/java/tests/RecylebinTests.java b/Kochkaleva/src/test/java/tests/RecylebinTests.java
index 3f41a22..2493f5c 100644
--- a/Kochkaleva/src/test/java/tests/RecylebinTests.java
+++ b/Kochkaleva/src/test/java/tests/RecylebinTests.java
@@ -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();
- recyclebin.addToCartButtonClick();
- Assert.assertTrue("test passed", true);
+ try {
+ recyclebin.addToCartButtonClick();
+ 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();
}
}
diff --git a/Kochkaleva/src/test/java/tests/RunTests.java b/Kochkaleva/src/test/java/tests/RunTests.java
deleted file mode 100644
index 15232e0..0000000
--- a/Kochkaleva/src/test/java/tests/RunTests.java
+++ /dev/null
@@ -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());
- }
-
-}
diff --git a/Kochkaleva/src/test/java/tests/SortTests.java b/Kochkaleva/src/test/java/tests/SortTests.java
index 9d244d9..48d4ff6 100644
--- a/Kochkaleva/src/test/java/tests/SortTests.java
+++ b/Kochkaleva/src/test/java/tests/SortTests.java
@@ -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);
- sort.sortBySalesClick();
- driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
-
- Assert.assertTrue("test passed", true);
+ context.getDriver().manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
+ try {
+ sort.sortBySalesClick();
+ context.getDriver().manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
+ pass = true;
+ } catch (IllegalStateException e) {
+ e.printStackTrace();
+ }
+ Assert.assertTrue("test passed", pass);
}
@Test
public void checkForSizeFiltering() {
- sort.sizeFilter();
+ boolean pass = false;
+ try {
+ sort.sizeFilter();
+ pass = true;
+ } catch (IllegalStateException e) {
+ e.printStackTrace();
+ }
+ Assert.assertEquals(true, pass);
}
@Test
public void checkForColorFiltering() {
- sort.colorFilter();
+ boolean pass = false;
+ try {
+ sort.colorFilter();
+ pass = true;
+ } catch (IllegalStateException e) {
+ e.printStackTrace();
+ }
+ Assert.assertFalse(!pass);
}
@Test
public void checkForCostFilter() {
- sort.costFilter();
+ 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();
}
}