Search in sources :

Example 1 with DriverExtractor

use of com.seleniumtests.driver.DriverExtractor in project seleniumRobot by bhecquet.

the class TestDriverExtractor method testDriverNotExtractedAlreadyExists.

/**
 * Driver file already exists with version file up to date
 * @throws IOException
 */
@Test(groups = { "ut" })
public void testDriverNotExtractedAlreadyExists() throws IOException {
    extractor.extractDriver("chromedriver_103.0_chrome-103-104");
    DriverExtractor driverExtractor = spy(new DriverExtractor(rootPath));
    driverExtractor.extractDriver("chromedriver_103.0_chrome-103-104");
    // check driver has not been copied as it already exists in the right version
    verify(driverExtractor, never()).copyDriver("chromedriver_103.0_chrome-103-104");
}
Also used : DriverExtractor(com.seleniumtests.driver.DriverExtractor) Test(org.testng.annotations.Test) MockitoTest(com.seleniumtests.MockitoTest)

Example 2 with DriverExtractor

use of com.seleniumtests.driver.DriverExtractor in project seleniumRobot by bhecquet.

the class TestDriverExtractor method initContext.

@BeforeClass(groups = { "ut" })
public void initContext(final ITestContext testNGCtx) throws Exception {
    initThreadContext(testNGCtx);
    rootPath = SeleniumTestsContextManager.getRootPath() + "/tmp";
    extractor = new DriverExtractor(rootPath);
    driverPath = extractor.getDriverPath();
}
Also used : DriverExtractor(com.seleniumtests.driver.DriverExtractor) BeforeClass(org.testng.annotations.BeforeClass)

Example 3 with DriverExtractor

use of com.seleniumtests.driver.DriverExtractor in project seleniumRobot by bhecquet.

the class AppiumDriverFactory method extractAndroidDriver.

private void extractAndroidDriver(MutableCapabilities capabilities) {
    String chromeDriverFile = (String) capabilities.getCapability(AndroidMobileCapabilityType.CHROMEDRIVER_EXECUTABLE);
    if (chromeDriverFile != null) {
        String driverPath;
        try {
            driverPath = FileUtility.decodePath(new DriverExtractor().extractDriver(chromeDriverFile));
            capabilities.setCapability(AndroidMobileCapabilityType.CHROMEDRIVER_EXECUTABLE, driverPath);
        } catch (UnsupportedEncodingException e) {
            logger.error("cannot get driver path", e);
        }
    }
}
Also used : DriverExtractor(com.seleniumtests.driver.DriverExtractor) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 4 with DriverExtractor

use of com.seleniumtests.driver.DriverExtractor 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 5 with DriverExtractor

use of com.seleniumtests.driver.DriverExtractor in project seleniumRobot by bhecquet.

the class TestDriverExtractor method testDriverNotExtractedAlreadyExistsNoVersion.

/**
 * driver extracted as version file does not exist
 * @throws IOException
 */
@Test(groups = { "ut" })
public void testDriverNotExtractedAlreadyExistsNoVersion() throws IOException {
    extractor.extractDriver("chromedriver_103.0_chrome-103-104");
    // remove version to force copy
    Paths.get(driverPath.toString(), "version_chromedriver_103.0_chrome-103-104.txt").toFile().delete();
    DriverExtractor driverExtractor = spy(new DriverExtractor(rootPath));
    driverExtractor.extractDriver("chromedriver_103.0_chrome-103-104");
    // check driver has been copied as it already exists but no version has been specified
    verify(driverExtractor).copyDriver("chromedriver_103.0_chrome-103-104");
}
Also used : DriverExtractor(com.seleniumtests.driver.DriverExtractor) Test(org.testng.annotations.Test) MockitoTest(com.seleniumtests.MockitoTest)

Aggregations

DriverExtractor (com.seleniumtests.driver.DriverExtractor)5 MockitoTest (com.seleniumtests.MockitoTest)2 Test (org.testng.annotations.Test)2 ConfigurationException (com.seleniumtests.customexception.ConfigurationException)1 File (java.io.File)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 BeforeClass (org.testng.annotations.BeforeClass)1