Search in sources :

Example 16 with BrowserType

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

the class TestLinuxOsUtility method testFirefoxStandardInstallation.

@Test(groups = { "ut" })
public void testFirefoxStandardInstallation() {
    PowerMockito.mockStatic(OSCommand.class);
    PowerMockito.mockStatic(Paths.class);
    when(Paths.get("/usr/local/bin/firefox")).thenReturn(path);
    when(path.toFile()).thenReturn(browserFile);
    when(browserFile.exists()).thenReturn(true);
    when(OSCommand.executeCommandAndWait("which firefox")).thenReturn("/usr/local/bin/firefox");
    when(OSCommand.executeCommandAndWait("firefox --version | more")).thenReturn("Mozilla Firefox 56.0");
    when(OSCommand.executeCommandAndWait("which iceweasel")).thenReturn("/usr/bin/which: no iceweasel in (/usr/local/sbin)");
    when(OSCommand.executeCommandAndWait("which chromium-browser")).thenReturn("/usr/bin/which: no chromium-browser in (/usr/local/sbin)");
    when(OSCommand.executeCommandAndWait("which google-chrome")).thenReturn("/usr/bin/which: no google-chrome in (/usr/local/sbin)");
    Map<BrowserType, List<BrowserInfo>> browsers = new OSUtilityUnix().discoverInstalledBrowsersWithVersion();
    assertTrue(browsers.containsKey(BrowserType.FIREFOX));
}
Also used : OSUtilityUnix(com.seleniumtests.util.osutility.OSUtilityUnix) BrowserType(com.seleniumtests.driver.BrowserType) List(java.util.List) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) MockitoTest(com.seleniumtests.MockitoTest)

Example 17 with BrowserType

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

the class TestWindowsOsUtility method testSeveralFirefoxInstallationsMissingBrowser.

/**
 * check that only valid installations are returned
 * @throws IOException
 */
@Test(groups = { "ut" })
public void testSeveralFirefoxInstallationsMissingBrowser() throws IOException {
    Path profilePath = Paths.get(SeleniumTestsContextManager.getApplicationDataPath(), "ffprofile");
    Stream<Path> profiles = Files.list(Paths.get(SeleniumTestsContextManager.getApplicationDataPath(), "ffprofile"));
    PowerMockito.mockStatic(OSCommand.class);
    PowerMockito.mockStatic(Advapi32Util.class);
    PowerMockito.mockStatic(Paths.class);
    PowerMockito.mockStatic(Files.class);
    when(Paths.get("C:\\Program Files (x86)\\Mozilla2 Firefox\\firefox.exe")).thenReturn(path2);
    when(Paths.get("C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe")).thenReturn(path);
    when(path.toFile()).thenReturn(browserFile);
    when(path2.toFile()).thenReturn(browserFile2);
    when(browserFile.exists()).thenReturn(true);
    when(browserFile2.exists()).thenReturn(false);
    when(Advapi32Util.registryGetStringValue(WinReg.HKEY_LOCAL_MACHINE, "Software\\Classes\\ChromeHTML\\shell\\open\\command", "")).thenThrow(Win32Exception.class);
    // chrome beta not installed
    when(Advapi32Util.registryGetStringValue(WinReg.HKEY_LOCAL_MACHINE, "Software\\Classes\\ChromeBHTML\\shell\\open\\command", "")).thenThrow(Win32Exception.class);
    when(Advapi32Util.registryGetStringValue(WinReg.HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\IEXPLORE.EXE", "")).thenThrow(Win32Exception.class);
    when(Advapi32Util.registryGetStringValue(WinReg.HKEY_CURRENT_USER, "Software\\Microsoft\\MicrosoftEdge\\Main", "EdgeSwitchingOSBuildNumber")).thenThrow(Win32Exception.class);
    when(Advapi32Util.registryGetStringValue(WinReg.HKEY_CLASSES_ROOT, "FirefoxHTML\\shell\\open\\command", "")).thenReturn("\"C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe\" -osint -url \"%1\"");
    when(Advapi32Util.registryGetStringValue(WinReg.HKEY_CLASSES_ROOT, "FirefoxHTML-AC250DEAA7389F99\\shell\\open\\command", "")).thenReturn("\"C:\\Program Files (x86)\\Mozilla2 Firefox\\firefox.exe\" -osint -url \"%1\"");
    when(OSCommand.executeCommandAndWait("C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe --version | more")).thenReturn("Mozilla Firefox 56.0");
    when(OSCommand.executeCommandAndWait("C:\\Program Files (x86)\\Mozilla2 Firefox\\firefox.exe --version | more")).thenReturn("Mozilla Firefox 55.0");
    when(OSCommand.executeCommandAndWait(new String[] { "REG", "QUERY", "HKCR", "/f", "FirefoxHTML", "/k", "/c" })).thenReturn("\r\n" + "HKEY_CLASSES_ROOT\\FirefoxHTML\r\n" + "HKEY_CLASSES_ROOT\\FirefoxHTML-AC250DEAA7389F99\r\n" + "Fin de la recherche : 2 correspondance(s) trouvée(s).");
    OSUtility.refreshBrowserList();
    Map<BrowserType, List<BrowserInfo>> browsers = OSUtility.getInstalledBrowsersWithVersion();
    Assert.assertTrue(browsers.containsKey(BrowserType.FIREFOX));
    Assert.assertEquals(browsers.get(BrowserType.FIREFOX).size(), 1);
    Assert.assertTrue(browsers.get(BrowserType.FIREFOX).get(0).getPath().contains("Mozilla Firefox"));
}
Also used : Path(java.nio.file.Path) BrowserType(com.seleniumtests.driver.BrowserType) List(java.util.List) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) MockitoTest(com.seleniumtests.MockitoTest)

Example 18 with BrowserType

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

the class TestWindowsOsUtility method testFirefoxServerWindowsInstallation.

/**
 * Search Firefox in registry at HKEY_CLASSES_ROOT\\FirefoxHTML-308046\\shell\\open\\command
 * @throws IOException
 */
@Test(groups = { "ut" })
public void testFirefoxServerWindowsInstallation() throws IOException {
    Path profilePath = Paths.get(SeleniumTestsContextManager.getApplicationDataPath(), "ffprofile");
    Stream<Path> profiles = Files.list(Paths.get(SeleniumTestsContextManager.getApplicationDataPath(), "ffprofile"));
    PowerMockito.mockStatic(OSCommand.class);
    PowerMockito.mockStatic(Advapi32Util.class);
    PowerMockito.mockStatic(Paths.class);
    PowerMockito.mockStatic(Files.class);
    when(Paths.get("C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe")).thenReturn(path);
    when(path.toFile()).thenReturn(browserFile);
    when(browserFile.exists()).thenReturn(true);
    when(Advapi32Util.registryGetStringValue(WinReg.HKEY_LOCAL_MACHINE, "Software\\Classes\\ChromeHTML\\shell\\open\\command", "")).thenThrow(Win32Exception.class);
    // chrome beta not installed
    when(Advapi32Util.registryGetStringValue(WinReg.HKEY_LOCAL_MACHINE, "Software\\Classes\\ChromeBHTML\\shell\\open\\command", "")).thenThrow(Win32Exception.class);
    when(Advapi32Util.registryGetStringValue(WinReg.HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\IEXPLORE.EXE", "")).thenThrow(Win32Exception.class);
    when(Advapi32Util.registryGetStringValue(WinReg.HKEY_LOCAL_MACHINE, "Software\\WOW6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Microsoft Edge", "InstallLocation")).thenThrow(Win32Exception.class);
    when(Advapi32Util.registryGetStringValue(WinReg.HKEY_CLASSES_ROOT, "FirefoxHTML-AC250DEAA7389F99\\shell\\open\\command", "")).thenReturn("\"C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe\" -osint -url \"%1\"");
    when(OSCommand.executeCommandAndWait("C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe --version | more")).thenReturn("Mozilla Firefox 56.0");
    when(OSCommand.executeCommandAndWait(new String[] { "REG", "QUERY", "HKCR", "/f", "FirefoxHTML", "/k", "/c" })).thenReturn("\r\n" + "HKEY_CLASSES_ROOT\\FirefoxHTML-AC250DEAA7389F99\r\n" + "Fin de la recherche : 2 correspondance(s) trouvée(s).");
    OSUtility.refreshBrowserList();
    List<BrowserType> browsers = OSUtilityFactory.getInstance().getInstalledBrowsers();
    Assert.assertTrue(browsers.contains(BrowserType.FIREFOX));
}
Also used : Path(java.nio.file.Path) BrowserType(com.seleniumtests.driver.BrowserType) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) MockitoTest(com.seleniumtests.MockitoTest)

Example 19 with BrowserType

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

the class SeleniumTestsContext method updateInstalledBrowsers.

/**
 * If chrome or firefox binary is redefined in parameter, update list of installed browser so
 * that it matches those really used
 */
private void updateInstalledBrowsers() {
    Map<BrowserType, List<BrowserInfo>> installedBrowsers = OSUtility.getInstalledBrowsersWithVersion(getBetaBrowser());
    if (getFirefoxBinPath() != null) {
        String version = OSUtility.getFirefoxVersion(getFirefoxBinPath());
        installedBrowsers.get(BrowserType.FIREFOX).add(new BrowserInfo(BrowserType.FIREFOX, OSUtility.extractFirefoxVersion(version), getFirefoxBinPath()));
    }
    if (getChromeBinPath() != null) {
        String version = OSUtility.getChromeVersion(getChromeBinPath());
        installedBrowsers.get(BrowserType.CHROME).add(new BrowserInfo(BrowserType.CHROME, OSUtility.extractChromeOrChromiumVersion(version), getChromeBinPath()));
    }
}
Also used : BrowserType(com.seleniumtests.driver.BrowserType) BrowserInfo(com.seleniumtests.browserfactory.BrowserInfo) List(java.util.List) ArrayList(java.util.ArrayList)

Example 20 with BrowserType

use of com.seleniumtests.driver.BrowserType 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)

Aggregations

BrowserType (com.seleniumtests.driver.BrowserType)32 List (java.util.List)28 Test (org.testng.annotations.Test)26 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)25 MockitoTest (com.seleniumtests.MockitoTest)22 ArrayList (java.util.ArrayList)20 BrowserInfo (com.seleniumtests.browserfactory.BrowserInfo)18 HashMap (java.util.HashMap)14 MutableCapabilities (org.openqa.selenium.MutableCapabilities)6 ChromeCapabilitiesFactory (com.seleniumtests.browserfactory.ChromeCapabilitiesFactory)5 EdgeCapabilitiesFactory (com.seleniumtests.browserfactory.EdgeCapabilitiesFactory)5 GenericDriverTest (com.seleniumtests.GenericDriverTest)4 OSUtilityUnix (com.seleniumtests.util.osutility.OSUtilityUnix)4 Path (java.nio.file.Path)4 CustomEventFiringWebDriver (com.seleniumtests.driver.CustomEventFiringWebDriver)3 ReporterTest (com.seleniumtests.it.reporter.ReporterTest)3 TextFieldElement (com.seleniumtests.uipage.htmlelements.TextFieldElement)3 EnumMap (java.util.EnumMap)3 Map (java.util.Map)3 WebDriver (org.openqa.selenium.WebDriver)3