Search in sources :

Example 21 with ConfigurationException

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));
    }
}
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 22 with ConfigurationException

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());
    }
}
Also used : HttpResponse(kong.unirest.HttpResponse) MobileCapabilityType(io.appium.java_client.remote.MobileCapabilityType) IOException(java.io.IOException) Capabilities(org.openqa.selenium.Capabilities) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) Unirest(kong.unirest.Unirest) File(java.io.File) SeleniumTestsContextManager(com.seleniumtests.core.SeleniumTestsContextManager) Matcher(java.util.regex.Matcher) JsonNode(kong.unirest.JsonNode) ConfigurationException(com.seleniumtests.customexception.ConfigurationException) UnirestInstance(kong.unirest.UnirestInstance) Pattern(java.util.regex.Pattern) AuthenticationException(org.apache.http.auth.AuthenticationException) UnirestException(kong.unirest.UnirestException) DriverConfig(com.seleniumtests.driver.DriverConfig) UnirestInstance(kong.unirest.UnirestInstance) Matcher(java.util.regex.Matcher) ConfigurationException(com.seleniumtests.customexception.ConfigurationException) UnirestException(kong.unirest.UnirestException) JsonNode(kong.unirest.JsonNode) File(java.io.File)

Example 23 with ConfigurationException

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;
}
Also used : ConfigurationException(com.seleniumtests.customexception.ConfigurationException) Capabilities(org.openqa.selenium.Capabilities) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities)

Example 24 with ConfigurationException

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());
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) ConfigurationException(com.seleniumtests.customexception.ConfigurationException) DriverExceptions(com.seleniumtests.customexception.DriverExceptions) MutableCapabilities(org.openqa.selenium.MutableCapabilities) AndroidDriver(io.appium.java_client.android.AndroidDriver) WebElement(org.openqa.selenium.WebElement) URL(java.net.URL)

Example 25 with ConfigurationException

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;
}
Also used : ConfigurationException(com.seleniumtests.customexception.ConfigurationException) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities)

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