Search in sources :

Example 31 with BrowserInfo

use of com.seleniumtests.browserfactory.BrowserInfo in project seleniumRobot by bhecquet.

the class WebUIDriver method checkBrowserRunnable.

private void checkBrowserRunnable() {
    if (config.getMode() == DriverMode.LOCAL && !config.getTestType().isMobile()) {
        Map<BrowserType, List<BrowserInfo>> browsers = OSUtility.getInstalledBrowsersWithVersion(config.getBetaBrowser());
        if (!browsers.containsKey(config.getBrowserType()) || browsers.get(config.getBrowserType()).isEmpty()) {
            throw new ConfigurationException(String.format("Browser %s is not available. Available browsers are %s", config.getBrowserType(), browsers));
        }
        boolean browserFound = false;
        for (BrowserInfo browserInfo : browsers.get(config.getBrowserType())) {
            if (config.getBetaBrowser().equals(browserInfo.getBeta())) {
                browserFound = true;
                break;
            }
        }
        if (!browserFound) {
            throw new ConfigurationException(String.format("Browser %s %s is not available. Available browsers are %s", config.getBrowserType(), config.getBetaBrowser() ? "beta" : "", browsers));
        }
    }
}
Also used : ConfigurationException(com.seleniumtests.customexception.ConfigurationException) BrowserInfo(com.seleniumtests.browserfactory.BrowserInfo) List(java.util.List) ArrayList(java.util.ArrayList)

Example 32 with BrowserInfo

use of com.seleniumtests.browserfactory.BrowserInfo in project seleniumRobot by bhecquet.

the class OSUtilityWindows method discoverInstalledBrowsersWithVersion.

@Override
public Map<BrowserType, List<BrowserInfo>> discoverInstalledBrowsersWithVersion(boolean discoverBetaBrowsers) {
    Map<BrowserType, List<BrowserInfo>> browserList = new EnumMap<>(BrowserType.class);
    browserList.put(BrowserType.HTMLUNIT, Arrays.asList(new BrowserInfo(BrowserType.HTMLUNIT, BrowserInfo.LATEST_VERSION, null)));
    browserList.put(BrowserType.PHANTOMJS, Arrays.asList(new BrowserInfo(BrowserType.PHANTOMJS, BrowserInfo.LATEST_VERSION, null)));
    // look for Firefox
    try {
        browserList.put(BrowserType.FIREFOX, new ArrayList<>());
        for (String firefoxPath : searchFirefoxVersions()) {
            String version = getFirefoxVersion(firefoxPath);
            try {
                browserList.get(BrowserType.FIREFOX).add(new BrowserInfo(BrowserType.FIREFOX, extractFirefoxVersion(version), firefoxPath));
            } catch (ConfigurationException e) {
            // ignore
            }
        }
    } catch (IndexOutOfBoundsException e) {
    // ignore
    }
    // look for chrome
    try {
        browserList.put(BrowserType.CHROME, new ArrayList<>());
        // main chrome version
        String chromePath = Advapi32Util.registryGetStringValue(WinReg.HKEY_LOCAL_MACHINE, "Software\\Classes\\ChromeHTML\\shell\\open\\command", "");
        chromePath = chromePath.split(EXE_EXT_QUOTE)[0].replace("\"", "") + ".exe";
        String version = getWindowsChromeVersion(chromePath);
        browserList.get(BrowserType.CHROME).add(new BrowserInfo(BrowserType.CHROME, extractChromeVersion("Google Chrome " + version), false, chromePath));
    } catch (Win32Exception | ConfigurationException e) {
        logger.warn("Error searching chrome installations: " + e.getMessage());
    }
    try {
        // beta chrome version
        String chromeBetaPath = Advapi32Util.registryGetStringValue(WinReg.HKEY_LOCAL_MACHINE, "Software\\Classes\\ChromeBHTML\\shell\\open\\command", "");
        chromeBetaPath = chromeBetaPath.split(EXE_EXT_QUOTE)[0].replace("\"", "") + ".exe";
        String versionBeta;
        versionBeta = getWindowsBetaChromeVersion(chromeBetaPath);
        browserList.get(BrowserType.CHROME).add(new BrowserInfo(BrowserType.CHROME, extractChromeVersion("Google Chrome " + versionBeta), true, chromeBetaPath));
    } catch (Win32Exception | ConfigurationException e) {
        logger.warn("Error searching Beta chrome installations: " + e.getMessage());
    }
    // look for ie
    try {
        Advapi32Util.registryGetStringValue(WinReg.HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\IEXPLORE.EXE", "");
        String version = getIeVersionFromRegistry();
        browserList.put(BrowserType.INTERNET_EXPLORER, Arrays.asList(new BrowserInfo(BrowserType.INTERNET_EXPLORER, extractIEVersion(version), null)));
    } catch (Win32Exception | ConfigurationException e) {
        logger.warn("Error searching Internet explorer installations: " + e.getMessage());
    }
    // look for edge chromium
    try {
        browserList.put(BrowserType.EDGE, new ArrayList<>());
        String edgePath = Advapi32Util.registryGetStringValue(WinReg.HKEY_LOCAL_MACHINE, "Software\\WOW6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Microsoft Edge", "InstallLocation");
        String version = getWindowsEdgeVersion(edgePath);
        if (version != null && !version.isEmpty()) {
            browserList.get(BrowserType.EDGE).add(new BrowserInfo(BrowserType.EDGE, extractEdgeVersion(version), false, Paths.get(edgePath, MSEDGE_EXE).toString()));
        }
    } catch (Win32Exception | ConfigurationException e) {
        logger.warn("Error searching Edge chromium installations: " + e.getMessage());
    }
    try {
        // beta edge version
        String edgePathBeta = Advapi32Util.registryGetStringValue(WinReg.HKEY_LOCAL_MACHINE, "Software\\WOW6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Microsoft Edge Beta", "InstallLocation");
        String versionBeta = getWindowsBetaEdgeVersion(edgePathBeta);
        if (versionBeta != null && !versionBeta.isEmpty()) {
            browserList.get(BrowserType.EDGE).add(new BrowserInfo(BrowserType.EDGE, extractEdgeVersion(versionBeta), true, Paths.get(edgePathBeta, MSEDGE_EXE).toString()));
        }
    } catch (Win32Exception | ConfigurationException e) {
        logger.warn("Error searching Beta Edge chromium installations: " + e.getMessage());
    }
    return browserList;
}
Also used : BrowserType(com.seleniumtests.driver.BrowserType) ConfigurationException(com.seleniumtests.customexception.ConfigurationException) BrowserInfo(com.seleniumtests.browserfactory.BrowserInfo) ArrayList(java.util.ArrayList) List(java.util.List) EnumMap(java.util.EnumMap) Win32Exception(com.sun.jna.platform.win32.Win32Exception)

Example 33 with BrowserInfo

use of com.seleniumtests.browserfactory.BrowserInfo in project seleniumRobot by bhecquet.

the class TestBrowserInfo method testBrowserInfoEdge.

@Test(groups = { "it" })
public void testBrowserInfoEdge() {
    if (!SystemUtils.IS_OS_WINDOWS_10) {
        throw new SkipException("This test can only be done on Windows 10");
    }
    BrowserInfo browserInfo = new BrowserInfo(BrowserType.EDGE, "98.0", "/some/path", false);
    browserInfo.getDriverFileName();
    Assert.assertTrue(browserInfo.isDriverFileSearched());
    Assert.assertEquals(browserInfo.getDriverFileName(), "edgedriver_98.0_edge-98-99");
}
Also used : BrowserInfo(com.seleniumtests.browserfactory.BrowserInfo) SkipException(org.testng.SkipException) GenericDriverTest(com.seleniumtests.GenericDriverTest) Test(org.testng.annotations.Test)

Example 34 with BrowserInfo

use of com.seleniumtests.browserfactory.BrowserInfo in project seleniumRobot by bhecquet.

the class TestBrowserInfo method testBrowserInfoChrome.

@Test(groups = { "it" })
public void testBrowserInfoChrome() {
    BrowserInfo browserInfo = new BrowserInfo(BrowserType.CHROME, "99.0", "/some/path", false);
    browserInfo.getDriverFileName();
    Assert.assertTrue(browserInfo.isDriverFileSearched());
    Assert.assertEquals(browserInfo.getDriverFileName(), "chromedriver_99.0_chrome-99-100");
}
Also used : BrowserInfo(com.seleniumtests.browserfactory.BrowserInfo) GenericDriverTest(com.seleniumtests.GenericDriverTest) Test(org.testng.annotations.Test)

Example 35 with BrowserInfo

use of com.seleniumtests.browserfactory.BrowserInfo in project seleniumRobot by bhecquet.

the class TestBrowserInfo method testBrowserInfoSafari.

@Test(groups = { "it" })
public void testBrowserInfoSafari() {
    if (!SystemUtils.IS_OS_MAC_OSX) {
        throw new SkipException("This test can only be done on Mac OS X");
    }
    BrowserInfo browserInfo = new BrowserInfo(BrowserType.SAFARI, "7.0", "/some/path", false);
    browserInfo.getDriverFileName();
    Assert.assertTrue(browserInfo.isDriverFileSearched());
    Assert.assertNull(browserInfo.getDriverFileName());
}
Also used : BrowserInfo(com.seleniumtests.browserfactory.BrowserInfo) SkipException(org.testng.SkipException) GenericDriverTest(com.seleniumtests.GenericDriverTest) Test(org.testng.annotations.Test)

Aggregations

BrowserInfo (com.seleniumtests.browserfactory.BrowserInfo)71 Test (org.testng.annotations.Test)59 MockitoTest (com.seleniumtests.MockitoTest)53 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)53 ArrayList (java.util.ArrayList)23 List (java.util.List)19 BrowserType (com.seleniumtests.driver.BrowserType)18 HashMap (java.util.HashMap)14 MutableCapabilities (org.openqa.selenium.MutableCapabilities)9 GenericDriverTest (com.seleniumtests.GenericDriverTest)6 ChromeCapabilitiesFactory (com.seleniumtests.browserfactory.ChromeCapabilitiesFactory)5 EdgeCapabilitiesFactory (com.seleniumtests.browserfactory.EdgeCapabilitiesFactory)5 CustomEventFiringWebDriver (com.seleniumtests.driver.CustomEventFiringWebDriver)4 BeforeMethod (org.testng.annotations.BeforeMethod)4 EnumMap (java.util.EnumMap)3 Map (java.util.Map)3 SkipException (org.testng.SkipException)3 FirefoxCapabilitiesFactory (com.seleniumtests.browserfactory.FirefoxCapabilitiesFactory)2 IECapabilitiesFactory (com.seleniumtests.browserfactory.IECapabilitiesFactory)2 MobileDevice (com.seleniumtests.browserfactory.mobile.MobileDevice)2