使用Selenium grid在多个浏览器上运行测试&testNG



我正在探索在多个浏览器上执行测试的selenium grid。我已经按照在线教程配置了集线器和节点。我创建了一个测试脚本。

下面是测试脚本的代码:
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();
  }
}

我的目标是在多个浏览器上运行这个测试我已经添加了所需的功能,如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?

感谢您的帮助

您需要在ur @beforeTest中为不同的浏览器(每个浏览器用于Chrome或IE或Firefox)提供单独的功能,并且您需要编写代码以接受testng.xml参数,以便各自的浏览器可以在节点机器上运行…

通常测试脚本是通过使用test .xml运行的,但是每个浏览器的配置细节,您需要将它们保存在您想要运行的每个节点机器中

您需要运行命令/可以在每个节点机器上创建bat文件,并在运行我们的test .xml之前运行/保持它们。

有关更多信息,请参阅此链接

到目前为止还没有最佳实践,根据您的需要您可以定制一些东西,所以首先尝试在多台机器上运行基本步骤。

最新更新