Я так полагаю из pom’a нужен только профиль?
<profile>
<id>stand_ie11</id>
<properties>
<env>stand_ie11</env>
<user.username></user.username>
<user.password></user.password>
<grid2.hub>http://wsus2003:4444/wd/hub</grid2.hub>
<site.url>http://vm-go1:9080/ccee/LoginScreen.jsp</site.url>
<browser.name>internet exlporer</browser.name>
<browser.version>11</browser.version>
<browser.platform></browser.platform>
</properties>
</profile>
Запуск драйевра реализован так:
@BeforeClass
public void init() {
baseUrl = PropertyLoader.loadProperty("site.url");
gridHubUrl = PropertyLoader.loadProperty("grid2.hub");
browser = new Browser();
browser.setName(PropertyLoader.loadProperty("browser.name"));
browser.setVersion(PropertyLoader.loadProperty("browser.version"));
browser.setPlatform(PropertyLoader.loadProperty("browser.platform"));
String username = PropertyLoader.loadProperty("user.username");
String password = PropertyLoader.loadProperty("user.password");
driver = WebDriverFactory.getInstance(gridHubUrl, browser, username,
password);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
Вот WebDriverFactory:
public static WebDriver getInstance(String gridHubUrl, Browser browser,
String username, String password) {
WebDriver webDriver = null;
DesiredCapabilities capability = new DesiredCapabilities();
String browserName = browser.getName();
capability.setJavascriptEnabled(true);
// In case there is no Hub
if (gridHubUrl == null || gridHubUrl.length() == 0) {
return getInstance(browserName, username, password);
}
if (CHROME.equals(browserName)) {
capability = DesiredCapabilities.chrome();
} else if (FIREFOX.equals(browserName)) {
capability = DesiredCapabilities.firefox();
FirefoxProfile ffProfile = new FirefoxProfile();
// Authenication Hack for Firefox
if (username != null && password != null) {
ffProfile.setPreference("network.http.phishy-userpass-length",
255);
capability.setCapability(FirefoxDriver.PROFILE, ffProfile);
}
capability.setCapability(CapabilityType.TAKES_SCREENSHOT, true);
} else if (INTERNET_EXPLORER.equals(browserName)) {
capability = DesiredCapabilities.internetExplorer();
capability
.setCapability(
InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,
true);
} else if (PHANTOMJS.equals(browserName)) {
capability = DesiredCapabilities.phantomjs();
} else if (OPERA.equals(browserName)) {
capability = DesiredCapabilities.opera();
} else if (SAFARI.equals(browserName)) {
capability = DesiredCapabilities.safari();
} else {
capability = DesiredCapabilities.htmlUnit();
// HTMLunit Check
if (username != null && password != null) {
webDriver = (HtmlUnitDriver) AuthenticatedHtmlUnitDriver
.create(username, password);
} else {
webDriver = new HtmlUnitDriver(true);
}
return webDriver;
}
capability = setVersionAndPlatform(capability, browser.getVersion(),
browser.getPlatform());
// Create Remote WebDriver
try {
webDriver = new RemoteWebDriver(new URL(gridHubUrl), capability);
} catch (MalformedURLException e) {
e.printStackTrace();
}
return webDriver;
}
Смысл в том что если в <grid2.hub> указать неправильный IP, затем запускаю тесты командой mvn test -P stand_ie11
- то я ожидаю что будет какая-то ошибка, типа “Сервер не отвечает” или что-то в этом роде, а на деле вот результат:
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running TestSuite
...
... TestNG 6.8.9beta by C?dric Beust (cedric@beust.com)
...
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 6.611 sec - in TestSuite