0
votes

I am exploring selenium grid for executing tests on multiple browsers. I have configured hub and node following online tutorials. I have created a test script.

Here is the code of test script:

public class SeleniumGridTest {
  WebDriver driver;
  String baseUrl, nodeUrl;
  static FirefoxProfile myprofile;

  @BeforeTest
  public void beforeTest() throws MalformedURLException {
      ProfilesIni profile = new ProfilesIni();          
      myprofile = profile.getProfile("SeleniumAuto");         
      nodeUrl = "http://10.233.18.60:5566/wd/hub";
      DesiredCapabilities capability = DesiredCapabilities.firefox();
      capability.setBrowserName("firefox");
      capability.setCapability(FirefoxDriver.PROFILE, myprofile);     
      driver = new RemoteWebDriver(new URL(nodeUrl), capability);
  }

  @Test
  public void google() {  
  driver.get("http://www.google.co.in");
  System.out.println(driver.getCurrentUrl());
  }

  @Test
  public void newtours() {  
  driver.get("http://newtours.demoaut.com");
  System.out.println(driver.getCurrentUrl());
  }

  @AfterTest
  public void afterTest() {
  driver.quit();
  }

}

My aim is to run this test on multiple browsers I have added desired capabilities as firefox,

1)should I add desired capabilities  for other browsers in the
@BeforeTest annotation? for eg capability.setBrowserName("chrome");
2)is that enough to run on multiple browsers. 
3)If I have to run a suite of tests, where should I add the selenium grid configuration
details in all the tests or is it possible in testNG xml? 
4)what is the best practice used in real time?

any help appreciated

1

1 Answers

0
votes

You need to have separate capabilities for different browsers (each one for Chrome or IE or Firefox) in ur @beforeTest, and you need to write the code to accept the testng.xml parameters so that the respective browsers can run on the node machines...

Normally the test scripts are run by using testng.xml, but the configuration details of each browser, you need to keep them in each node machine you want to run

You need to run the commands/can create bat files in each node machine and run/keep them up before running ur testng.xml.

For more information, you can refer to this link

There are no best practices so far, depending on your need you can customize things, so 1st try the basic steps to run on multiple machines.