use of com.seleniumtests.customexception.ConfigurationException in project seleniumRobot by bhecquet.
the class BrowserInfo method addEdgeDriverFile.
/**
* Edge driver depends on windows build
* @throws IOException
*/
private void addEdgeDriverFile() throws IOException {
List<String> driverFiles = getDriverFiles();
driverFiles = driverFiles.stream().filter(s -> s.contains("edge-") && s.startsWith("edgedriver_")).map(s -> s.replace(".exe", "")).sorted().collect(Collectors.toList());
if (driverFiles.isEmpty()) {
throw new ConfigurationException("no edgedriver in resources");
}
Map<Integer, String> driverVersion = getChromiumDriverVersion(driverFiles, REG_EDGE_VERSION);
int edgeVersion = Integer.parseInt(version.split("\\.")[0]);
driverFileName = driverVersion.get(edgeVersion);
// when chrome version is greater than driver version, take the last driver and display warning as something may go wrong
if (driverFileName == null && edgeVersion > Collections.max(driverVersion.keySet())) {
driverFileName = driverFiles.get(driverFiles.size() - 1);
logger.warn("--------------------------------------------------------------------");
logger.warn(String.format("Edge version %d does not have any associated driver, update seleniumRobot driver version, the latest driver has been used", edgeVersion));
logger.warn("--------------------------------------------------------------------");
} else if (driverFileName == null) {
throw new ConfigurationException(String.format("Edge version %d does not have any associated driver, update seleniumRobot driver version", edgeVersion));
}
}
use of com.seleniumtests.customexception.ConfigurationException in project seleniumRobot by bhecquet.
the class BrowserStackCapabilitiesFactory method uploadFile.
/**
* Upload application to saucelabs server
* @param targetAppPath
* @param serverURL
* @return
* @throws IOException
* @throws AuthenticationException
*/
private String uploadFile(String application) {
// extract user name and password from getWebDriverGrid
Matcher matcher = REG_USER_PASSWORD.matcher(SeleniumTestsContextManager.getThreadContext().getWebDriverGrid().get(0));
String user;
String password;
if (matcher.matches()) {
user = matcher.group(1);
password = matcher.group(2);
} else {
throw new ConfigurationException("webDriverGrid variable does not have the right format for connecting to sauceLabs: \"https://<user>:<token>@hub.browserstack.com/wd/hub\"");
}
try (UnirestInstance unirest = Unirest.spawnInstance()) {
String proxyHost = System.getProperty("https.proxyHost");
String proxyPort = System.getProperty("https.proxyPort");
if (proxyHost != null && proxyPort != null) {
unirest.config().proxy(proxyHost, Integer.valueOf(proxyPort));
}
HttpResponse<JsonNode> jsonResponse = unirest.post(BROWSERSTACK_UPLOAD_URL).basicAuth(user, password).field("file", new File(application)).asJson().ifFailure(response -> {
throw new ConfigurationException(String.format("Application file upload failed: %s", response.getStatusText()));
}).ifSuccess(response -> {
logger.info("Application successfuly uploaded to Saucelabs");
});
return jsonResponse.getBody().getObject().getString("app_url");
} catch (UnirestException e) {
throw new ConfigurationException("Application file upload failed: " + e.getMessage());
}
}
use of com.seleniumtests.customexception.ConfigurationException in project seleniumRobot by bhecquet.
the class BrowserStackCapabilitiesFactory method createCapabilities.
@Override
public DesiredCapabilities createCapabilities() {
final DesiredCapabilities capabilities = new DesiredCapabilities();
// platform must be the concatenation of 'os' and 'os_version' that browserstack undestands
String platform = webDriverConfig.getPlatform();
String platformVersion = null;
String platformName = null;
if (SeleniumTestsContextManager.isMobileTest()) {
if (ANDROID_PLATFORM.equalsIgnoreCase(webDriverConfig.getPlatform())) {
Capabilities androidCaps = new AndroidCapabilitiesFactory(webDriverConfig).createCapabilities();
capabilities.merge(androidCaps);
capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, "UIAutomator2");
} else if (IOS_PLATFORM.equalsIgnoreCase(webDriverConfig.getPlatform())) {
Capabilities iosCaps = new IOsCapabilitiesFactory(webDriverConfig).createCapabilities();
capabilities.merge(iosCaps);
}
// pour deviceName
capabilities.setCapability("device", webDriverConfig.getDeviceName());
capabilities.setCapability("realMobile", "true");
capabilities.setCapability("os_version", webDriverConfig.getMobilePlatformVersion());
capabilities.setCapability("os", webDriverConfig.getPlatform());
} else {
if (platform.toLowerCase().startsWith("windows")) {
platformVersion = platform.toLowerCase().replace("windows", "").trim();
platformName = "Windows";
} else if (platform.toLowerCase().startsWith("os x")) {
platformVersion = platform.toLowerCase().replace("os x", "").trim();
platformName = "OS X";
} else {
throw new ConfigurationException("Only Windows and Mac are supported desktop platforms ('Windows xxx' or 'OS X xxx'). See https://www.browserstack.com/automate/capabilities for details. 'platform' param is " + platform);
}
if (webDriverConfig.getBrowserVersion() != null) {
capabilities.setCapability("browser_version", webDriverConfig.getBrowserVersion());
}
capabilities.setCapability("os", platformName);
capabilities.setCapability("os_version", platformVersion);
}
capabilities.setCapability("browserName", webDriverConfig.getBrowserType());
capabilities.setCapability("name", SeleniumTestsContextManager.getThreadContext().getTestMethodSignature());
capabilities.setCapability("project", SeleniumTestsContextManager.getApplicationName());
// we need to upload something
if (capabilities.getCapability(MobileCapabilityType.APP) != null) {
String appUrl = uploadFile((String) capabilities.getCapability(MobileCapabilityType.APP));
capabilities.setCapability("app", appUrl);
}
return capabilities;
}
use of com.seleniumtests.customexception.ConfigurationException in project seleniumRobot by bhecquet.
the class AppiumDriverFactory method createNativeDriver.
@Override
protected WebDriver createNativeDriver() {
// start appium
appiumLauncher = AppiumLauncherFactory.getInstance();
appiumLauncher.startAppium();
try {
MutableCapabilities capabilities = getMobileCapabilities();
if (ANDROID_PLATORM.equalsIgnoreCase(webDriverConfig.getPlatform())) {
extractAndroidDriver(capabilities);
return new AndroidDriver<WebElement>(new URL(appiumLauncher.getAppiumServerUrl()), capabilities);
} else if ("ios".equalsIgnoreCase(webDriverConfig.getPlatform())) {
return new IOSDriver<WebElement>(new URL(appiumLauncher.getAppiumServerUrl()), capabilities);
} else {
throw new ConfigurationException(String.format("Platform %s is unknown for Appium tests", webDriverConfig.getPlatform()));
}
} catch (MalformedURLException e) {
throw new DriverExceptions("Error creating driver: " + e.getMessage());
}
}
use of com.seleniumtests.customexception.ConfigurationException in project seleniumRobot by bhecquet.
the class IDesktopCapabilityFactory method updateDefaultCapabilities.
private MutableCapabilities updateDefaultCapabilities() {
DesiredCapabilities capability = new DesiredCapabilities();
capability.setJavascriptEnabled(webDriverConfig.isEnableJavascript());
capability.setCapability(CapabilityType.TAKES_SCREENSHOT, true);
capability.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
// ACCEPT_INSECURE_CERTS is not permitted for IE
if (webDriverConfig.getBrowserType() != BrowserType.INTERNET_EXPLORER) {
capability.setCapability(CapabilityType.ACCEPT_INSECURE_CERTS, webDriverConfig.isSetAcceptUntrustedCertificates());
} else {
capability.setCapability(CapabilityType.ACCEPT_INSECURE_CERTS, false);
}
if (webDriverConfig.getBrowserVersion() != null) {
capability.setCapability(CapabilityType.BROWSER_VERSION, webDriverConfig.getBrowserVersion());
}
if (webDriverConfig.getWebPlatform() != null) {
capability.setPlatform(webDriverConfig.getWebPlatform());
capability.setCapability(CapabilityType.PLATFORM_NAME, webDriverConfig.getWebPlatform());
}
configureProxyCap(capability);
// NEOLOAD //
if (webDriverConfig.isNeoloadActive()) {
if ("Design".equals(System.getProperty("nl.selenium.proxy.mode"))) {
logger.warn("Enabling Neoload Design mode automatically configures a manual proxy through neoload instance, other proxy settings are overriden and network capture won't be possible");
}
try {
capability = NLWebDriverFactory.addProxyCapabilitiesIfNecessary(capability);
} catch (ExceptionInInitializerError e) {
throw new ConfigurationException("Error while contacting Neoload Design API", e);
} catch (RuntimeException e) {
throw new ConfigurationException("Error while getting neoload project, check license and loaded project", e);
}
}
return capability;
}
Aggregations