Search in sources :

Example 1 with OSUtilityUnix

use of com.seleniumtests.util.osutility.OSUtilityUnix 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 2 with OSUtilityUnix

use of com.seleniumtests.util.osutility.OSUtilityUnix 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 3 with OSUtilityUnix

use of com.seleniumtests.util.osutility.OSUtilityUnix in project seleniumRobot by bhecquet.

the class TestLinuxOsUtility method testChromeStandardInstallation.

@Test(groups = { "ut" })
public void testChromeStandardInstallation() {
    PowerMockito.mockStatic(OSCommand.class);
    PowerMockito.mockStatic(Paths.class);
    when(Paths.get("/usr/local/bin/google-chrome")).thenReturn(path);
    when(path.toFile()).thenReturn(browserFile);
    when(browserFile.exists()).thenReturn(true);
    when(OSCommand.executeCommandAndWait("which google-chrome")).thenReturn("/usr/local/bin/google-chrome");
    when(OSCommand.executeCommandAndWait(new String[] { "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)");
    Map<BrowserType, List<BrowserInfo>> browsers = new OSUtilityUnix().discoverInstalledBrowsersWithVersion();
    assertTrue(browsers.containsKey(BrowserType.CHROME));
}
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 OSUtilityUnix

use of com.seleniumtests.util.osutility.OSUtilityUnix 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 5 with OSUtilityUnix

use of com.seleniumtests.util.osutility.OSUtilityUnix in project seleniumRobot by bhecquet.

the class TestLinuxOsUtility method testGetProcessPidByListenPort.

@Test(groups = { "ut" })
public void testGetProcessPidByListenPort() {
    PowerMockito.mockStatic(OSCommand.class);
    when(OSCommand.executeCommandAndWait("netstat -anp")).thenReturn("tcp        0      0 0.0.0.0:48000           0.0.0.0:*               LISTEN      1421/nimbus(control\r\n" + "tcp        0      0 0.0.0.0:51239           0.0.0.0:*               LISTEN      22492/nimbus(spooler\r\n" + "tcp        0      0 0.0.0.0:10050           0.0.0.0:*               LISTEN      1382/zabbix_agentd\r\n" + "tcp      112      0 10.204.84.149:48624     10.204.90.112:5647      CLOSE_WAIT  1362/python\r\n" + "tcp      112      0 10.204.84.149:48836     10.204.90.112:5647      CLOSE_WAIT  1362/python\r\n" + "tcp6       0      0 10.204.84.149:39436     10.200.42.177:5555      TIME_WAIT   -\r\n" + "tcp6       0      0 10.204.84.149:52030     10.200.42.184:5555      TIME_WAIT   -\r\n" + "tcp6       0      0 10.204.84.149:60048     10.200.41.38:5555       TIME_WAIT   -\r\n" + "udp        0      0 0.0.0.0:68              0.0.0.0:*                           1301/dhclient\r\n" + "udp        0      0 0.0.0.0:111             0.0.0.0:*                           939/rpcbind\r\n");
    Integer processPid = new OSUtilityUnix().getProcessIdByListeningPort(51239);
    Assert.assertEquals((Integer) processPid, (Integer) 22492);
}
Also used : OSUtilityUnix(com.seleniumtests.util.osutility.OSUtilityUnix) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) MockitoTest(com.seleniumtests.MockitoTest)

Aggregations

MockitoTest (com.seleniumtests.MockitoTest)5 OSUtilityUnix (com.seleniumtests.util.osutility.OSUtilityUnix)5 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 Test (org.testng.annotations.Test)5 BrowserType (com.seleniumtests.driver.BrowserType)4 List (java.util.List)4