使用selenium grid&;在多个浏览器上运行测试;testNG
我正在探索selenium网格,以便在多个浏览器上执行测试。我已经按照在线教程配置了中心和节点。我已经创建了一个测试脚本 以下是测试脚本的代码:使用selenium grid&;在多个浏览器上运行测试;testNG,testng,selenium-grid,Testng,Selenium Grid,我正在探索selenium网格,以便在多个浏览器上执行测试。我已经按照在线教程配置了中心和节点。我已经创建了一个测试脚本 以下是测试脚本的代码: public class SeleniumGridTest { WebDriver driver; String baseUrl, nodeUrl; static FirefoxProfile myprofile; @BeforeTest public void beforeTest() throws MalformedURLEx
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参数,以便相应的浏览器可以在节点计算机上运行 通常使用testng.xml运行测试脚本, 但是每个浏览器的配置详细信息,您需要将它们保存在要运行的每个节点计算机中 在运行ur testng.xml之前,您需要运行命令/可以在每个节点计算机中创建bat文件,并运行/保持这些文件 有关更多信息,请参阅此 到目前为止还没有最佳实践,根据您的需要,您可以自定义内容,因此首先尝试在多台计算机上运行的基本步骤