Search in sources :

Example 1 with BrowserType

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");
}
Also used : BrowserType(com.seleniumtests.driver.BrowserType) HashMap(java.util.HashMap) BrowserInfo(com.seleniumtests.browserfactory.BrowserInfo) MutableCapabilities(org.openqa.selenium.MutableCapabilities) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) EdgeCapabilitiesFactory(com.seleniumtests.browserfactory.EdgeCapabilitiesFactory) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) MockitoTest(com.seleniumtests.MockitoTest)

Example 2 with BrowserType

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));
}
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 3 with BrowserType

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();
}
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 4 with BrowserType

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"));
}
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 5 with BrowserType

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));
}
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)

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