How to execute Selenium WebDriver test cases parallel in multiple Browser using TestNG ?

Pre-Requisite:
Read these article before proceeding with this post:
Configuring Selenium Webdriver in Eclipse with TestNG plugin installation.

I suppose that you are familiar with how to add jar files to your project and How to add any class, folder and XML.

Most of the time we find it hard to do compatibility testing of certain web-page on various Browsers and it takes a big chunk of time for its execution on various set of Browser and also on various instance of Browser.

TestNG has provided us with an option through its Parameter feature, through which we could run the same test script written in Selenium WebDriver parallel to all installed Browser on our system?

Scripts and Steps to execute Script 

1- Go to your Eclipse Project –> Right Click on Project –> Click On New–> others–> Pop up would appear–> Click on XML –> Select XML File –> Click on Next –> New XML File pop up would appear–> Enter the name of XML and click on Finish

2- Your XML file would appear like this

  <?xml version=“1.0” encoding=“UTF-8”?>
<suite name=“Suite_2” parallel=“tests”>
<test name=“Funaction Test Cases “>
<parameter name=“browser” value=“Chrome” />
<classes>
<class name=“com.testng.Test” />
</classes>
</test> <!– Test –>

<test name=“Funaction Test Cases_Firefox “>
<parameter name=“browser” value=“Firefox” />
<classes>
<class name=“com.testng.Test” />
</classes>
</test>

<test name=“Funaction Test Cases_IE “>
<parameter name=“browser” value=“IE” />
<classes>
<class name=“com.testng.Test” />
</classes>
</test>

</suite> <!– Suite –>

Download XML file from here
Now understand the tags of XML that I have marked Bold in XML file
Parallel:  This is being used to run tests parallelly in different browser
suite name: This is the name of your test suit
test name : kind of test cases (you may give a name like Regression, Sanity,Smoke, or anything that make you to make better test execution ) like I have given name to this test case as Generic test
Classes: name of class that you want to add in this test execution
Most important one is

<parameter name="browser" value="FF"></parameter>

Here browser has been taken as a parameter name(you can give a name as per your choice) and FF for Firefox, IE for Internet Explorer, and Chrome for Chrome Browser are the various values given to this browser parameter would be called in our code.


3- Now its time to understand how you have to use the parameter name in the Java program. Since parameter is defined for Browsers. Since you are trying to use the TestNG framework we would  write two function first one to launch Browser and Second one to close Browser

Create new java class in your Java Project
Steps to create a new java class:: right-click on project ||New|| Click on Class||Enter the name of the class and Hit on the finish.
The name of my java class is Browser.java so just create one class with the name Browser and copy and paste the following code in eclipse.

But before moving ahead i would suggest to go through following two post

1- Launching Chrome Browser
2- CHALLENGES TO RUN SELENIUM WEBDRIVER SCRIPTS IN IE BROWSER

package com.testng;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Parameters;
//import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeMethod;

public class Browser {

WebDriver driver;
@BeforeMethod   /* The annotated method will be run before all tests in this suite have run */
//browser is the name of parameter that we have used in xml
@Parameters("browser") /* this annotation is used to insert parameter in test*/
public void openBroswer(String browser){

/*Comparing the value of parameter name if this is FF then It would launch Firefox and script that would run is as follows */
        if(b.equalsIgnoreCase("Chrome"))
        {
            System.setProperty("webdriver.chrome.driver", "path of chromedriver.exe");
            
            driver = new ChromeDriver();
            
        } else if (b.equalsIgnoreCase("FF"))
        {
            driver = new FirefoxDriver();
        } else if (b.equalsIgnoreCase("IE"))
        {
System.setProperty("webdriver.ie.driver", "path of IEDriver.exe");
            
            driver = new InternetExplorerDriver();
        }
    }

@AfterMethod /* this annotation would run once test script execution would complete*/

public void closeBrowser()
{

try{
driver.wait(15000);

}

catch(Exception e)
{}
driver.close();
driver.quit();
}
}

4- Since we have created Browser class in which we have used the parameter defined in XML, Now we should create one more class that is our Test class, This class would inherit Browser class for launching Browser before executing scripts under @Test annotation and for Closing Browser once execution of scipt under @Test annotation get completed.
here I have given the name of this class is Test

package com.testng;

import org.openqa.selenium.By;
import org.testng.Reporter;
import org.testng.annotations.Test;

@Test

public class Test extends Browser{

public void test(){
/* in this test we are searching selenium in Google and clicking on first link in Google Result*/

driver.get("http://www.google.com");

driver.findElement(By.id("lst-ib")).sendKeys("selenium");
driver.findElement(By.id("lst-ib").sendKeys(Keys.ENTER);


//driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
driver.findElement(By.xpath("//*[@id='rso']/div[1]/div/div/h3/a")).click();
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}

}

5- Now its time to execute Test-Case
Steps:
Right Click on Test.java file and –> Run As –> Run Confinguration –> In pop up Go Testng –> Right Click on Testng and Click on New –> Give name to your Run Configuration, Browser Class and select your Xml just by Browsing in front of Suit –> hit on Finish and this would run your test

TestNg-ConfigHope this post would help you to run your selenium test case parallel.

Friends I have tried these scripts on my system and are running well so if you find any missing bracket or braces missing then please do the correction on your own but Script is correct.

Dwarika Dhish Mishra

My name is Dwarika Dhish Mishra, its just my name and I am trying to bring the worth of my name in to actions and wants to be the solution not the problem. I believe in spreading knowledge and happiness. More over I am fun loving person and like travelling a lot. By nature I am a tester and a solution maker. I believe in the tag line of http://ted.org “Idea worth spreading” . For the same, I have created this blog to bring more and more learning to tester fraternity through day to day learning in professional and personal life. All contents are the part of my learning and so are available for all..So please spread the contents as much as you can at your end so that it could reach to every needful people in testing fraternity. I am pretty happy that more and more people are showing interest to become the part your Abode QA blog and I think this is good sign for us all because more and more content would be before you to read and to cherish. You may write or call me at my Email id: dwarika1987@gmail.com Cell: 9999978609

You may also like...

96 Responses

  1. fariza says:

    Hi, what does it mean by “select your Xml just by Browsing in front of Suit”?
    Note: I’m a total newbie.

  2. Shailesh says:

    I read the your blog but could not get XML file as you mentioned in –
    Scripts and Steps to execute Script
    1st Time Could you help me

    I am using Eclipse Indigo Version.

    Thanks,
    Shailesh

    • Hi Shailesh
      I have just mention the line of code that would be included in xml for parallel execution of test in Browsers, In this post I have not attached any xml file but the lines of xnl code.So please go again to the heading
      Scripts and Steps to execute Script.

      • Shailesh says:

        Ok
        – Now I get my XML but’s it name is “testng-customesuite.xml” is there any difference between “testng.xml” and “testng-customesuite.xml”. It is present in Temp Folder i.e. C:Document and SettingsshaileshLocal SettingsTempTestng-eclipse 15466544(foldername)testng-customesuite.xml

        – I copied that file into my project because there is no way(or does not found) in eclipse(indo version) to view the XML. But your mentioned way does not work for me. 1- Go to your Eclipse Project –> Right Click on Project –> Click On New–> others–> Pop up would appear–> Click on XML –> Select XML File –> Click on Next –> New XML File pop up would appear–> Enter the name of XML and click on Finish

        – Also in Code
        if(browser.equalsIgnoreCase(“FF”))
        {
        System.out.println(“Firefox driver would be used”);
        driver = new FirefoxDriver();
        }

        It displays error as browser cannot be resolved.

        Right now I able to run Parallel test Case by following your step in one browser. Thanks.

        But Right now I not able to run test case into two different browser.

      • Shailesh says:

        Hi Dwarika,

        My Question is not how to luach other browser like Chrome or IE Or Firefox.

        My Question – In parallel testing I not able to lauch the Test Case in Different Browser like One in Chrome and Other is IE. Because it displays error at –

        if(browser.equalsIgnoreCase(“FF”))
        {
        System.out.println(“Firefox driver would be used”);
        driver = new FirefoxDriver();
        }

        It displays error as “browser”[in browser.equalsIgnoreCase(“FF”)] cannot be resolved.

        I can also send you mail of code if needed please give your mail id.

        Thanks for Prompt Reply!

        Shailesh.

      • Shailesh says:

        Hi Dwarka,

        Today I read your blog for Data Driven – http://abodeqa.com/tag/junitor-testng-data-driven-with-webdriver/

        But in there you can not mention how to write to Excel of Result of Execution? I think that is important for reader like me. Thanks Buddy 🙂

        Regards,
        Shailesh

        • Most welcome, As per your suggestion I will put one article on writing data in Excel file..So just wait for my next post,

          • Sachin says:

            Hi Sir I’m trying to run test suite (tsestNG). But, when i run it’s opening multiple browser windows and then run one by one (Suppose in test suite have a 5 classes its open 5 browser windows and then run one by one). I want to run one by one but, after one class execution is complete then browser windows should close and then fresh window should open and run………
            my xml file is

          • remove parallel=”methods” or parallel=”tests” or parallel=”classes” which ever you have used in your suite

      • Shailesh says:

        Hi Dwarika,

        I able to solve the Problem by changing just –
        @Parameter ({“browser”})
        //My setup method.

        But Right Now My test cases run Sequentially one after another. I followed all your step. WHY?

        My TestNG version – 6.8

        Thanks,
        Shailesh

        • Might be this is happening because each Browser takes different time to be launched through WebDriver so might be you would be getting it like sequentially.

        • mohanapriya.v says:

          hai i also have same prblm pls snd me how to do compatibility testing on browser using selenium ..i will install testNG also but i got error msg.

  3. Shailesh says:

    Waiting for Reply Sir, its urgent.

    it might look like silly question but it important to me

  4. Palak says:

    Hi

    i am unable to browse the class while doing:
    Right Click on Test.java file and –> Run As –> Run Confinguration –> In pop up Go Testng –> Right Click on Testng and Click on New –> Give name to your Run Configuration, Browser Class and select your Xml just by Browsing in front of Suit –> hit on Finish and this would run your test

    And therefore unable to run the test.
    Please help!

  5. Purush says:

    Great Article and easy to follow…. Thanks a lot 🙂

  6. Imran says:

    Hey Dwarika Dhish Mishra,
    Please tell me to configure in eclipse Helios TestNG with Grid pls provide me steps.

    Thanks !!
    In Advance

  7. Sai Ram says:

    Hello
    Primarily thank you for this article.
    I have stuck up with an issue, hope that will be cleared with this blog.
    My Issue is i am running my jbehave (maven + selenium) stories in the browser i specified,
    But i need to run in multiple browsers with out switching.. means first it has to comple story in one browser and next with another browser.. Can you plzz help me out..
    T

    • sathya says:

      u can run multiple xml files within 1 xml file (testng). there is tag called . So create one file for each browser type, combine all of them into testngMaster.xml. Run testngMaster.xml, hope this helps

  8. prashant says:

    [TestNG] Running:
    C:UsersPAppDataLocalTemptestng-eclipse-1762005051testng-customsuite.xml

    FAILED CONFIGURATION: @BeforeMethod openBroswer
    org.testng.TestNGException:
    Parameter ‘browser’ is required by @Configuration on method openBroswer but has not been marked @Optional or defined
    in C:UsersPAppDataLocalTemptestng-eclipse-1762005051testng-customsuite.xml
    at org.testng.internal.Parameters.createParameters(Parameters.java:155)
    at org.testng.internal.Parameters.createParameters(Parameters.java:358)
    at org.testng.internal.Parameters.createConfigurationParameters(Parameters.java:86)
    at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:199)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:653)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
    at org.testng.TestRunner.privateRun(TestRunner.java:767)
    at org.testng.TestRunner.run(TestRunner.java:617)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
    at org.testng.SuiteRunner.run(SuiteRunner.java:240)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
    at org.testng.TestNG.run(TestNG.java:1057)
    at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)

    SKIPPED CONFIGURATION: @AfterMethod closeBrowser
    SKIPPED: test

    ===============================================
    Default test
    Tests run: 1, Failures: 0, Skips: 1
    Configuration Failures: 1, Skips: 1
    ===============================================

    ===============================================
    Default suite
    Total tests run: 1, Failures: 0, Skips: 1
    Configuration Failures: 1, Skips: 1
    ===============================================

    [TestNG] Time taken by [FailedReporter passed=0 failed=0 skipped=0]: 37 ms
    [TestNG] Time taken by org.testng.reporters.jq.Main@b1c260: 34 ms
    [TestNG] Time taken by org.testng.reporters.JUnitReportReporter@f73c1: 7 ms
    [TestNG] Time taken by org.testng.reporters.XMLReporter@1f6f0bf: 10 ms
    [TestNG] Time taken by org.testng.reporters.SuiteHTMLReporter@2c84d9: 39 ms
    [TestNG] Time taken by org.testng.reporters.EmailableReporter2@8b819f: 5 ms

    • Daniel says:

      I have the same problem, could you fix it?

      • satish says:

        I’ve the same problem,please reply me as soon as possible.

      • Amit says:

        Hi,
        sometimes this problem comes whle running your tests using TestNG.
        To resolve this error, you can do one thing that the file where you have created method for opening the browser (i.e the method to launch the application), just put a the below line with the method as:-
        public void openBrowser(@Optional(“firefox”) String Browser, @Optional(“”) String AppURL)
        {
        // Here your code for launching the app goes…..
        }

        Your error goes away…..after running this code..

        Please let me know if you are still facing such issue.

        Thanks
        Amit

        • prabhu says:

          How to run multiple user login using webdriver + Eclips … can You
          plz provide the step by step procedure….

  9. goran says:

    Hi,
    Is it possible to have multiple versions of IE on the same machine and run test again them?

  10. Devendra Kumar says:

    Hi, I am new on selenium. I want to run selenium test case from console using webdriver in java. So please provide me appropriate information regarding this. What packages will be needed and what are steps need to follow for running this. Thanks in advance.

  11. munnira says:

    My question is related to

    –driver.findElement(By.id(“gbqfq”)).sendKeys(“selenium”);
    There are no id’s in my FF with id “gbqfq”..

    –driver.findElement(By.xpath(“//ol[@id=’rso’]/li[1]//h3/a”)).click();
    from where did u get this Xpath — i am getting positional xPath by righclicking on third option..

    —How do we generalize that by default it should pick 3rd option for any search…
    i was searching for testng and it didnt click on third option.But it worked well for selenium

  12. akshatktshat says:

    I am getting NULL Pointer Exception
    <>
    =======
    XML file below
    ====================================================================

    –>

    =======
    Browser file below
    ====================================================================
    package test;

    import org.openqa.selenium.WebDriver;
    //import org.openqa.selenium.chrome.ChromeDriver;
    import org.openqa.selenium.firefox.FirefoxDriver;
    import org.openqa.selenium.ie.InternetExplorerDriver;
    import org.openqa.selenium.support.ui.WebDriverWait;
    import org.testng.annotations.AfterMethod;
    import org.testng.annotations.Parameters;
    //import org.testng.annotations.AfterTest;
    import org.testng.annotations.BeforeMethod;

    public class Browser {

    //WebDriver driver;
    WebDriver webDriver = null;
    ReadDataFromExcel excelData = null;
    Contants var = new Contants();
    String[][] data = null;
    String[][] steps = null;
    WebDriverWait wait = null;
    TestUtilityMethods testUtil = new TestUtilityMethods();

    @BeforeMethod
    public void beforeMethod(){

    excelData = new ReadDataFromExcel();
    data = excelData.excelReadMethod(var.dataFile, var.productNameSheet);
    steps = excelData.excelReadMethod(var.stepsFile, var.stepsSheet);

    // Initialize the web driver & web Driver wait objects.
    webDriver = testUtil.keywordMethods(steps, webDriver);
    //webDriver = this.OpenBrowser(BROW)
    wait = new WebDriverWait(webDriver, 10);
    }

    @Parameters(“browser”)
    public void openBroswer(String browser){

    /*Comparing the value of parameter name if this is FF then It would launch Firefox and script that would run is as follows */
    if(browser.equalsIgnoreCase(“FF”))
    {
    System.out.println(“Firefox driver would be used”);
    webDriver = new FirefoxDriver();
    }
    else
    {
    System.out.println(“Ie webdriver would be used”);
    webDriver = new InternetExplorerDriver();
    }
    }

    @AfterMethod /* this annotation would run once test script execution would complete*/
    public void closeBrowser()
    {try{
    webDriver.wait(5000);
    }
    catch(Exception e){}
    webDriver.close();
    webDriver.quit();
    }

    }
    =======
    Test1.java file below
    ====================================================================
    package test;

    import static org.testng.Assert.assertEquals;

    import org.openqa.selenium.By;
    import org.openqa.selenium.support.ui.ExpectedConditions;
    import org.testng.Reporter;
    import org.testng.annotations.Test;

    @Test

    public class Test1 extends Browser {

    public void test1_LoginScreen() {
    System.out.println(“test After method”);

    try {
    //Wait for the login screen to render on screen.
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.id(“customer-portal”)));

    //Locate elements and test with asserts.
    assertEquals(webDriver.getCurrentUrl().toString(), “http://localhost:8080/asm/asm_input”);
    System.out.println(“Assert Successful.”);
    } catch (Exception e) {
    // TODO Auto-generated catch block
    e.getMessage();
    }
    }

    }
    ====================================================================

    Any help will be appreciated 🙂

    • akshatktshat says:

      XML file didnt came well so re-posting it.
      =================================================

      –>

      • akshatktshat says:

        OK so now it is running..issue was in the XML file. I was giving the wrong class name. But now it is only running for Firefox & not for IE….any suggestions?

  13. @akshatktshat

    I have mailed you the solution so try that once and then let me know.

  14. harsh says:

    Hello Dwarika,

    I have copy and pasted the same code and the same XML written by you.
    All the browser gets open parallel. But after finish the task in one browser, it get started in another than after finishing task in 2nd it gets performed in 3rd browser.

    I suppose the same action should get performed in all the browsers parallel.
    Please help me out.
    Thanks in advance.

  15. NIyati says:

    org.testng.TestNGException: org.xml.sax.SAXParseException; lineNumber: 2; columnNumber: 13; Open quote is expected for attribute “{1}” associated with an element type “name”.
    at org.testng.TestNG.initializeSuitesAndJarFile(TestNG.java:341)
    at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:88)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
    Caused by: org.xml.sax.SAXParseException; lineNumber: 2; columnNumber: 13; Open quote is expected for attribute “{1}” associated with an element type “name”.
    atcom.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)

    Got this error for above code ,
    So i m unable to understand Error
    can any 1 help me for this ……………………………..!

    • @Niyati

      There is problem in your xml …try to write allabove code manual because i have found it few time that copying above code is introducing some random string so try it manually or drop me a mail, i will send you the xml file that you can use for parallel execution

  16. Niyati says:

    @Dwarika
    I solved my all error in above program There is a problem in xml file only
    Modified XMl File :

    Btw Thanks again for such a nice concept 😀

  17. Niyati says:

    Reblogged this on NiyatiSoni.

  18. satish says:

    [TestNG] Running:
    C:UsersSatishAppDataLocalTemptestng-eclipse-1224165690testng-customsuite.xml

    FAILED CONFIGURATION: @BeforeMethod openBrowser
    org.testng.TestNGException:
    Parameter ‘browser’ is required by @Configuration on method openBrowser but has not been marked @Optional or defined
    in C:UsersSatishAppDataLocalTemptestng-eclipse-1224165690testng-customsuite.xml
    at org.testng.internal.Parameters.createParameters(Parameters.java:155)
    at org.testng.internal.Parameters.createParameters(Parameters.java:358)
    at org.testng.internal.Parameters.createConfigurationParameters(Parameters.java:86)
    at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:199)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:653)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
    at org.testng.TestRunner.privateRun(TestRunner.java:767)
    at org.testng.TestRunner.run(TestRunner.java:617)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:335)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:330)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
    at org.testng.SuiteRunner.run(SuiteRunner.java:240)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
    at org.testng.TestNG.run(TestNG.java:1057)
    at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)

    SKIPPED CONFIGURATION: @AfterMethod closeBrowser
    SKIPPED: test

    ===============================================
    Default test
    Tests run: 1, Failures: 0, Skips: 1
    Configuration Failures: 1, Skips: 1
    ===============================================

    ===============================================
    Default suite
    Total tests run: 1, Failures: 0, Skips: 1
    Configuration Failures: 1, Skips: 1
    ===============================================

    [TestNG] Time taken by [FailedReporter passed=0 failed=0 skipped=0]: 19 ms
    [TestNG] Time taken by org.testng.reporters.SuiteHTMLReporter@538b31: 164 ms
    [TestNG] Time taken by org.testng.reporters.JUnitReportReporter@53f89f: 8 ms
    [TestNG] Time taken by org.testng.reporters.jq.Main@15075f9: 151 ms
    [TestNG] Time taken by org.testng.reporters.XMLReporter@c7539: 8 ms
    [TestNG] Time taken by org.testng.reporters.EmailableReporter2@e5307e: 9 ms

  19. Rajani says:

    Browser is not getting maximized completely during execution of Web driver programs.
    Please suggest me.

    • @Rajani

      use this line of code
      driver.manage().window().maximize();
      just after your this line of code
      driver = new FirefoxDriver();

      Hope this would help you to maximize your window

      Thank you!!

      • Rajani says:

        First of all thanks for quick reply.. but I heard that web driver by default maximize the browser where as in RC we have to use the command selenium.windowMaximize()..
        Please correct me if I am wrongh..

  20. tester02 says:

    hi i am new to testng . how do i give runtime arguments to testng vi ant ?? i want to create a runnable jar of my tests from command line with command line arguments . browser is firefox only.

  21. Gaurav says:

    Hi,

    I am able to open 2 parallel browsers using XML file. But all the executions of 2 tests are running in only one browser. Please help !!

  22. Manish Kumar says:

    Hi Dwarika,

    I have used your code for running a test on different browsers but it is giving an error “Parameter ‘browser’ is required by @Configuration on method openBroswer but has not been marked @Optional or defined”

    My Code is given below please suggest me where i did mistake

    XML file:

    Broswer File:
    package com.testng;

    import java.util.concurrent.TimeUnit;

    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.firefox.FirefoxDriver;
    import org.openqa.selenium.ie.InternetExplorerDriver;
    import org.testng.annotations.AfterMethod;
    import org.testng.annotations.BeforeMethod;
    import org.testng.annotations.Parameters;

    public class Browser
    {

    WebDriver driver;

    @BeforeMethod
    @Parameters(“browser”)
    public void openBroswer(String browser)
    {

    /*Comparing the value of parameter name if this is FF then It would launch Firefox and script that would run is as follows */
    if(browser.equalsIgnoreCase(“FF”))
    {
    System.out.println(“Firefox driver would be used”);
    driver = new FirefoxDriver();
    driver.manage().timeouts().implicitlyWait(50, TimeUnit.SECONDS);
    }
    else
    {
    System.out.println(“Ie webdriver would be used”);
    driver =new InternetExplorerDriver();
    driver.manage().timeouts().implicitlyWait(50, TimeUnit.SECONDS);

    }
    }
    @AfterMethod /* this annotation would run once test script execution would complete*/

    public void closeBrowser()
    {
    try
    {
    driver.wait(15000);
    }
    catch(Exception e){}
    driver.close();
    driver.quit();
    }
    }

    and My Test file:
    package com.testng;

    import java.util.concurrent.TimeUnit;

    import org.openqa.selenium.By;
    import org.testng.Reporter;
    import org.testng.annotations.Test;

    @Test

    public class Gmail_Login extends Browser
    {

    public void openbroswer()
    {

    driver.get(“http://www.google.com/”);
    driver.findElement(By.className(“gb_f”)).click();
    try
    {
    Thread.sleep(5000);
    }
    catch (InterruptedException e)
    {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }

    }

    }

    Please have look into this.

    Thanks in advance!

  23. Manish Kumar says:

    Hi Dwarika,

    It is working fine on IE but on FF it is giving an below error:

    org.openqa.selenium.WebDriverException: Failed to connect to binary FirefoxBinary(C:Program Files (x86)Mozilla Firefoxfirefox.exe) on port 7055; process output follows:
    *** LOG addons.manager: Application has been upgraded
    *** LOG addons.xpi: startup
    *** LOG addons.xpi: Skipping unavailable install location app-system-local
    *** LOG addons.xpi: Skipping unavailable install location app-system-share
    *** LOG addons.xpi: Ignoring file entry whose name is not a valid add-on ID: C:UsersManishAppDataLocalTempanonymous6754452699755471458webdriver-profileextensionswebdriver-staging
    *** LOG addons.xpi: checkForChanges
    *** LOG addons.xpi-utils: Opening XPI database C:UsersManishAppDataLocalTempanonymous6754452699755471458webdriver-profileextensions.json
    *** LOG addons.xpi: New add-on fxdriver@googlecode.com installed in app-profile
    *** Blocklist::_loadBlocklistFromFile: blocklist is disabled
    *** LOG addons.xpi-utils: Make addon app-profile:fxdriver@googlecode.com visible
    *** LOG DeferredSave/extensions.json: Save changes
    *** LOG DeferredSave/extensions.json: Save changes
    *** LOG addons.xpi: New add-on {972ce4c6-7e08-4474-a285-3208198ce6fd} installed in app-global
    *** LOG addons.xpi-utils: Make addon app-global:{972ce4c6-7e08-4474-a285-3208198ce6fd} visible
    *** LOG DeferredSave/extensions.json: Save changes
    *** LOG DeferredSave/extensions.json: Save changes
    *** LOG addons.xpi: New add-on wrc@avast.com installed in winreg-app-global
    *** LOG addons.xpi-utils: Make addon winreg-app-global:wrc@avast.com visible
    *** LOG DeferredSave/extensions.json: Save changes
    *** LOG DeferredSave/extensions.json: Save changes
    *** LOG addons.xpi: Updating database with changes to installed add-ons
    *** LOG addons.xpi-utils: Updating add-on states
    *** LOG addons.xpi-utils: Writing add-ons list
    *** LOG DeferredSave/extensions.json: Starting timer
    *** LOG DeferredSave/extensions.json: Starting write
    *** LOG DeferredSave/extensions.json: Write succeeded
    *** LOG addons.xpi-utils: XPI Database saved, setting schema version preference to 15
    *** LOG addons.manager: shutdown
    *** LOG addons.xpi: shutdown
    *** LOG addons.xpi-utils: shutdown
    *** LOG addons.xpi: Notifying XPI shutdown observers
    *** LOG addons.manager: Async provider shutdown done
    *** LOG addons.xpi: startup
    *** LOG addons.xpi: Skipping unavailable install location app-system-local
    *** LOG addons.xpi: Skipping unavailable install location app-system-share
    *** LOG addons.xpi: Ignoring file entry whose name is not a valid add-on ID: C:UsersManishAppDataLocalTempanonymous6754452699755471458webdriver-profileextensionswebdriver-staging
    *** LOG addons.xpi: checkForChanges
    *** LOG addons.xpi: No changes found
    JavaScript error: chrome://browser/content/urlbarBindings.xml, line 654: aUrl is undefined
    JavaScript error: chrome://browser/content/urlbarBindings.xml, line 654: aUrl is undefined
    JavaScript error: chrome://browser/content/urlbarBindings.xml, line 654: aUrl is undefined
    JavaScript error: chrome://browser/content/urlbarBindings.xml, line 654: aUrl is undefined
    JavaScript error: chrome://browser/content/urlbarBindings.xml, line 654: aUrl is undefined
    JavaScript error: chrome://browser/content/urlbarBindings.xml, line 654: aUrl is undefined

    Build info: version: ‘2.31.0’, revision: ‘1bd294d’, time: ‘2013-02-27 20:52:59’
    System info: os.name: ‘Windows 7’, os.arch: ‘x86’, os.version: ‘6.1’, java.version: ‘1.7.0_25’
    Driver info: driver.version: FirefoxDriver
    at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:118)
    at org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:244)
    at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:110)
    at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:190)
    at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:183)
    at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:179)
    at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:92)
    at com.testng.Browser.openBroswer(Browser.java:27)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
    at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:564)
    at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:213)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:653)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
    at org.testng.TestRunner.privateRun(TestRunner.java:767)
    at org.testng.TestRunner.run(TestRunner.java:617)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:335)
    at org.testng.SuiteRunner.access$000(SuiteRunner.java:37)
    at org.testng.SuiteRunner$SuiteWorker.run(SuiteRunner.java:369)
    at org.testng.internal.thread.ThreadUtil$2.call(ThreadUtil.java:64)
    at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
    Caused by: org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms. Firefox console output:
    *** LOG addons.manager: Application has been upgraded
    *** LOG addons.xpi: startup
    *** LOG addons.xpi: Skipping unavailable install location app-system-local
    *** LOG addons.xpi: Skipping unavailable install location app-system-share
    *** LOG addons.xpi: Ignoring file entry whose name is not a valid add-on ID: C:UsersManishAppDataLocalTempanonymous6754452699755471458webdriver-profileextensionswebdriver-staging
    *** LOG addons.xpi: checkForChanges
    *** LOG addons.xpi-utils: Opening XPI database C:UsersManishAppDataLocalTempanonymous6754452699755471458webdriver-profileextensions.json
    *** LOG addons.xpi: New add-on fxdriver@googlecode.com installed in app-profile
    *** Blocklist::_loadBlocklistFromFile: blocklist is disabled
    *** LOG addons.xpi-utils: Make addon app-profile:fxdriver@googlecode.com visible
    *** LOG DeferredSave/extensions.json: Save changes
    *** LOG DeferredSave/extensions.json: Save changes
    *** LOG addons.xpi: New add-on {972ce4c6-7e08-4474-a285-3208198ce6fd} installed in app-global
    *** LOG addons.xpi-utils: Make addon app-global:{972ce4c6-7e08-4474-a285-3208198ce6fd} visible
    *** LOG DeferredSave/extensions.json: Save changes
    *** LOG DeferredSave/extensions.json: Save changes
    *** LOG addons.xpi: New add-on wrc@avast.com installed in winreg-app-global
    *** LOG addons.xpi-utils: Make addon winreg-app-global:wrc@avast.com visible
    *** LOG DeferredSave/extensions.json: Save changes
    *** LOG DeferredSave/extensions.json: Save changes
    *** LOG addons.xpi: Updating database with changes to installed add-ons
    *** LOG addons.xpi-utils: Updating add-on states
    *** LOG addons.xpi-utils: Writing add-ons list
    *** LOG DeferredSave/extensions.json: Starting timer
    *** LOG DeferredSave/extensions.json: Starting write
    *** LOG DeferredSave/extensions.json: Write succeeded
    *** LOG addons.xpi-utils: XPI Database saved, setting schema version preference to 15
    *** LOG addons.manager: shutdown
    *** LOG addons.xpi: shutdown
    *** LOG addons.xpi-utils: shutdown
    *** LOG addons.xpi: Notifying XPI shutdown observers
    *** LOG addons.manager: Async provider shutdown done
    *** LOG addons.xpi: startup
    *** LOG addons.xpi: Skipping unavailable install location app-system-local
    *** LOG addons.xpi: Skipping unavailable install location app-system-share
    *** LOG addons.xpi: Ignoring file entry whose name is not a valid add-on ID: C:UsersManishAppDataLocalTempanonymous6754452699755471458webdriver-profileextensionswebdriver-staging
    *** LOG addons.xpi: checkForChanges
    *** LOG addons.xpi: No changes found
    JavaScript error: chrome://browser/content/urlbarBindings.xml, line 654: aUrl is undefined
    JavaScript error: chrome://browser/content/urlbarBindings.xml, line 654: aUrl is undefined
    JavaScript error: chrome://browser/content/urlbarBindings.xml, line 654: aUrl is undefined
    JavaScript error: chrome://browser/content/urlbarBindings.xml, line 654: aUrl is undefined
    JavaScript error: chrome://browser/content/urlbarBindings.xml, line 654: aUrl is undefined
    JavaScript error: chrome://browser/content/urlbarBindings.xml, line 654: aUrl is undefined

    at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:106)
    … 30 more

  24. Manish says:

    Hi Dwarika,

    Currently i am working on Object Repository of selenium.

    I want to get the attribute value of all the element present on a web page along with the count of the element.

    So please suggest me what should i do first and how can i do that.

    Thanks in Advance!

  25. SB says:

    @Manish
    Please search Web, u can get plenty- Here is one example:
    driver.findElement(By.id(“idoftheelem”)).getAttribute(“value”);

    @Dwarika
    Nice and excellent!
    Thanks for your time and help!
    Have u ever worked with BDD (RobotFramework / JBehave)

  26. SB says:

    @Dwarika,

    If we use the single and same WebDriver object for more than 1 class/test for Parallel runs, will this create problem ?
    Because more than one class are using the samea WebDriver object (though for IEDriver and FFdriver are separate things)

    Thanks

    • No we are not using same object in multiple classes, actually here we are using Parametrization and here we are just changing the parameter with FF, IE or with Chrome and whenever code is seeing IE or FF or Chrome then it is calling the respective browser.

  27. SB says:

    Thanks for the reply!

    Sorry, I did not see any JUnit specific topi, so posting here.

    I need your advice.
    I am using – JUnit +Eclipse +Java+Webdriver.
    I want to use Assumes in my Java files, so if the 1st method fails, the subsequent methods won’t run.

    For this, I tried to use Corollaries.java which is at Github.com

    My example Java file:
    ——————-
    import junit.framework.Assert;
    import org.junit.Rule;
    import org.junit.contrib.assumes.Corollaries;
    import org.junit.runner.RunWith;
    import……………………

    @RunWith(Corollaries.class)
    public class myC()
    {
    }
    ——————————–

    My problem is, I could not understand how to use it.

    I put the Corollaries.java in my package.
    But getting error at —–
    Assumes assumptions = method.getAnnotation(Assumes.class);

    The error says that Assumes class is not extending the Annotations.

    Can u help.

    Best regards,

  28. pooja says:

    hi Dwarika,

    Thanks for writing this …..
    How to distribute tests among different browsers?
    Have to run some of the tests on 1 browser, some on other to distribute the load (I have 40 tests in excel sheet, so takes more than an hour to complete the test, so thought, distributing them among different browsers will help out) so I’m exploring selenium grid,
    Have registered hub and nodes, have run one test ex.
    DesiredCapabilities capability = DesiredCapabilities.firefox();
    capability.setCapability(“browser”, “firefox”);
    capability.setCapability(“browser_version”, “Linux”);
    capability.setCapability(“os”, “7”);
    capability.setCapability(“os_version”, “17.0”);
    capability.setCapability(“browserstack.debug”, “true”);
    WebDriver driver = new RemoteWebDriver(new URL(“http://localhost:4444/wd/hub”), capability);
    driver.get(“http://www.google.com”);

    But it runs only once and on 1 browser at a time. (I can parametrize it with TestNg and run same with different browsers parallel like you said, but it runs same test in different browsers not distributes the tests)
    So how should I modify it to distribute my tests let say open 5 browsers (1st browser runs-1st 8 tests, 2nd runs-next 8 tests and so on)?

    I’m Using
    Java+ WebDriver+Maven+TestNg and controlling tests on Jenkins

  29. Sumit Kumar Mishra says:

    Hi Dwarika,

    I am new in automation testing and trying to setup hybrid automation framework in our organization.

    Please can you guide me or do you have any demo of hybrid framework design?

    My mail id : sumit.mishra48@gmail.com

  30. Bhavana says:

    Hi Dwarika,

    Can you please tell me that in the Selenium webdriver, if I have a button on a webpage wherein its location is continuously changing, then how do i write the xpath for that button?? Will the xpath remain same or how

  31. Prathap says:

    How to run test on multiple browser. I am using cucumberjs and selenium. Please help me

  32. Natalie says:

    Hi Dwarika Dhish Mishra,

    Thank you for your blog, for giving a chance to others learn from you!

    My question might be simple, but I struggle to find a solution. In your example you run in parallel tests on different browser type.

    I have key-driven build framework where each test cases set are in Excel spreadsheet. For example I ran spreadsheet S1 and S2 where S1 has all login test cases and S2 has all email validation test cases. I have more than 2 of cause.

    Question:

    I do NOT want to run S1,S2… on FF and IE on two different browsers. How to set up testng.xml to be able to run S1, S2 etc in parallel using same browser, say FF. I want to speed up execution of all test cases against one browser.

    Thank you for your help,
    Natalie

  33. datta says:

    I tried this program it is just showing the result . it did not perform any action on browser.

    [TestNG] Running:
    C:\Users\Day\AppData\Local\Temp\testng-eclipse-275109580\testng-customsuite.xml

    ===============================================
    Default test
    Tests run: 0, Failures: 0, Skips: 0
    ===============================================

    ===============================================
    Default suite
    Total tests run: 0, Failures: 0, Skips: 0
    ===============================================

    [TestNG] Time taken by org.testng.reporters.EmailableReporter2@bf2d5e: 6 ms
    [TestNG] Time taken by org.testng.reporters.SuiteHTMLReporter@1e4457d: 34 ms
    [TestNG] Time taken by org.testng.reporters.XMLReporter@18a7efd: 71 ms
    [TestNG] Time taken by [FailedReporter passed=0 failed=0 skipped=0]: 0 ms
    [TestNG] Time taken by org.testng.reporters.JUnitReportReporter@1632c2d: 0 ms
    [TestNG] Time taken by org.testng.reporters.jq.Main@13caecd: 55 ms
    Picked up _JAVA_OPTIONS: -Xmx512M

  34. Vishnu says:

    Hi Dwarika,

    I am trying parallel execution in same browser. It has created two result folders but When creating result files (Excel) it is failed to create. How to create two excel report file for the same time to the respective folders.

    Error shows as below

    Cannot create EXCEL File, test case stop.Failed, Create Excel ‘ExcelResult_5_FEB_2015_08_35_18.xls’ has error is occur. (null)
    ================================> Cannot create EXCEL File, test case stop.Feb 05, 2015 8:35:22 AM org.openqa.selenium.os.UnixProcess$SeleniumWatchDog destroyHarder
    INFO: Command failed to close cleanly. Destroying forcefully (v2). org.openqa.selenium.os.UnixProcess$SeleniumWatchDog@370b8836

  35. Robin Hood says:

    I learned a lot at thedevmasters.com. It is an amazing service special there mentoring program gave me real hand on experience in troubleshooting. I was able to create a full “Sports Statistics Scripts write a script to process data using selenium tools.” in less than 6 hour time all by myself. Amazing professional team of mentors and software educators. Visit http://www.thedevmasters.com and robin@thedevmasters.com, 1(866)340-1375

  36. Reina says:

    When Ioriginally commented I clicked the “Notify me when new comments are added” checkbox and now
    each time a comment is added I get three e-mails with the same comment.
    Is there any way you can remove me from that service?
    Cheers!

  37. vivek says:

    Hi,
    My requirement is that while the method under @Test is getting executed I want to print the browser on which it is getting executed.How would I be abLe to do that?

  38. Sandeep says:

    i have configured all as per the steps mentioned and is running as well without error.
    But is is not opening any browser just giving me below result –
    [TestNG] Running:
    C:\Users\ssha65\AppData\Local\Temp\testng-eclipse–1069124013\testng-customsuite.xml

    ===============================================
    Default test
    Tests run: 0, Failures: 0, Skips: 0
    ===============================================

  39. Smita says:

    Hi,

    I am able to open 2 parallel browsers using XML file. But all the executions of 2 tests are running in only one browser. Please help !!

  40. Jyothi says:

    Hi Dwarika,
    I got solution from this Article.Thank you.

  41. Gopika says:

    Wow, what a explanation!! Thanks a lot man 🙂 Your blog is awesome and also I’m wondering about the discussion here. All my doubts are cleared in your discussion. Thank you very much. I would like to visit your blog often. Keep Rocking.

  42. Sunil says:

    Hi Dwarika!

    In xml containing 5 classes, i have given parallel = “classes” thread-count=”2″.But I want to run the test cases sequentially but I do not want to make changes in the xml file. When I tried using listener (IAnnotationTransformer) anotation.setSequential=”true” and I also tried at the @Test by providing sequential=”True” and singleThreaded=”True”. It still executes in parallel. Is there anyway to solve this.

    Thanks,
    Sunil

  43. Vaishnavi Chheda says:

    Thanks for a great blog.
    But I am unable to start the run the test on any browsers.
    The browser opens but nothing happens after.

    FF: 52.0
    MacOs: Sierra

  44. raji says:

    Hi dwarika,

    How to do the same in junit+selenium webdriver+maven…

  45. raji says:

    Hi dwarika,

    How to do the HOW TO EXECUTE SELENIUM WEBDRIVER TEST CASES PARALLEL IN MULTIPLE BROWSER USING junit+selenium webdriver+maven….

  46. vasista says:

    Please share with me final code of “PARALLEL IN MULTIPLE BROWSER USING TESTNG PARAMETER ANNOTATION “

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.