Search in sources :

Example 36 with ConfigurationException

use of com.seleniumtests.customexception.ConfigurationException in project seleniumRobot by bhecquet.

the class IDesktopCapabilityFactory method prepareBinaryAndDriver.

/**
 * In local mode, select the right browser info, depending on type, version and binary
 * If several version are available, the highest is selected. This means that if betaVersion option is selected, we will get the beta browser.
 *
 * @param browserType		the browser to select (chrome, firefox, ...)
 * @param binPath			the browser binary to start, if specifically set by user through option. Else, installed browser will be used
 * @param driverPath		user defined driver. if null, default driver will be selected depending on browser and version
 * @param version			user defined version if user needs to start a specific version of the browser and this version is installed
 * @return
 */
private BrowserInfo prepareBinaryAndDriver(final BrowserType browserType, final String binPath, final String driverPath, final String version) {
    // automatic list from OS + binary added as launch option (see SeleniumTestsContext.updateInstalledBrowsers())
    List<BrowserInfo> browserInfos = OSUtility.getInstalledBrowsersWithVersion(webDriverConfig.getBetaBrowser()).get(browserType);
    if (version != null) {
        selectedBrowserInfo = BrowserInfo.getInfoFromVersion(version, browserInfos);
    } else if (binPath != null) {
        selectedBrowserInfo = BrowserInfo.getInfoFromBinary(binPath, browserInfos);
        logger.info("Using user defined browser binary from: " + selectedBrowserInfo.getPath());
    } else {
        for (BrowserInfo browser : browserInfos) {
            if (webDriverConfig.getBetaBrowser().equals(browser.getBeta())) {
                selectedBrowserInfo = browser;
            }
        }
    }
    if (selectedBrowserInfo == null) {
        throw new ConfigurationException(String.format("Browser %s %s is not available", webDriverConfig.getBrowserType(), webDriverConfig.getBetaBrowser() ? "beta" : ""));
    }
    // in case of legacy firefox driverFileName is null
    String newDriverPath = new DriverExtractor().extractDriver(selectedBrowserInfo.getDriverFileName());
    if (driverPath != null) {
        newDriverPath = driverPath;
        logger.info("using user defined driver from: " + driverPath);
    }
    if (newDriverPath != null) {
        System.setProperty(getDriverExeProperty(), newDriverPath);
        if (!OSUtility.isWindows() && !new File(newDriverPath).setExecutable(true)) {
            logger.error(String.format("Error setting executable on driver %s", newDriverPath));
        }
    }
    return selectedBrowserInfo;
}
Also used : ConfigurationException(com.seleniumtests.customexception.ConfigurationException) DriverExtractor(com.seleniumtests.driver.DriverExtractor) File(java.io.File)

Example 37 with ConfigurationException

use of com.seleniumtests.customexception.ConfigurationException in project seleniumRobot by bhecquet.

the class IDesktopCapabilityFactory method configureProxyCap.

/**
 * Add proxy capability
 * If network capture is enabled, start browsermob proxy and set it into browser
 * @param capability
 */
private void configureProxyCap(MutableCapabilities capability) {
    Proxy proxy = webDriverConfig.getProxy();
    if (webDriverConfig.getCaptureNetwork()) {
        if (webDriverConfig.getWebProxyType() != ProxyType.DIRECT && webDriverConfig.getWebProxyType() != ProxyType.MANUAL) {
            throw new ConfigurationException("PAC/AUTODETECT/SYSTEM proxy cannot be used with browsermob proxy");
        }
        BrowserMobProxy mobProxy = new BrowserMobProxyServer();
        if (webDriverConfig.getWebProxyType() == ProxyType.MANUAL) {
            mobProxy.setChainedProxy(new InetSocketAddress(webDriverConfig.getWebProxyAddress(), webDriverConfig.getWebProxyPort()));
            if (webDriverConfig.getWebProxyLogin() != null && webDriverConfig.getWebProxyPassword() != null) {
                mobProxy.chainedProxyAuthorization(webDriverConfig.getWebProxyLogin(), webDriverConfig.getWebProxyPassword(), AuthType.BASIC);
            }
        }
        mobProxy.setTrustAllServers(true);
        mobProxy.enableHarCaptureTypes(CaptureType.REQUEST_CONTENT, CaptureType.REQUEST_HEADERS, CaptureType.RESPONSE_HEADERS);
        mobProxy.start(0);
        Proxy seleniumProxy = ClientUtil.createSeleniumProxy(mobProxy);
        capability.setCapability(CapabilityType.PROXY, seleniumProxy);
        webDriverConfig.setBrowserMobProxy(mobProxy);
    } else {
        capability.setCapability(CapabilityType.PROXY, proxy);
    }
}
Also used : Proxy(org.openqa.selenium.Proxy) BrowserMobProxy(net.lightbody.bmp.BrowserMobProxy) ConfigurationException(com.seleniumtests.customexception.ConfigurationException) InetSocketAddress(java.net.InetSocketAddress) BrowserMobProxy(net.lightbody.bmp.BrowserMobProxy) BrowserMobProxyServer(net.lightbody.bmp.BrowserMobProxyServer)

Example 38 with ConfigurationException

use of com.seleniumtests.customexception.ConfigurationException in project seleniumRobot by bhecquet.

the class SeleniumRobotSnapshotServerConnector method addCurrentTestStepToTestCase.

/**
 * Add the current test case (should have been previously created) to this test session
 */
public void addCurrentTestStepToTestCase(Integer testStepId, Integer testCaseInSessionId) {
    if (testStepId == null || testCaseInSessionId == null) {
        throw new ConfigurationException("Test step and Test case in session must be previously created");
    }
    try {
        // get list of tests associated to this session
        List<String> testSteps = getStepListFromTestCase(testCaseInSessionId);
        if (!testSteps.contains(testStepId.toString())) {
            testSteps.add(testStepId.toString());
        }
        addTestStepsToTestCases(testSteps, testCaseInSessionId);
    } catch (UnirestException | JSONException | SeleniumRobotServerException e) {
        throw new SeleniumRobotServerException("cannot add test step to test case", e);
    }
}
Also used : ConfigurationException(com.seleniumtests.customexception.ConfigurationException) UnirestException(kong.unirest.UnirestException) JSONException(kong.unirest.json.JSONException) SeleniumRobotServerException(com.seleniumtests.customexception.SeleniumRobotServerException)

Example 39 with ConfigurationException

use of com.seleniumtests.customexception.ConfigurationException in project seleniumRobot by bhecquet.

the class SeleniumRobotSnapshotServerConnector method createSnapshot.

/**
 * Create snapshot on server that will be used to show differences between 2 versions of the application
 */
public Integer createSnapshot(Snapshot snapshot, Integer sessionId, Integer testCaseInSessionId, Integer stepResultId) {
    if (!active) {
        return null;
    }
    if (sessionId == null) {
        throw new ConfigurationException("Session must be previously recorded");
    }
    if (testCaseInSessionId == null) {
        throw new ConfigurationException("TestCaseInSession must be previously recorded");
    }
    checkStepResult(stepResultId);
    if (snapshot == null || snapshot.getScreenshot() == null || snapshot.getScreenshot().getFullImagePath() == null) {
        throw new SeleniumRobotServerException("Provided snapshot does not exist");
    }
    String snapshotName = snapshot.getName().length() > MAX_SNAPSHOT_NAME_LENGHT ? snapshot.getName().substring(0, MAX_SNAPSHOT_NAME_LENGHT) : snapshot.getName();
    try {
        File pictureFile = new File(snapshot.getScreenshot().getFullImagePath());
        JSONObject snapshotJson = getJSonResponse(buildPostRequest(url + SNAPSHOT_API_URL).field("stepResult", stepResultId).field("sessionId", sessionUUID).field(FIELD_TEST_CASE, testCaseInSessionId.toString()).field(FIELD_IMAGE, pictureFile).field(FIELD_NAME, snapshotName).field("compare", snapshot.getCheckSnapshot().getName()).field("diffTolerance", String.valueOf(snapshot.getCheckSnapshot().getErrorThreshold())));
        return snapshotJson.getInt("id");
    } catch (UnirestException | JSONException | SeleniumRobotServerException e) {
        throw new SeleniumRobotServerException("cannot create test snapshot", e);
    }
}
Also used : JSONObject(kong.unirest.json.JSONObject) ConfigurationException(com.seleniumtests.customexception.ConfigurationException) UnirestException(kong.unirest.UnirestException) JSONException(kong.unirest.json.JSONException) File(java.io.File) SeleniumRobotServerException(com.seleniumtests.customexception.SeleniumRobotServerException)

Example 40 with ConfigurationException

use of com.seleniumtests.customexception.ConfigurationException in project seleniumRobot by bhecquet.

the class ConfigReader method readConfig.

public Map<String, TestVariable> readConfig(InputStream iniFileStream, String environment) {
    Map<String, TestVariable> testConfig = new HashMap<>();
    try {
        Ini ini = new Ini();
        Config conf = ini.getConfig();
        conf.setGlobalSection(true);
        conf.setGlobalSectionName(GLOBAL_SECTION_NAME);
        conf.setFileEncoding(StandardCharsets.UTF_8);
        ini.setConfig(conf);
        ini.load(iniFileStream);
        Set<Entry<String, Section>> sections = ini.entrySet();
        // first get global options
        testConfig = getGlobalOptions(testConfig, sections);
        // then overwrite global options with local ones
        testConfig = getLocalOptions(testConfig, sections, environment);
        return testConfig;
    } catch (InvalidFileFormatException e) {
        throw new ConfigurationException("Invalid ini/properties file: " + iniFileStream + ", check there is no BOM for encoding");
    } catch (IOException e) {
        throw new ConfigurationException(String.format("File does not exist %s: %s", iniFileStream, e.getMessage()));
    }
}
Also used : InvalidFileFormatException(org.ini4j.InvalidFileFormatException) Entry(java.util.Map.Entry) HashMap(java.util.HashMap) Ini(org.ini4j.Ini) ConfigurationException(com.seleniumtests.customexception.ConfigurationException) Config(org.ini4j.Config) TestVariable(com.seleniumtests.core.TestVariable) IOException(java.io.IOException)

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