我有一个.properties文件,该文件提供用于实例化ServiceHooks类中的WebDriver的输入数据。 如何更改此逻辑以使用Cucumber .feature文件来驱动我提供给WebDriver的参数并实现这种情况?
Feature: Login page navigation
Scenario Outline: User navigates to url
Given I open the browser <browser> on operatingSystem <platform>
When I navigate to url <url>
Then I see the login page
Examples:
|browser|platform| url |
|"firefox"|"windows"|"https://loginpage.com"|
|"chrome"| "windows" |"https://loginpage.com"|
我有一些代码可以评估驱动程序是否是远程的,并在执行测试方案之前实例化驱动程序(因此已经打开浏览器)。
public class ServiceHooks {
public static WebDriver driver;
public void getDriverInstance() {
//if isRemoteDriver evaluests to true or false base on a .properties file
if (isRemoteDriver.equals("yes")){
driver = getRemoteDriverInstance(platform, browser, url);
} else {
driver = getLocalDriverInstance(platform, browser, url);
}
//platform, browser, url are served from the .properties file as well
public WebDriver getLocalDriverInstance(String platform, String browser, String url)
throws MalformedURLException {
WebDriver localDriver = null;
DesiredCapabilities capabilities = new DesiredCapabilities();
//ChromeOptions options = new ChromeOptions();
// Platforms
if (platform.equalsIgnoreCase("Windows")) {
capabilities.setPlatform(Platform.WINDOWS);
}
if (platform.equalsIgnoreCase("MAC")) {
capabilities.setPlatform(Platform.MAC);
}
// Browsers
if (browser.equalsIgnoreCase("chrome")) {
capabilities = DesiredCapabilities.chrome();
localDriver = new ChromeDriver();
}
if (browser.equalsIgnoreCase("firefox")) {
capabilities = DesiredCapabilities.firefox();
localDriver = new FirefoxDriver();
}
if (browser.equalsIgnoreCase("ie")) {
capabilities = DesiredCapabilities.internetExplorer();
localDriver = new InternetExplorerDriver();
}
localDriver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
localDriver.manage().window().maximize();
localDriver.get(url);
return localDriver;
}
public static WebDriver getRemoteDriverInstance(String platform, String browser, String url)
throws MalformedURLException {
String nodeURL = "http://localhost:4444/wd/hub";
WebDriver remoteDriver = null;
DesiredCapabilities capabilities = new DesiredCapabilities();
// Platforms
if (platform.equalsIgnoreCase("Windows")) {
capabilities.setPlatform(Platform.WINDOWS);
}
if (platform.equalsIgnoreCase("MAC")) {
capabilities.setPlatform(Platform.MAC);
}
// Browsers
if (browser.equalsIgnoreCase("chrome")) {
capabilities = DesiredCapabilities.chrome();
}
if (browser.equalsIgnoreCase("firefox")) {
capabilities = DesiredCapabilities.firefox();
}
if (browser.equalsIgnoreCase("ie")) {
capabilities = DesiredCapabilities.internetExplorer();
}
// Open the Application
remoteDriver = new RemoteWebDriver(new URL(nodeURL), capabilities);
remoteDriver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
remoteDriver.manage().window().maximize();
remoteDriver.get(url);
return remoteDriver;
}
}
我希望能够使用WebDriver在本地以及通过Selenium Grid远程运行提到的黄瓜测试方案。