Selenium Grid with TestNG

How to Configure Selenium Grid:
I hope i don't need to give explanation of Selenium Grid. So i would like to go straight away to the configuration part.
How to Configure TestNG in Eclipse.
1. Download Test NG.
2. Eclipse - File - New Java Project.
3.Right Click on the Project and Select Build Path -->Configuration Build Path.
4.Click Add External Jars -->Select (Currently) testng-5.13.1.jar.
Step by Step Configuration of Selenium Grid:
2. Selenium Grid uses ant targets to start or launch the Grid. Also the package comes with ant targets to launch Remote Control on desired port. So we need to Configure ANT.

4.Unpack the zip and add the ant bin path (ex: F:\Automation\apache-ant-1.8.2\bin to the System Variable Path.














5.Add JAVA_HOME in User Variables.


 6.To make sure the configuration is proper, Open Command prompt and go to the ant bin directory and type ant -version.You should get this details.Thats It! You have successfully Configured the ANT





Launch the Selenium Grid Hub:
Imagine we need to run a test script at a time on both Firefox and Internet Explorer.
1.Start the grid : Goto Command prompt and the directory where the grid is located and build.xml exists.
2.Type ant launch-hub. This will launch the Selenium Grid on 4444 port.
3.Now we need to register 2 remote controls to Grid. One RC for running Firefox tests and the other for Internet Explorer tests.
4.Open the command prompt from the Grid directory and run the following command.
ant -Dport=5556 -Denvironment=*firefox launch-remote-control . This will start Remote Control instance on 5556 and will be listening to grid.
5.Open another command prompt from the Grid directory and run the following command
ant -Dport=5557 -Denvironment=*iehta launch-remote-control . This will start Remote Control instance on 5557 and will be listening to grid.


6.Open the browser and run the following URL http://localhost:4444/console. This is to make sure RCs registered to grid.


 
How to run Test Scripts against multiple RCs parallel:
1.Eclipse create a New Java Project. 

2.Right Click on the Project - TestNG -->Create TestNg Class.














3.Create Test NG class as follows:

















4.Open the testng.xml file and edit with following details
<suite name="Suite" parallel="tests">
    <test name="Firefox">
        <parameter name="selenium.host" value="localhost"></parameter>
        <parameter name="selenium.port" value="5556"></parameter>
        <parameter name="selenium.browser" value="*firefox"></parameter>
        <parameter name="selenium.url" value="http://www.google.com"></parameter>
        <parameter name="searchCriteria" value="SeleniumGrid"></parameter>
        <classes>
            <class name="com.qaselenium.NewTest" />
        </classes>
    </test>
    <test name="Internet Explorer">
        <parameter name="selenium.host" value="localhost"></parameter>
        <parameter name="selenium.port" value="5557"></parameter>
        <parameter name="selenium.browser" value="*iehta"></parameter>
        <parameter name="selenium.url" value="http://www.google.com"></parameter>
        <parameter name="searchCriteria" value="TestNG"></parameter>
        <classes>
            <class name="com.qaselenium.NewTest" />
        </classes>
    </test>
</suite>
5. Now a Single test script will run in both Firefox and Internet explorer. parallel parameter should be set to tests in order to run these test parallel on multiple browsers.
6.Open the TestNG class and use the following Code
package com.qaselenium;

import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;

import com.thoughtworks.selenium.DefaultSelenium;
import com.thoughtworks.selenium.Selenium;

public class NewTest {
    Selenium selenium;

    @BeforeClass
    @Parameters({ "selenium.host", "selenium.port", "selenium.browser",
            "selenium.url" })
    public void beforeClass(String host, String port, String browser, String url) {
        this.selenium = new DefaultSelenium(host, Integer.parseInt(port),
                browser, url);
        this.selenium.start();
        this.selenium.open("");
    }

    @AfterClass
    public void afterClass() {
        this.selenium.close();
        this.selenium.stop();
    }

    @Test
    @Parameters({ "searchCriteria" })
    public void testGoogleSearch(String criteria) {
        this.selenium.type("name=q", criteria);
        try {
            Thread.sleep(15000);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }   
}
Run the Test Script in Grid:

To run the tests, open the Testng.xml and right click >> Run as >> Run Configurations
36. Select TestNG from the left list
37. Click on Add (+) button on the topleft
38.Select the project
39.Select the TestSuite as src/testng.xml
40.Apply and run the settings
41.You can now run the tests on multiple browsers parallely.

THATS IT ENJOY!!!

39 comments:

  1. Thanks Vijay
    This is very useful article.

    Devendra Singh

    ReplyDelete
  2. Thanks Vijay Its very help full for me.

    ReplyDelete
  3. Thanks Vijay for the knowledge sharing....

    ~ Srini.

    ReplyDelete
  4. Thank u so much
    We were stuck for last 2 Hrs..
    The last portion of configuring the xml file was really helpful.

    ReplyDelete
  5. Any one help me!!!!!

    [TestNG] Running:
    /tmp/testng-eclipse--1183928812/testng-customsuite.xml

    FAILED CONFIGURATION: @BeforeClass beforeClass
    org.testng.TestNGException:
    Parameter 'selenium.host' is required by @Configuration on method beforeClass but has not been marked @Optional or defined
    in /tmp/testng-eclipse--1183928812/testng-customsuite.xml
    at org.testng.internal.Parameters.createParameters(Parameters.java:159)
    at org.testng.internal.Parameters.createParameters(Parameters.java:372)
    at org.testng.internal.Parameters.createConfigurationParameters(Parameters.java:90)
    at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:199)
    at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:140)
    at org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:170)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:104)
    at org.testng.TestRunner.privateRun(TestRunner.java:771)
    at org.testng.TestRunner.run(TestRunner.java:621)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:357)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:352)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:310)
    at org.testng.SuiteRunner.run(SuiteRunner.java:259)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1200)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1125)
    at org.testng.TestNG.run(TestNG.java:1033)
    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)


    ReplyDelete
  6. Above is issue ...i don't no how to resolve ....help me please

    ReplyDelete
  7. Thanks for a great information in your blog.I have read all the post of your blog.Great work on Selenium

    ReplyDelete
  8. Thanks for sharing great information in your blog. Got to learn new things from your Blog . It was very nice blog to learn about Selenium.
    Selenium

    ReplyDelete
  9. i have configured a Jenkins to run the test scripts in three different browser(chrome/ie/firefox),fr IE we are using a windows 2012 server.

    upto last week the scripts run without any issue. last week sytem get restarted then i have registered the IE,registration also successful.

    But once i registered it started to connect to some unwanted/random urls and creating lot of threads.

    After some the node will be done due to out of threads.

    can you anyone help me to solve this.

    ReplyDelete
  10. Advanced Selenium Framework Training in Chennai by Vishwa

    Hi, Reach Mr.Vishwa for Best Selenium and Coded UI Training in Chennai with real time project assistance. This people will teach everything from the basics up to advanced level scenarios from frameworks.

    I learned from Mr.Vishwa and Raj they are very good automation people for Selenium Frameworks. After joined with them I learned many things and now I am writing automation scripts in own project. Vishwa 9003085882
    selenium training in chennai

    ReplyDelete
  11. Hi friends,
    Thanks for referring a good training in selenium in Chennai. Got good results and feeling comfy and confident with them. So all of you looking for selenium training, talk to them.
    Talk to eight one two two two four one two eight six.
    http://thecreatingexperts.com/selenium-training- in-chennai/

    ReplyDelete
  12. This comment has been removed by the author.

    ReplyDelete
  13. This comment has been removed by the author.

    ReplyDelete
  14. Selenium is used in many IT companies due to its numerous advantages compared to other automation testing tools in the market. There is massive demand for automation testers to validate software and mobile applications across the world. Taking Selenium Course in Chennai will assist aspirants to enter automation testing industry!!!

    ReplyDelete

  15. It is really a great work and the way in which u r sharing the knowledge is excellent.
    Thanks for helping me to understand basic concepts. As a beginner in software testing your post help me a lot.Thanks for your informative article. software testing Training in chennai | Best software testing Training institute in velachery

    ReplyDelete
  16. Selenium Testing Real Time Hands on Training in Chennai…

    Don’t always Depend on Training Institute alone.Please aware of Best Trainers too..

    http://thecreatingexperts.com/selenium-training-in-chennai/

    If You need a Best Trainer in Selenium Testing??? Then be ready for a DEMO From the Trainer MR.Karthick
    CONTACT:8122241286

    Both Classroom/Online Training is Available!!!!!!

    ReplyDelete

  17. Selenium WebDriver fits in the same role as RC did, and has incorporated the original 1.x bindings. It refers to both the language bindings and the implementations of the individual browser controlling code. This is commonly referred to as just "WebDriver" or sometimes as Selenium 2.
    Selenium Training Institute in Chennai

    ReplyDelete
  18. Looking for best training in SELENIUM, take a glance at http://thecreatingexperts.com/selenium-training-in-chennai/

    ReplyDelete
  19. I was looking for Selenium and Appium training in Chennai and got a link,it was the CREATING EXPERTS awesome training with real-time scenarios,got a good exposure to learn things best.If you are looking for one click the link below and contact 8122241286.

    http://thecreatingexperts.com/appium-training-in-chennai/
    http://thecreatingexperts.com/selenium-training-in-chennai/

    ReplyDelete
  20. Few months back i was searching for SELENIUM training, and i attended demo session with some of the trainers in CHENNAI, but did not get a clear picture of whom to get trained with?

    Later i came across THE CREATING EXPERTS.The demo class was up-to the mark with satisfying my needs and requirements and here i got placed in a concern.

    Thanks to their in-depth hands on training with real time scenarios.For training inquiries

    http://thecreatingexperts.com/selenium-training-in-chennai/

    contact info - Mr.Karthick 8122241286

    ReplyDelete
  21. Thanks for sharing this blog.Creating Experts provides Best training in selenium

    http://thecreatingexperts.com/selenium-training-in-chennai/

    contact 8122241286

    ReplyDelete
  22. Thanks for sharing great information in your blog.

    Selenium training institute which provides Real Time Hands on Training…THE CREATING EXPERTS

    http://thecreatingexperts.com/selenium-training-in-chennai/


    contact-8122241286

    ReplyDelete
  23. nice blog...The leading training concern THE CREATING EXPERTS are providing SELENIUM training and here is the link

    http://thecreatingexperts.com/selenium-training-in-chennai/

    contact 8122241286

    ReplyDelete
  24. Thanks for sharing this blog.Creating Experts provides Best training in selenium

    http://thecreatingexperts.com/selenium-training-in-chennai/

    contact 8122241286

    ReplyDelete
  25. SELENIUM Training in Chennai is provided by

    THE CREATING EXPERTS they provide hands on training with real time scenarios

    http://thecreatingexperts.com/selenium-training-in-chennai/

    contact 8122241286 for more info

    ReplyDelete
  26. SELENIUM Training in Chennai is provided by

    THE CREATING EXPERTS they provide hands on training with real time scenarios

    http://thecreatingexperts.com/selenium-training-in-chennai/

    contact 8122241286 for more info

    ReplyDelete
  27. The Creating Experts provides training in SELENIUM

    They provide hands on training with real time scenarios

    http://thecreatingexperts.com/selenium-training-in-chennai/

    contact +91-08122241286

    ReplyDelete
  28. Nice blog...

    Selenium training institute which provides Real Time Hands on Training…THE CREATING EXPERTS

    http://thecreatingexperts.com/selenium-training-in-chennai/


    contact-8122241286

    ReplyDelete
  29. nice blog...Selenium training is offered by THE CREATING EXPERTS in Chennai

    http://thecreatingexperts.com/selenium-training-in-chennai/

    contact 8122241286

    ReplyDelete
  30. SELENIUM training in Chennai by TE CREATING EXPERTS ,they provide you hands on training with real time scenarios

    http://thecreatingexperts.com/selenium-training-in-chennai/

    contact 8122241286

    ReplyDelete
  31. Informative blog..SELENIUM testing by THE CREATING EXPERTS in CHENNAI

    http://thecreatingexperts.com/selenium-training-in-chennai/

    contact 8122241286

    ReplyDelete
  32. SELENIUM training in Chennai

    http://thecreatingexperts.com/selenium-training-in-chennai/

    SELENIUM training in Chennai by THE CREATING EXPERTS ,

    They provide you hands on training with real time scenarios

    contact 8122241286

    ReplyDelete
  33. Hi, all nice blog for a long time i was searching for a real time trainer and landed with my trainer in selenium
    SELENIUM training is provided by THE CREATING EXPERTS in CHENNAI

    http://thecreatingexperts.com/selenium-training-in-chennai/

    Contact 8122241286 for more info

    ReplyDelete
  34. NICE BLOG...Selenium training in CHENNAI provided by THE CREATING EXPERTS

    http://thecreatingexperts.com/selenium-training-in-chennai/

    CONTACT 8122241286.

    ReplyDelete
  35. Very Nice...Contains A to Z concepts...Thanks a lot.. and looking for the best selenium training in Chennai with certification from us. we have experienced selenium experts offer selenium course training with industry exposure. Check Here https://goo.gl/VRNEXv

    ReplyDelete
  36. The most popular destination for Hadoop Training in

    Noida
    in NOIDA is CIITNOIDA in Sector-2

    You can Master the various components of Hadoop ecosystem like Hadoop, MapReduce Architecture, Pig, Hive, HBase, Sqoop, Flume by their Senior Experts

    from Industry with good Industrial experience of handling big projects.

    You can even Get hands-on practice with live projects and ORACLE certification at CIITNOIDA.

    This Big Data Hadoop Training in Noida is best

    suited for CS & IT Engineering Students, professionals looking to gain expertise in Big Data and work for Fortune 500 Software Companies.

    Hadoop Training in Noida
    Big Data Hadoop Training in Noida

    ReplyDelete