Print

Different methods run in parallel on the same servers with the same browser source code in Java

Different methods run in parallel on the same servers with the same browser source code in Java.

 

Here is the project structure.

SeleniumMasterSearch.Java

 

package com.seleniummaster.runtestsparallel;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.AfterMethod;

public class SeleniumMasterSearch {
  private WebDriver driver;
  private String baseUrl;
 
  @BeforeMethod
  public void Setup() throws MalformedURLException {
    URL hubUrl = new URL("http://localhost:4444/wd/hub");
      DesiredCapabilities capabilities = new DesiredCapabilities();
      capabilities.setBrowserName("firefox");
      capabilities.setPlatform(Platform.WINDOWS);
      driver = new RemoteWebDriver(hubUrl, capabilities);
      baseUrl = "http://seleniummaster.com/sitecontent/index.php/";
      driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
      driver.manage().window().maximize();
  }

  @Test
  public void SearchInformation1() {
    driver.get(baseUrl);
    driver.findElement(By.id("mod-finder-searchword")).clear();
    driver.findElement(By.id("mod-finder-searchword")).sendKeys("Selenium IDE");
    driver.findElement(By.id("mod-finder-searchword")).sendKeys(Keys.ENTER);
    
  }
  
  @Test
  public void SearchInformation2() {
    driver.get(baseUrl);
    driver.findElement(By.id("mod-finder-searchword")).clear();
    driver.findElement(By.id("mod-finder-searchword")).sendKeys("Selenium RC");
    driver.findElement(By.id("mod-finder-searchword")).sendKeys(Keys.ENTER);
    
  }
  @AfterMethod
  public void TearDown() {
    driver.quit();
  }

}

TestNG.xml

<?xml version="1.0" encoding="UTF-8"?>
<suite name="Suite" parallel="methods" thread-count="2">
  <test name="Test">
    <classes>
      <class name="com.seleniummaster.runtestsparallel.SeleniumMasterSearch"/>
    </classes>
  </test> <!-- Test -->
</suite> <!-- Suite -->

Run Tests with TestNG