Skip to content

Commit

Permalink
split tests into different drivers
Browse files Browse the repository at this point in the history
  • Loading branch information
razvanvancea committed Jan 25, 2020
1 parent ec06520 commit e9199c3
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 7 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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`
3 changes: 3 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<groupId>org.example</groupId>
<artifactId>rv-zalenium</artifactId>
<version>1.0-SNAPSHOT</version>
<name>rv-zalenium</name>

<properties>
<testng.version>7.1.0</testng.version>
Expand Down Expand Up @@ -38,6 +39,7 @@
<version>${maven.surfire.version}</version>
</dependency>
</dependencies>

<profiles>
<profile>
<id>parallel</id>
Expand All @@ -57,4 +59,5 @@
</build>
</profile>
</profiles>

</project>
53 changes: 53 additions & 0 deletions src/test/java/GithubTest.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,33 @@
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 SimpleTest {
public class ZaleniumTest {

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);
}

Expand All @@ -56,6 +59,8 @@ public void checkZaleniumDocs(){
Assert.assertTrue(linuxLogo.isDisplayed());
}



@AfterTest
public void tearDown(){
this.driver.quit();
Expand Down
16 changes: 11 additions & 5 deletions testng.xml
Original file line number Diff line number Diff line change
@@ -1,28 +1,34 @@
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="zalenium tests" parallel="tests">

<test name="basic1">
<classes>
<class name="SimpleTest"/>
<class name="ZaleniumTest"/>
<class name="GithubTest"/>
</classes>
</test>

<test name="basic2">
<classes>
<class name="SimpleTest"/>
<class name="ZaleniumTest"/>
</classes>
</test>

<test name="basic3">
<classes>
<class name="SimpleTest"/>
<class name="GithubTest"/>
</classes>
</test>

<test name="basic4">
<classes>
<class name="SimpleTest"/>
<class name="ZaleniumTest"/>
</classes>
</test>

<test name="basic5">
<classes>
<class name="SimpleTest"/>
<class name="GithubTest"/>
</classes>
</test>
</suite>

0 comments on commit e9199c3

Please sign in to comment.