├── .gitattributes ├── .gitignore ├── README.md ├── TestNG.xml ├── pom.xml └── src └── test └── java ├── BaseTest.java ├── CapabilityFactory.java ├── FirstTest.java ├── OptionsManager.java └── SecondTest.java /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm 2 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 3 | 4 | # User-specific stuff 5 | .idea/**/workspace.xml 6 | .idea/**/tasks.xml 7 | .idea/**/usage.statistics.xml 8 | .idea/**/dictionaries 9 | .idea/**/shelf 10 | 11 | # Generated files 12 | .idea/**/contentModel.xml 13 | 14 | # Sensitive or high-churn files 15 | .idea/**/dataSources/ 16 | .idea/**/dataSources.ids 17 | .idea/**/dataSources.local.xml 18 | .idea/**/sqlDataSources.xml 19 | .idea/**/dynamic.xml 20 | .idea/**/uiDesigner.xml 21 | .idea/**/dbnavigator.xml 22 | 23 | # Gradle 24 | .idea/**/gradle.xml 25 | .idea/**/libraries 26 | 27 | # Gradle and Maven with auto-import 28 | # When using Gradle or Maven with auto-import, you should exclude module files, 29 | # since they will be recreated, and may cause churn. Uncomment if using 30 | # auto-import. 31 | # .idea/modules.xml 32 | # .idea/*.iml 33 | # .idea/modules 34 | *.iml 35 | # *.ipr 36 | 37 | # CMake 38 | cmake-build-*/ 39 | 40 | # Mongo Explorer plugin 41 | .idea/**/mongoSettings.xml 42 | 43 | # File-based project format 44 | *.iws 45 | 46 | # IntelliJ 47 | out/ 48 | 49 | # mpeltonen/sbt-idea plugin 50 | .idea_modules/ 51 | 52 | # JIRA plugin 53 | atlassian-ide-plugin.xml 54 | 55 | # Cursive Clojure plugin 56 | .idea/replstate.xml 57 | 58 | # Crashlytics plugin (for Android Studio and IntelliJ) 59 | com_crashlytics_export_strings.xml 60 | crashlytics.properties 61 | crashlytics-build.properties 62 | fabric.properties 63 | 64 | # Editor-based Rest Client 65 | .idea/httpRequests 66 | 67 | # Android studio 3.1+ serialized cache file -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # TestNGParallel 2 | TestNG Parallel Test Execution 3 | 4 | Article Links: https://www.swtestacademy.com/selenium-parallel-tests-grid-testng/ 5 | https://www.swtestacademy.com/local-parallel-testing-selenium/ 6 | -------------------------------------------------------------------------------- /TestNG.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | TestNGParallel 8 | TestNGParallel 9 | 1.0-SNAPSHOT 10 | 11 | 12 | 13 | org.apache.maven.plugins 14 | maven-compiler-plugin 15 | 16 | 1.8 17 | 1.8 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | org.seleniumhq.selenium 26 | selenium-java 27 | 3.141.59 28 | 29 | 30 | 31 | org.testng 32 | testng 33 | 7.1.0 34 | 35 | 36 | org.projectlombok 37 | lombok 38 | 1.18.12 39 | test 40 | 41 | 42 | -------------------------------------------------------------------------------- /src/test/java/BaseTest.java: -------------------------------------------------------------------------------- 1 | import java.net.MalformedURLException; 2 | import java.net.URL; 3 | import org.openqa.selenium.WebDriver; 4 | import org.openqa.selenium.remote.RemoteWebDriver; 5 | import org.testng.annotations.AfterClass; 6 | import org.testng.annotations.AfterMethod; 7 | import org.testng.annotations.BeforeMethod; 8 | import org.testng.annotations.Parameters; 9 | 10 | public class BaseTest { 11 | 12 | //Declare ThreadLocal Driver (ThreadLocalMap) for ThreadSafe Tests 13 | protected static ThreadLocal driver = new ThreadLocal<>(); 14 | public CapabilityFactory capabilityFactory = new CapabilityFactory(); 15 | 16 | @BeforeMethod 17 | @Parameters(value={"browser"}) 18 | public void setup (String browser) throws MalformedURLException { 19 | //Set Browser to ThreadLocalMap 20 | driver.set(new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilityFactory.getCapabilities(browser))); 21 | } 22 | 23 | public WebDriver getDriver() { 24 | //Get driver from ThreadLocalMap 25 | return driver.get(); 26 | } 27 | 28 | @AfterMethod 29 | public void tearDown() { 30 | getDriver().quit(); 31 | } 32 | 33 | @AfterClass void terminate () { 34 | //Remove the ThreadLocalMap element 35 | driver.remove(); 36 | } 37 | } -------------------------------------------------------------------------------- /src/test/java/CapabilityFactory.java: -------------------------------------------------------------------------------- 1 | import org.openqa.selenium.Capabilities; 2 | 3 | public class CapabilityFactory { 4 | public Capabilities capabilities; 5 | 6 | public Capabilities getCapabilities (String browser) { 7 | if (browser.equals("firefox")) 8 | capabilities = OptionsManager.getFirefoxOptions(); 9 | else 10 | capabilities = OptionsManager.getChromeOptions(); 11 | return capabilities; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/test/java/FirstTest.java: -------------------------------------------------------------------------------- 1 | import org.testng.Assert; 2 | import org.testng.annotations.Test; 3 | 4 | /** 5 | * Created by ONUR on 03.12.2016. 6 | */ 7 | public class FirstTest extends BaseTest { 8 | 9 | @Test 10 | public void GOOGLE1() { 11 | System.out.println("Google1 Test Started! " + "Thread Id: " + Thread.currentThread().getId()); 12 | getDriver().navigate().to("http://www.google.com"); 13 | System.out.println("Google1 Test's Page title is: " + getDriver().getTitle() +" " + "Thread Id: " + Thread.currentThread().getId()); 14 | Assert.assertEquals(getDriver().getTitle(), "Google"); 15 | System.out.println("Google1 Test Ended! " + "Thread Id: " + Thread.currentThread().getId()); 16 | } 17 | 18 | @Test 19 | public void GOOGLE2() { 20 | System.out.println("Google2 Test Started! " + "Thread Id: " + Thread.currentThread().getId()); 21 | getDriver().navigate().to("http://www.google.com"); 22 | System.out.println("Google2 Test's Page title is: " + getDriver().getTitle() +" " + "Thread Id: " + Thread.currentThread().getId()); 23 | Assert.assertEquals(getDriver().getTitle(), "Google"); 24 | System.out.println("Google2 Test Ended! " + "Thread Id: " + Thread.currentThread().getId()); 25 | } 26 | 27 | @Test 28 | public void GOOGLE3() { 29 | System.out.println("Google3 Test Started! " + "Thread Id: " + Thread.currentThread().getId()); 30 | getDriver().navigate().to("http://www.google.com"); 31 | System.out.println("Google3 Test's Page title is: " + getDriver().getTitle() +" " + "Thread Id: " + Thread.currentThread().getId()); 32 | Assert.assertEquals(getDriver().getTitle(), "Google"); 33 | System.out.println("Google3 Test Ended! " + "Thread Id: " + Thread.currentThread().getId()); 34 | } 35 | 36 | @Test 37 | public void GOOGLE5() { 38 | System.out.println("Google5 Test Started! " + "Thread Id: " + Thread.currentThread().getId()); 39 | getDriver().navigate().to("http://www.google.com"); 40 | System.out.println("Google5 Test's Page title is: " + getDriver().getTitle() +" " + "Thread Id: " + Thread.currentThread().getId()); 41 | Assert.assertEquals(getDriver().getTitle(), "Google"); 42 | System.out.println("Google5 Test Ended! " + "Thread Id: " + Thread.currentThread().getId()); 43 | } 44 | 45 | @Test 46 | public void GOOGLE6() { 47 | System.out.println("Google6 Test Started! " + "Thread Id: " + Thread.currentThread().getId()); 48 | getDriver().navigate().to("http://www.google.com"); 49 | System.out.println("Google6 Test's Page title is: " + getDriver().getTitle() +" " + "Thread Id: " + Thread.currentThread().getId()); 50 | Assert.assertEquals(getDriver().getTitle(), "Google"); 51 | System.out.println("Google6 Test Ended! " + "Thread Id: " + Thread.currentThread().getId()); 52 | } 53 | 54 | @Test 55 | public void GOOGLE7() { 56 | System.out.println("Google7 Test Started! " + "Thread Id: " + Thread.currentThread().getId()); 57 | getDriver().navigate().to("http://www.google.com"); 58 | System.out.println("Google7 Test's Page title is: " + getDriver().getTitle() +" " + "Thread Id: " + Thread.currentThread().getId()); 59 | Assert.assertEquals(getDriver().getTitle(), "Google"); 60 | System.out.println("Google7 Test Ended! " + "Thread Id: " + Thread.currentThread().getId()); 61 | } 62 | 63 | @Test 64 | public void GOOGLE8() { 65 | System.out.println("Google8 Test Started! " + "Thread Id: " + Thread.currentThread().getId()); 66 | getDriver().navigate().to("http://www.google.com"); 67 | System.out.println("Google8 Test's Page title is: " + getDriver().getTitle() +" " + "Thread Id: " + Thread.currentThread().getId()); 68 | Assert.assertEquals(getDriver().getTitle(), "Google"); 69 | System.out.println("Google8 Test Ended! " + "Thread Id: " + Thread.currentThread().getId()); 70 | } 71 | 72 | @Test 73 | public void GOOGLE9() { 74 | System.out.println("Google9 Test Started! " + "Thread Id: " + Thread.currentThread().getId()); 75 | getDriver().navigate().to("http://www.google.com"); 76 | System.out.println("Google9 Test's Page title is: " + getDriver().getTitle() +" " + "Thread Id: " + Thread.currentThread().getId()); 77 | Assert.assertEquals(getDriver().getTitle(), "Google"); 78 | System.out.println("Google9 Test Ended! " + "Thread Id: " + Thread.currentThread().getId()); 79 | } 80 | } -------------------------------------------------------------------------------- /src/test/java/OptionsManager.java: -------------------------------------------------------------------------------- 1 | import org.openqa.selenium.chrome.ChromeOptions; 2 | import org.openqa.selenium.firefox.FirefoxDriver; 3 | import org.openqa.selenium.firefox.FirefoxOptions; 4 | import org.openqa.selenium.firefox.FirefoxProfile; 5 | 6 | public class OptionsManager { 7 | 8 | //Get Chrome Options 9 | public static ChromeOptions getChromeOptions() { 10 | ChromeOptions options = new ChromeOptions(); 11 | options.addArguments("--start-maximized"); 12 | options.addArguments("--ignore-certificate-errors"); 13 | options.addArguments("--disable-popup-blocking"); 14 | //options.addArguments("--incognito"); 15 | return options; 16 | /*ChromeDriverService service = new ChromeDriverService.Builder() 17 | .usingAnyFreePort() 18 | .build(); 19 | ChromeDriver driver = new ChromeDriver(service, options);*/ 20 | } 21 | 22 | //Get Firefox Options 23 | public static FirefoxOptions getFirefoxOptions () { 24 | FirefoxOptions options = new FirefoxOptions(); 25 | FirefoxProfile profile = new FirefoxProfile(); 26 | //Accept Untrusted Certificates 27 | profile.setAcceptUntrustedCertificates(true); 28 | profile.setAssumeUntrustedCertificateIssuer(false); 29 | //Use No Proxy Settings 30 | profile.setPreference("network.proxy.type", 0); 31 | //Set Firefox profile to capabilities 32 | options.setCapability(FirefoxDriver.PROFILE, profile); 33 | return options; 34 | } 35 | } -------------------------------------------------------------------------------- /src/test/java/SecondTest.java: -------------------------------------------------------------------------------- 1 | import org.testng.Assert; 2 | import org.testng.annotations.Test; 3 | 4 | /** 5 | * Created by ONUR on 03.12.2016. 6 | */ 7 | public class SecondTest extends BaseTest { 8 | 9 | @Test 10 | public void GOOGLE4() { 11 | System.out.println("Google4 Test Started! " + "Thread Id: " + Thread.currentThread().getId()); 12 | getDriver().navigate().to("http://www.google.com"); 13 | System.out.println("Google4 Test's Page title is: " + getDriver().getTitle() +" " + "Thread Id: "+ Thread.currentThread().getId()); 14 | Assert.assertEquals(getDriver().getTitle(), "Google"); 15 | System.out.println("Google4 Test Ended! " + "Thread Id: " + Thread.currentThread().getId()); 16 | } 17 | 18 | @Test 19 | public void YANDEX() { 20 | System.out.println("Yandex Test Started! " + "Thread Id: " + Thread.currentThread().getId()); 21 | getDriver().navigate().to("http://www.yandex.com"); 22 | System.out.println("Yandex Test's Page title is: " + getDriver().getTitle() +" " + "Thread Id: " + Thread.currentThread().getId()); 23 | Assert.assertEquals(getDriver().getTitle(), "Yandex"); 24 | System.out.println("Yandex Test Ended! " + "Thread Id: " + Thread.currentThread().getId()); 25 | } 26 | } --------------------------------------------------------------------------------