From e9199c33a1bc5c4ec07bcbf445b29bdc0090260a Mon Sep 17 00:00:00 2001 From: razvanvancea Date: Sun, 26 Jan 2020 01:57:44 +0200 Subject: [PATCH] split tests into different drivers --- README.md | 7 +++ pom.xml | 3 ++ src/test/java/GithubTest.java | 53 +++++++++++++++++++ .../{SimpleTest.java => ZaleniumTest.java} | 9 +++- testng.xml | 16 ++++-- 5 files changed, 81 insertions(+), 7 deletions(-) create mode 100644 README.md create mode 100644 src/test/java/GithubTest.java rename src/test/java/{SimpleTest.java => ZaleniumTest.java} (98%) diff --git a/README.md b/README.md new file mode 100644 index 0000000..4bc8d0e --- /dev/null +++ b/README.md @@ -0,0 +1,7 @@ +#Java, Selenium, RemoteWebDriver, Parallel Execution, TestNG, Maven Profiles @RV + +This project shows the core concepts of RemoteWebDriver, TestNG, Parallel execution and Maven profiles. + +It can be easily integrated with **Selenium Grid** or **Docker (Zalenium)**. + +**CLI execution:** `mvn clean test -Pparallel` diff --git a/pom.xml b/pom.xml index 82c8beb..7bc319a 100644 --- a/pom.xml +++ b/pom.xml @@ -7,6 +7,7 @@ org.example rv-zalenium 1.0-SNAPSHOT + rv-zalenium 7.1.0 @@ -38,6 +39,7 @@ ${maven.surfire.version} + parallel @@ -57,4 +59,5 @@ + diff --git a/src/test/java/GithubTest.java b/src/test/java/GithubTest.java new file mode 100644 index 0000000..d6cfe0a --- /dev/null +++ b/src/test/java/GithubTest.java @@ -0,0 +1,53 @@ +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.remote.DesiredCapabilities; +import org.openqa.selenium.remote.RemoteWebDriver; +import org.testng.Assert; +import org.testng.ITestContext; +import org.testng.annotations.AfterTest; +import org.testng.annotations.BeforeTest; +import org.testng.annotations.Test; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.concurrent.TimeUnit; + +/** + * @author Razvan Vancea + */ +public class GithubTest { + + private WebDriver driver; + + @BeforeTest + public void setupDriver(ITestContext ctx){ + DesiredCapabilities cap; + cap = DesiredCapabilities.chrome(); + + String host = "http://localhost:4444/wd/hub"; + + String testName = ctx.getCurrentXmlTest().getName(); + cap.setCapability("name", testName); + + try { + this.driver = new RemoteWebDriver(new URL(host), cap); + } catch (MalformedURLException e){ + e.printStackTrace(); + } + + driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS); + } + + @Test + public void assertGithubRepoTitle(){ + driver.get("https://github.com/razvanvancea"); + + String currentTitle = driver.getTitle(); + String expectedTitle = "razvanvancea (RV) ยท GitHub"; + + Assert.assertEquals(currentTitle, expectedTitle); + } + + @AfterTest + public void tearDown(){ + this.driver.quit(); + } +} diff --git a/src/test/java/SimpleTest.java b/src/test/java/ZaleniumTest.java similarity index 98% rename from src/test/java/SimpleTest.java rename to src/test/java/ZaleniumTest.java index 47e490e..8109013 100644 --- a/src/test/java/SimpleTest.java +++ b/src/test/java/ZaleniumTest.java @@ -8,7 +8,6 @@ import org.testng.annotations.AfterTest; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; - import java.net.MalformedURLException; import java.net.URL; import java.util.concurrent.TimeUnit; @@ -16,7 +15,7 @@ /** * @author Razvan Vancea */ -public class SimpleTest { +public class ZaleniumTest { private WebDriver driver; @@ -24,14 +23,18 @@ public class SimpleTest { public void setupDriver(ITestContext ctx){ DesiredCapabilities cap; cap = DesiredCapabilities.chrome(); + String host = "http://localhost:4444/wd/hub"; + String testName = ctx.getCurrentXmlTest().getName(); cap.setCapability("name", testName); + try { this.driver = new RemoteWebDriver(new URL(host), cap); } catch (MalformedURLException e){ e.printStackTrace(); } + driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS); } @@ -56,6 +59,8 @@ public void checkZaleniumDocs(){ Assert.assertTrue(linuxLogo.isDisplayed()); } + + @AfterTest public void tearDown(){ this.driver.quit(); diff --git a/testng.xml b/testng.xml index 8bc6858..8e10a9f 100644 --- a/testng.xml +++ b/testng.xml @@ -1,28 +1,34 @@ + - + + + - + + - + + - + + - +