使用selenium grid& amp ;;在多个浏览器上运行测试TestNG的

时间:2015-05-29 08:58:17

标签: testng selenium-grid

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

以下是测试脚本的代码:

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?

任何帮助表示赞赏

1 个答案:

答案 0 :(得分:0)

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

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

您需要运行命令/可以在每个节点机器中创建bat文件,并在运行ur testng.xml之前运行/保留它们。

有关详细信息,请参阅此link

目前还没有最佳做法,根据您的需要,您可以自定义内容,因此请先尝试在多台计算机上运行的基本步骤。

相关问题