Search in sources :

Example 31 with ConfigurationException

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>");
        }
    }
}
Also used : ConfigurationException(com.seleniumtests.customexception.ConfigurationException)

Example 32 with ConfigurationException

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;
}
Also used : HashMap(java.util.HashMap) Matcher(java.util.regex.Matcher) ConfigurationException(com.seleniumtests.customexception.ConfigurationException)

Example 33 with ConfigurationException

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));
    }
}
Also used : Win32Exception(com.sun.jna.platform.win32.Win32Exception) HashMap(java.util.HashMap) OSUtility(com.seleniumtests.util.osutility.OSUtility) ArrayList(java.util.ArrayList) Logger(org.apache.log4j.Logger) Matcher(java.util.regex.Matcher) SeleniumRobotLogger(com.seleniumtests.util.logging.SeleniumRobotLogger) ConfigurationException(com.seleniumtests.customexception.ConfigurationException) Map(java.util.Map) ManagementFactory(java.lang.management.ManagementFactory) WinReg(com.sun.jna.platform.win32.WinReg) Path(java.nio.file.Path) Files(java.nio.file.Files) Platform(org.openqa.selenium.Platform) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) BrowserType(com.seleniumtests.driver.BrowserType) OSUtilityFactory(com.seleniumtests.util.osutility.OSUtilityFactory) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) Stream(java.util.stream.Stream) Paths(java.nio.file.Paths) Advapi32Util(com.sun.jna.platform.win32.Advapi32Util) Pattern(java.util.regex.Pattern) Collections(java.util.Collections) ConfigurationException(com.seleniumtests.customexception.ConfigurationException)

Example 34 with ConfigurationException

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);
    }
}
Also used : JSONObject(org.json.JSONObject) ConfigurationException(com.seleniumtests.customexception.ConfigurationException) IOException(java.io.IOException) File(java.io.File)

Example 35 with ConfigurationException

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 "";
}
Also used : ConfigurationException(com.seleniumtests.customexception.ConfigurationException) Matcher(java.util.regex.Matcher)

Aggregations

ConfigurationException (com.seleniumtests.customexception.ConfigurationException)66 ArrayList (java.util.ArrayList)19 File (java.io.File)18 IOException (java.io.IOException)14 HashMap (java.util.HashMap)13 Test (org.testng.annotations.Test)13 Matcher (java.util.regex.Matcher)9 List (java.util.List)8 UnirestException (kong.unirest.UnirestException)8 GenericTest (com.seleniumtests.GenericTest)7 SeleniumRobotServerException (com.seleniumtests.customexception.SeleniumRobotServerException)7 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)6 ScenarioException (com.seleniumtests.customexception.ScenarioException)5 BrowserType (com.seleniumtests.driver.BrowserType)5 Map (java.util.Map)5 Pattern (java.util.regex.Pattern)5 Collectors (java.util.stream.Collectors)5 Win32Exception (com.sun.jna.platform.win32.Win32Exception)4 StandardCharsets (java.nio.charset.StandardCharsets)4 Files (java.nio.file.Files)4