Selenium WebDriver Parallel Tests Execution Using TestNG - @Parameters

Browser compatibility software testing Is most Important affair for whatever software spider web application as well as by as well as large yous conduct keep to perform browser compatibility testing earlier 1 or 2 days of finally free of software spider web application. In such a form fourth dimension period, yous conduct keep to verify each Important functionality In every browsers suggested past times client. If yous volition go for running your all webdriver tests In each browsers ane past times ane as well as thus It volition bring equally good much fourth dimension to consummate your software tests as well as yous may non consummate It earlier release. In such situation, Running your tests In all required browsers at same time volition helps yous to relieve your fourth dimension efforts. So query Is - Can nosotros run our tests parallel In all required browsers using webdriver software automation testing tool? Answer Is yes.

Before learning how to run webdriver examine parallel inward multiple browsers, You must conduct keep cognition nigh how to run examine In webdriver using TestNg framework. You volition discovery links of TestNG tutorial postal service alongside examples on THIS PAGE. I conduct keep described testng configuration alongside detailed explanation on those links thus read them carefully ane past times one. You tin read webdriver related to a greater extent than tutorials on THIS LINK.

Parallelism In TestNG
You tin configure your testng.xml file In such a agency to run your examine suite or tests or methods In carve upwardly browsers Is known equally parallelism In TestNG. Interviewer tin inquire yous this question. Now allow us await at illustration of parallel examine execution In webdriver using testng. Bellow given illustration volition run the examine In Mozilla Firefox as well as Google chrome browser parallel.

Created Test_Parallel.java shape file for testing application as well as configured testng.xml file to run tests parallel equally shown In bellow given example. In testng.xml file, parallel="tests" Inside <suite> tag volition Instruct TestNG to visit bunch of methods of each <test> tag equally carve upwardly thread. Means If yous wants to run your software examine In 2 dissimilar browsers as well as thus yous require to arrive at ii <test> blocks for each browser Inside testng.xml file as well as Inside each <test> tag block, define ane to a greater extent than tag "parameter" alongside same name(In both <test> block) but alongside dissimilar values. In bellow given testng.xml file, each <test> block has "parameter" tag alongside same advert = browser but dissimilar values(FFX as well as CRM).

In examine case, I conduct keep used @Parameters notation to top parameter In method. Values of this parameter volition hold out feed past times testng.xml file. as well as and thus If status volition banking concern represent that value to arrive at upwardly one's hear which driver to usage for test. This way, illustration testng.xml file volition feed ii values(FFX as well as CRM) In parameter thus It volition opened upwardly Firefox as well as Google chrome browsers as well as run examine In both browsers. (For running examine In google chrome, You require to download chromedriver.exe. VIEW THIS POST to know to a greater extent than how to run webdriver examine In google chrome browser).

Run bellow given examine In your eclipse alongside testng to run across how It runs your examine In 2 browsers at same time.

Test_Parallel.java
package Testng_Pack; import org.junit.Assert;  populace shape Test_Parallel {   mortal  WebDriver driver=null;  @BeforeClass //parameter value volition retrieved from testng.xml file's <parameter> tag.  @Parameters ({"browser"})  populace void setup(String browser){//Method volition top value of parameter.   if (browser.equals("FFX")) {//If value Is FFX as well as thus webdriver volition opened upwardly Firefox Browser.    System.out.println("Test Starts Running In Firefox Browser.");    driver = novel FirefoxDriver();      }else if (browser.equals("CRM")){//If value Is CRM as well as thus webdriver volition opened upwardly chrome Browser.    System.out.println("Test Starts Running In Google chrome.");    System.setProperty("webdriver.chrome.driver",       "D:\\chromedriver_win32_2.3\\chromedriver.exe");    driver = novel ChromeDriver();      }   driver.manage().window().maximize();   driver.get(" ");    }   //Both bellow given tests volition hold out executed In both browsers.  @Test  populace void verify_title(){       String championship = driver.getTitle();    Assert.assertEquals("Only Testing: LogIn", title);    System.out.println("Title Is Fine.");     }   @Test  populace void verify_message(){     driver.findElement(By.xpath("//input[@name='userid']")).sendKeys("UID1");   driver.findElement(By.xpath("//input[@type='password']")).sendKeys("pass1");   driver.findElement(By.xpath("//input[@value='Login']")).click();   String warning = driver.switchTo().alert().getText();   driver.switchTo().alert().accept();   Assert.assertEquals("UserId Is : UID1  Password Is : pass1", alert);   System.out.println("Alert Is Fine.");    }   @AfterClass   populace void closebrowser(){    driver.quit();    } }

testng.xml
<suite name="webDriver" parallel="tests">    <test name="Test In FireFox" >     <parameter name="browser" value="FFX" />     <classes>       <class name="Testng_Pack.Test_Parallel" />     </classes>   </test>    <test name="Test In Google Chrome" >     <parameter name="browser" value="CRM"></parameter>     <classes>       <class name="Testng_Pack.Test_Parallel"></class>     </classes>   </test>  </suite>

If yous wants to run your software examine In ane to a greater extent than browser as well as thus yous require to arrive at novel <test> tag block inward testng.xml file as well as railroad train roughly other parameter value as well as and thus pose ane to a greater extent than if else status inward shape file to banking concern represent as well as run your test.

This agency yous tin your examine parallel In multiple browsers at same fourth dimension to cut your fourth dimension efforts.
More interesting articles here :Generation Enggelmundus Internet Marketing Tool here :Zeageat IM

http://www.software-testing-tutorials-automation.com/
Post a Comment (0)
Previous Post Next Post