use of com.seleniumtests.customexception.ConfigurationException in project seleniumRobot by bhecquet.
the class BrowserExtension method setOptions.
/**
* Sets extension options: Browser extension options must have the format: <key1>=<value1>;<key2>=<value2>
* @param userOptions
*/
public void setOptions(String userOptions) {
options = new HashMap<>();
for (String option : userOptions.split(";")) {
try {
String[] optionValue = option.split("=");
options.put(optionValue[0], optionValue[1]);
} catch (IndexOutOfBoundsException e) {
throw new ConfigurationException("Browser extension options must have the format: <key1>=<value1>;<key2>=<value2>");
}
}
}
use of com.seleniumtests.customexception.ConfigurationException in project seleniumRobot by bhecquet.
the class BrowserInfo method getChromiumDriverVersion.
/**
* Get version from chromium based browsers (chrome, edge)
* @param driverFiles
* @param versionRegex
* @return
*/
private Map<Integer, String> getChromiumDriverVersion(List<String> driverFiles, Pattern versionRegex) {
Map<Integer, String> driverVersion = new HashMap<>();
for (String fileName : driverFiles) {
Matcher matcher = versionRegex.matcher(fileName);
if (matcher.matches()) {
int minVersion = Integer.parseInt(matcher.group(1));
int maxVersion = Integer.parseInt(matcher.group(2));
if (maxVersion < minVersion) {
throw new ConfigurationException(String.format("Chrome driver file %s version is incorrect, max version should be > to min version", fileName));
} else {
for (int i = minVersion; i <= maxVersion; i++) {
driverVersion.put(i, fileName);
}
}
} else {
throw new ConfigurationException(String.format("Driver %s is excluded as it does not match the pattern 'chromedriver_<version>_chrome-<minVersion>-<maxVersion>'", fileName));
}
}
return driverVersion;
}
use of com.seleniumtests.customexception.ConfigurationException in project seleniumRobot by bhecquet.
the class BrowserInfo method addChromeDriverFile.
/**
* Find the most suitable driver when using chrome browser
* @throws IOException
*/
private void addChromeDriverFile() throws IOException {
List<String> driverFiles = getDriverFiles();
driverFiles = driverFiles.stream().filter(s -> s.contains("chrome-") && s.startsWith("chromedriver_")).map(s -> s.replace(".exe", "")).sorted().collect(Collectors.toList());
if (driverFiles.isEmpty()) {
throw new ConfigurationException("no chromedriver in resources");
}
Map<Integer, String> driverVersion = getChromiumDriverVersion(driverFiles, REG_CHROME_VERSION);
int chromeVersion = Integer.parseInt(version.split("\\.")[0]);
driverFileName = driverVersion.get(chromeVersion);
// when chrome version is greater than driver version, take the last driver and display warning as something may go wrong
if (driverFileName == null && chromeVersion > Collections.max(driverVersion.keySet())) {
driverFileName = driverFiles.get(driverFiles.size() - 1);
logger.warn("--------------------------------------------------------------------");
logger.warn(String.format("Chrome version %d does not have any associated driver, update seleniumRobot version, the latest driver has been used", chromeVersion));
logger.warn("--------------------------------------------------------------------");
} else if (driverFileName == null) {
throw new ConfigurationException(String.format("Chrome version %d does not have any associated driver, update seleniumRobot version", chromeVersion));
}
}
use of com.seleniumtests.customexception.ConfigurationException in project seleniumRobot by bhecquet.
the class LocalAppiumLauncher method checkAppiumVersion.
private void checkAppiumVersion() {
try {
File packageFile = Paths.get(appiumHome, "node_modules", "appium", "package.json").toFile();
String appiumConfig = FileUtils.readFileToString(packageFile);
JSONObject packages = new JSONObject(appiumConfig);
if (!"appium".equals(packages.getString("name"))) {
throw new ConfigurationException(String.format("package.json file found in %s is not for appium, check path", packageFile.getAbsolutePath()));
}
appiumVersion = packages.getString("version");
} catch (IOException e) {
throw new ConfigurationException("File package.json not found, appium does not seem to be installed in " + appiumHome, e);
}
}
use of com.seleniumtests.customexception.ConfigurationException in project seleniumRobot by bhecquet.
the class PerfectoCapabilitiesFactory method extractCloudName.
private String extractCloudName() {
List<String> hubUrls = webDriverConfig.getHubUrl();
if (hubUrls.isEmpty() || !hubUrls.get(0).contains(".perfectomobile.com/nexperience/perfectomobile/wd/hub")) {
throw new ConfigurationException("Perfecto usage needs configuring 'webDriverGrid' parameter with the format 'https://<apikey>@<cloudName>.perfectomobile.com/nexperience/perfectomobile/wd/hub'");
}
String hubUrl = hubUrls.get(0);
Matcher cloudNameMatcher = CLOUD_NAME_PATTERN.matcher(hubUrl);
if (cloudNameMatcher.matches()) {
return cloudNameMatcher.group(2);
}
return "";
}
Aggregations