Selenium测试框架中使用grid
然后在DriverFactory里创建getRemoteDriver
1 /**
2 * This method will create RemoteWebdriver
3 * @author Young
4 * @param remoteBrowserBean
5 * @return WebDriver
6 */
7 public static WebDriver getRemoteDriver(RemoteBrowserBean remoteBrowserBean) {
8 DesiredCapabilities capability = null;
9 if (remoteBrowserBean.getBrowserName().contains("firefox")) {
10 capability = DesiredCapabilities.firefox();
11 } else if (remoteBrowserBean.getBrowserName().contains("chrome")) {
12 capability = DesiredCapabilities.chrome();
13 }
14
15 WebDriver driver = null;
16 try {
17 driver = new RemoteWebDriver(
18 new URL(remoteBrowserBean.getHubURL()), capability);
19 } catch (MalformedURLException e) {
20 e.printStackTrace();
21 }
22 capability.setBrowserName(remoteBrowserBean.getBrowserName());
23 capability.setVersion(remoteBrowserBean.getVersion());
24 capability.setCapability(remoteBrowserBean.getPlatform()[0],
25 remoteBrowserBean.getPlatform()[1]);
26 driver.manage().window().maximize();
27 return driver;
28 }
接下来可以在case里边使用
1 @BeforeClass(alwaysRun=true)
2 public void beforeTest()
3 {
4 driver = DriverFactory.getRemoteDriver(new RemoteBrowserBean("chrome"));
5 }