How can I parallely execute automation tests using Selenium Grid

0 votes
How can I parallely execute automation tests using Selenium Grid?
Jul 22, 2019 in Selenium by Urmila
709 views

1 answer to this question.

0 votes

Hello Urmila, to parallelly execute automation tests using Selenium Grid, you can use following code snippet:

public class Parallel_Execution_Test
{
    WebDriver driver;
    String nodeURL;

    @Parameters({"Port"})
    @BeforeMethod()
    public void setUp(String Port) throws MalformedURLException
    {         
        if(Port.equalsIgnoreCase("4546"))
        {
            nodeURL = "http://10.0.0.22:4546/wd/hub";
            System.out.println("Chrome Browser Initiated");
            DesiredCapabilities capabilities = DesiredCapabilities.chrome();          
            capabilities.setBrowserName("chrome");
            capabilities.setPlatform(Platform.WINDOWS);

            driver = new RemoteWebDriver(new URL(nodeURL),capabilities);

            driver.get("https://www.google.com/");
            driver.manage().window().maximize();
            driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        }
        else if(Port.equalsIgnoreCase("5566"))
            {
                nodeURL = "http://10.0.0.22:5566/wd/hub";
                System.out.println("Firefox Browser Initiated");
                DesiredCapabilities capabilities1 = DesiredCapabilities.firefox();
                capabilities1.setBrowserName("firefox");
                capabilities1.setPlatform(Platform.WINDOWS);

                driver = new RemoteWebDriver(new URL(nodeURL),capabilities1);  

                driver.get("https://www.google.com/");
                driver.manage().window().maximize();
                driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
            }

        else if(Port.equalsIgnoreCase("4547"))
        {
            nodeURL = "http://10.0.0.22:4547/wd/hub";
            System.out.println("Internet Browser Initiated");
            DesiredCapabilities capabilities2 = DesiredCapabilities.internetExplorer();
            capabilities2.setBrowserName("internet explorer");
            capabilities2.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
            capabilities2.setCapability(InternetExplorerDriver.IGNORE_ZOOM_SETTING, true);
            capabilities2.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
            capabilities2.setCapability("ignoreProtectedModeSettings", true);
            capabilities2.setCapability("nativeEvents", false);
            capabilities2.setCapability(InternetExplorerDriver.INITIAL_BROWSER_URL, "");
            capabilities2.setCapability(InternetExplorerDriver.LOG_LEVEL, "DEBUG");
           

            capabilities2.setPlatform(Platform.WINDOWS);

            driver = new RemoteWebDriver(new URL(nodeURL),capabilities2);

            driver.get("https://www.google.com/");
            driver.manage().window().maximize();  
            driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        }
    }

    @Test
    public void googlePage() throws InterruptedException
    {
        try
        {

        driver.findElement(By.xpath("//*[id=search")).click();
        Thread.sleep(2000);

        driver.findElement(By.cssSelector("#chapternav > div > ul > li.chapternav-item.chapternav-item-ipad-air > a > figure")).click();
        Thread.sleep(2000);

        driver.findElement(By.linkText("Google Search")).click();
        Thread.sleep(2000);
        }

        catch(Exception e)
        {
            System.out.println(e.getMessage());
        }
    }

    @AfterMethod()
    public void tearDown()
    {
            driver.quit();
            System.out.println("Browser Closed");
    }
}

Now create the testing.xml file to pass parameters:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite thread-count="3" name="MultipleBrowser" parallel="tests">

  <test name="Chrome Test">
  <parameter name="Port" value="4546"/>
    <classes>
      <class name="DemoAutomation.Selenium_MultiBrowser_Test"/>
    </classes>
  </test>
 
  <test name="Firefox Test">
  <parameter name="Port" value="5566"/>
    <classes>
      <class name="DemoAutomation.Selenium_MultiBrowser_Test"/>   
    </classes>
  </test>
 
  <test name="Internet Explorer Test">
  <parameter name="Port" value="4547"/>
    <classes>
      <class name="DemoAutomation.Selenium_MultiBrowser_Test"/>
    </classes>
  </test>
 
</suite>
answered Jul 22, 2019 by Anvi
• 14,150 points

Related Questions In Selenium

0 votes
2 answers

How can we take screenshots of tests in Selenium 2 using C#

Hey, try using following code command to ...READ MORE

answered Aug 23, 2019 in Selenium by Abha
• 28,140 points
1,009 views
0 votes
1 answer

How can I download the *.jar file from http:// seleniumhq.org using selenium WebDriver?

For Selenium Standalone Server use this: profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/java-archive"); and ...READ MORE

answered Apr 9, 2018 in Selenium by Martin
• 4,320 points
3,247 views
0 votes
1 answer

How can I implement Selenium using C#?

Reference https://www.seleniumhq.org/docs/03_webdriver.jsp#the-5-minute-getting-started-guide using OpenQA.Selenium.Firefox; using OpenQA.Selenium; class GoogleSuggest { ...READ MORE

answered Apr 9, 2018 in Selenium by Neville
627 views
0 votes
1 answer

How can I setup Selenium Grid in Selenium 3.0

Below is the stepwise solution for setting ...READ MORE

answered Apr 27, 2018 in Selenium by Meci Matt
• 9,460 points
897 views
0 votes
2 answers

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,500 points
12,766 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
8,631 views
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,910 points
6,704 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 3, 2020 in Selenium by Sri
• 3,190 points
7,569 views
0 votes
1 answer

How can I refresh a browser window in different ways using Selenium Webdriver?

Hello Piyush, you can refresh a browser ...READ MORE

answered May 29, 2019 in Selenium by Anvi
• 14,150 points
2,923 views
0 votes
1 answer

How can I clear the text in a text box using Selenium WebDriver?

Hello Akriti, you can clear the text ...READ MORE

answered May 29, 2019 in Selenium by Anvi
• 14,150 points
6,247 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP