How can I parallely execute automation tests using Selenium Grid?

0 votes
How can I parallely execute automation tests using Selenium Grid?
Jul 22 in Selenium by Urmila
46 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 by Anvi
• 13,960 points

Related Questions In Selenium

0 votes
2 answers
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,280 points
712 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
67 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,440 points
190 views
0 votes
1 answer

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,430 points
1,190 views
0 votes
1 answer
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,510 points
1,274 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,510 points
1,032 views
0 votes
1 answer
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 in Selenium by Anvi
• 13,960 points
374 views