use of com.seleniumtests.driver.BrowserType in project seleniumRobot by bhecquet.
the class TestEdgeCapabilityFactory method testCreateEdgeCapabilitiesOverrideBinPath.
/**
* check the case where we have a beta browser. The last one is choosen
*/
@Test(groups = { "ut" })
public void testCreateEdgeCapabilitiesOverrideBinPath() {
when(config.getMode()).thenReturn(DriverMode.LOCAL);
// SeleniumTestsContext class adds a browserInfo when binary path is set
Map<BrowserType, List<BrowserInfo>> updatedBrowserInfos = new HashMap<>();
updatedBrowserInfos.put(BrowserType.EDGE, Arrays.asList(new BrowserInfo(BrowserType.EDGE, "92.0", "", false), new BrowserInfo(BrowserType.EDGE, "93.0", "/opt/edge/bin/edge", false)));
PowerMockito.when(OSUtility.getInstalledBrowsersWithVersion(false)).thenReturn(updatedBrowserInfos);
MutableCapabilities capa = new EdgeCapabilitiesFactory(config).createCapabilities();
Assert.assertEquals(((Map<?, ?>) (((EdgeOptions) capa).asMap().get(EdgeOptions.CAPABILITY))).get("binary").toString(), "/opt/edge/bin/edge");
}
use of com.seleniumtests.driver.BrowserType in project seleniumRobot by bhecquet.
the class TestLinuxOsUtility method testNoBrowserInstalled.
/**
* Check no error is raised when no browser is installed (issue #128)
*/
@Test(groups = { "ut" })
public void testNoBrowserInstalled() {
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/bin/which: no firefox in (/usr/local/sbin)");
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();
Assert.assertEquals(browsers.size(), 2);
Assert.assertFalse(browsers.containsKey(BrowserType.FIREFOX));
}
use of com.seleniumtests.driver.BrowserType in project seleniumRobot by bhecquet.
the class TestLinuxOsUtility method testChromeSpecialBinaryInstallation.
@Test(groups = { "ut" })
public void testChromeSpecialBinaryInstallation() {
PowerMockito.mockStatic(OSCommand.class);
PowerMockito.mockStatic(Paths.class);
when(Paths.get("/usr/local/bin/google-chrome")).thenReturn(path);
when(Paths.get("/usr/local/bin/google-chrome-binary")).thenReturn(path);
when(path.toFile()).thenReturn(browserFile);
when(browserFile.exists()).thenReturn(true);
when(OSUtility.getChromeVersion("/usr/local/bin/google-chrome")).thenReturn("Google Chrome 57.0.2987.110");
when(OSUtility.getChromeVersion("/usr/local/bin/google-chrome-binary")).thenReturn("Google Chrome 66.6.6666.666");
when(OSCommand.executeCommandAndWait("which google-chrome")).thenReturn("/usr/local/bin/google-chrome");
when(OSCommand.executeCommandAndWait(new String[] { "/usr/local/bin/google-chrome", "--version" })).thenReturn("Google Chrome 57.0.2987.110");
when(OSCommand.executeCommandAndWait("which firefox")).thenReturn("/usr/bin/which: no firefox in (/usr/local/sbin)");
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)");
SeleniumTestsContextManager.getThreadContext().setAttribute(CHROME_BINARY_PATH, "/usr/local/bin/google-chrome-binary");
OSUtility.resetInstalledBrowsersWithVersion();
SeleniumTestsContextManager.getThreadContext().configureContext(Reporter.getCurrentTestResult());
Map<BrowserType, List<BrowserInfo>> browsersBinary = new OSUtilityUnix().getInstalledBrowsersWithVersion(false);
assertEquals(browsersBinary.size(), 3);
assertEquals(browsersBinary.get(BrowserType.CHROME).size(), 2);
browsersBinary.get(BrowserType.CHROME).get(0).getVersion();
}
use of com.seleniumtests.driver.BrowserType in project seleniumRobot by bhecquet.
the class TestWindowsOsUtility method testSeveralFirefoxInstallations.
/**
* Search Firefox in registry at HKEY_CLASSES_ROOT\\FirefoxHTML-308046\\shell\\open\\command
* @throws IOException
*/
@Test(groups = { "ut" })
public void testSeveralFirefoxInstallations() 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(path);
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\\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(), 2);
Assert.assertTrue(browsers.get(BrowserType.FIREFOX).get(0).getPath().contains("Mozilla Firefox"));
}
use of com.seleniumtests.driver.BrowserType in project seleniumRobot by bhecquet.
the class TestWindowsOsUtility method testFirefoxStandardWindowsInstallation.
/**
* Search Firefox in registry at HKEY_CLASSES_ROOT\\FirefoxHTML\\shell\\open\\command
* @throws IOException
*/
@Test(groups = { "ut" })
public void testFirefoxStandardWindowsInstallation() 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(Paths.get(contains("Profiles"))).thenReturn(profilePath);
when(Files.list(profilePath)).thenReturn(profiles);
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\\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\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));
}
Aggregations