Sunday, September 2, 2018

How To Purpose Selenium Grid Two To Piece Of Job Webdriver Examination Cases Inward Parallel

| Sunday, September 2, 2018
Main payoff of selenium grid is nosotros tin run webdriver software exam cases inwards parallel using selenium grid 2 environment to reduce software exam execution time equally described inwards THIS POST. Also It helps us to perform compatibility testing equally it is supporting multiple browsers too. Earlier nosotros accept configured selenium grid two hub inwards THIS POST together with selenium grid nodes inwards THIS POST inwards simply unmarried machine. Now lets endeavor to role this environs to execute webdriver software automation exam cases inwards parallel.

Prerequisite : Selenium grid hub together with node should live on running equally described inwards previous steps.

I accept created uncomplicated software automation exam to execute it parallel inwards multiple browsers using selenium grid. It volition launch 3 browsers (Mozilla firefox, google chrome together with IE) parallel together with and then execute same software automation exam within each browser.

Note : Please withdraw mesh explorer related code materials from bellow given script if confront whatever related mistake equally it is non really stable amongst selenium grid.

Create bellow laissez passer exam inwards your eclipse projection nether Grid package.

SeGridTest.java
package Grid;  import static org.testng.Assert.fail;  import java.net.MalformedURLException; import java.net.URL; import java.util.concurrent.TimeUnit;  import org.openqa.selenium.By; import org.openqa.selenium.Capabilities; import org.openqa.selenium.WebDriver; import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.remote.RemoteWebDriver; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; import org.testng.annotations.AfterTest; import org.testng.annotations.BeforeTest; import org.testng.annotations.Parameters; import org.testng.annotations.Test;  populace cast SeGridTest {  WebDriver driver = null;  mortal StringBuffer verificationErrors = novel StringBuffer();   // Pass plateform, browser together with url parameters to launch browser together with URL inwards given plateform.  @Parameters({ "platform", "browser", "url" })  @BeforeTest(alwaysRun = true)  populace void setup(String platform, String browser, String url) throws MalformedURLException {   DesiredCapabilities caps = novel DesiredCapabilities();   // Set Platforms based on parameter received from testng.xml.   caps.setPlatform(org.openqa.selenium.Platform.WINDOWS);    // Set browser capability based on parameter received from testng.xml.   if (browser.equalsIgnoreCase("Internet Explorer"))    caps = DesiredCapabilities.internetExplorer();   if (browser.equalsIgnoreCase("Firefox"))    caps = DesiredCapabilities.firefox();   if (browser.equalsIgnoreCase("chrome"))    caps = DesiredCapabilities.chrome();    // Open browser on grid node.   driver = novel RemoteWebDriver(new URL("http://localhost:4444/wd/hub"),caps);   driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);   driver.manage().window().maximize();   // Open URL of Application   driver.get(url);  }   // Simple exam method to execute.  @Test(description = "Wait for push enabled")  populace void waitForButtonEnabled() throws InterruptedException {   WebDriverWait hold off = novel WebDriverWait(driver, 15);   wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("#submitButton")));   driver.findElement(By.xpath("//input[@id='submitButton']")).click();  }   // Simple exam method to execute.  @Test(description = "Wait for push enabled", dependsOnMethods = { "waitForButtonEnabled" })  populace void testCalc() throws InterruptedException {   driver.navigate().to("aa/search?q=what-is-selenium-grid-2-when-to-use-grid");   driver.findElement(By.xpath("//input[@id='2']")).click();   driver.findElement(By.xpath("//input[@id='plus']")).click();   driver.findElement(By.xpath("//input[@id='5']")).click();   driver.findElement(By.xpath("//input[@id='equals']")).click();   String trial = driver.findElement(By.xpath("//input[@id='Resultbox']")).getAttribute("value");    // Get Browser elevate together with version.   Capabilities caps = ((RemoteWebDriver) driver).getCapabilities();   String browserName = caps.getBrowserName();   String browserVersion = caps.getVersion();    // Get OS name.   String bone = System.getProperty("os.name").toLowerCase();    // Print exam trial amongst browser together with OS version detail.   System.out.println("OS = " + bone + ", Browser = " + browserName + " "+ browserVersion + " Test Result = " + result);  }   @AfterTest  populace void afterTest() {   // Close the browser   driver.quit();   String verificationErrorString = verificationErrors.toString();   if (!"".equals(verificationErrorString)) {    fail(verificationErrorString);   }  } }

If you lot remember, We accept used parallel inwards testng.xml file to execute software automation tests inwards parallel inwards selenium webdriver equally described inwards THIS POST. We volition role same matter hither but using selenium grid.

You tin see, We accept used parameters (plateform, browser together with url) amongst setup method. All these parameters volition live on served from testnx.xml file equally bellow. We accept configured 3 exam inwards bellow given xml file amongst unlike browser parameter to run exam inwards unlike browsers. Create bellow given testng.xml file nether your projection together with run it.

testng.xml
<!--Set thread-count = 3 to execute exam parallel inwards 3 max browsers at at time. You tin growth it--> <suite name="Parallel Tests" verbose="1" thread-count="3" parallel="tests">  <tests>      <!--Set exam parameters to execute exam inwards IE browser on windows plateform.-->   <test name="Windows+IE Test" >    <parameters>     <parameter name="platform" value="Windows" />     <parameter name="browser" value="Internet Explorer" />     <parameter name="url" value="aa/search?q=what-is-selenium-grid-2-when-to-use-grid" />    </parameters>    <classes>     <class name="Grid.SeGridTest" />    </classes>   </test>   <!--Set exam parameters to execute exam inwards Firefox browser on windows plateform.-->   <test name="Windows+Firefox Test" >    <parameters>     <parameter name="platform" value="Windows" />     <parameter name="browser" value="Firefox" />     <parameter name="url" value="aa/search?q=what-is-selenium-grid-2-when-to-use-grid" />    </parameters>    <classes>     <class name="Grid.SeGridTest" />    </classes>   </test>    <!--Set exam parameters to execute exam inwards chrome browser on windows plateform.-->   <test name="Windows+chrome Test" >    <parameters>     <parameter name="platform" value="Windows" />     <parameter name="browser" value="chrome" />     <parameter name="url" value="aa/search?q=what-is-selenium-grid-2-when-to-use-grid" />    </parameters>    <classes>     <class name="Grid.SeGridTest" />    </classes>   </test>     </tests> </suite>

Now, execute inwards a higher house testng.xml file together with disclose exam execution process. It volition  launch 3 browsers parallel together with and then execute tests inwards all 3 browsers. At the halt of exam execution, It volition impress trial inwards console equally bellow.

OS = windows 7, Browser = chrome 43.0.2357.132 Test Result = vii OS = windows 7, Browser = mesh explorer 8 Test Result = vii OS = windows 7, Browser = firefox 38.0.5 Test Result = 7

Testng trial volition looks similar bellow.


This is the agency to execute selenium webdriver software automation test inwards parallel multiple browsers using selenium grid 2 to perform compatibility testing.

Related Posts