Search in sources :

Example 21 with BrowserType

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

the class OSUtilityMac 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)));
    // safari is always installed on mac os
    browserList.put(BrowserType.SAFARI, Arrays.asList(new BrowserInfo(BrowserType.SAFARI, BrowserInfo.LATEST_VERSION, null)));
    // TODO: handle multiple installation of Chrome and Firefox. But how to do that without specifying the location
    if (new File("/Applications/Google Chrome.app").isDirectory()) {
        String version = getChromeVersion("/Applications/Google Chrome.app/Contents/MacOS/Google Chrome");
        browserList.put(BrowserType.CHROME, Arrays.asList(new BrowserInfo(BrowserType.CHROME, extractChromeVersion(version), "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome")));
    }
    if (new File("/Applications/Firefox.app").isDirectory()) {
        String version = getFirefoxVersion("/Applications/Firefox.app/Contents/MacOS/firefox");
        browserList.put(BrowserType.FIREFOX, Arrays.asList(new BrowserInfo(BrowserType.FIREFOX, extractFirefoxVersion(version), "/Applications/Firefox.app/Contents/MacOS/firefox")));
    }
    return browserList;
}
Also used : BrowserType(com.seleniumtests.driver.BrowserType) BrowserInfo(com.seleniumtests.browserfactory.BrowserInfo) List(java.util.List) EnumMap(java.util.EnumMap) File(java.io.File)

Example 22 with BrowserType

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

the class OSUtilityUnix 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)));
    // TODO: handle multiple installation of firefox and Chrome
    String firefoxLocation = OSCommand.executeCommandAndWait("which firefox").trim();
    String iceweaselLocation = OSCommand.executeCommandAndWait("which iceweasel").trim();
    String chromeLocation = OSCommand.executeCommandAndWait("which google-chrome").trim();
    String chromiumLocation = OSCommand.executeCommandAndWait("which chromium-browser").trim();
    if (!firefoxLocation.isEmpty() && !firefoxLocation.contains(WHICH_ERROR)) {
        String version = getFirefoxVersion("firefox");
        List<BrowserInfo> arrayFirefox = new ArrayList<>();
        arrayFirefox.add(new BrowserInfo(BrowserType.FIREFOX, extractFirefoxVersion(version), firefoxLocation));
        browserList.put(BrowserType.FIREFOX, arrayFirefox);
    } else if (!iceweaselLocation.isEmpty() && !iceweaselLocation.contains(WHICH_ERROR)) {
        String version = getFirefoxVersion("iceweasel");
        List<BrowserInfo> arrayIceWeasel = new ArrayList<>();
        arrayIceWeasel.add(new BrowserInfo(BrowserType.FIREFOX, extractFirefoxVersion(version), iceweaselLocation));
        browserList.put(BrowserType.FIREFOX, arrayIceWeasel);
    }
    if (!chromiumLocation.isEmpty() && !chromiumLocation.contains(WHICH_ERROR)) {
        String version = getChromeVersion("chromium-browser");
        List<BrowserInfo> arrayChromium = new ArrayList<>();
        arrayChromium.add(new BrowserInfo(BrowserType.CHROME, extractChromiumVersion(version), chromiumLocation));
        browserList.put(BrowserType.CHROME, arrayChromium);
    } else if (!chromeLocation.isEmpty() && !chromeLocation.contains(WHICH_ERROR)) {
        String version = getChromeVersion("google-chrome");
        List<BrowserInfo> arrayChrome = new ArrayList<>();
        arrayChrome.add(new BrowserInfo(BrowserType.CHROME, extractChromeVersion(version), chromeLocation));
        browserList.put(BrowserType.CHROME, arrayChrome);
    }
    return browserList;
}
Also used : BrowserType(com.seleniumtests.driver.BrowserType) BrowserInfo(com.seleniumtests.browserfactory.BrowserInfo) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) EnumMap(java.util.EnumMap)

Example 23 with BrowserType

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

the class TestWebUiDriver method testAttachExternalChromeBrowserStartingLate.

/**
 * Be sure that we can still attach driver even if it takes a long time to start
 * For chrome, max wait time is 1 minute
 */
@Test(groups = { "it" })
public void testAttachExternalChromeBrowserStartingLate() {
    SeleniumTestsContextManager.getThreadContext().setTestType(TestType.WEB);
    Map<BrowserType, List<BrowserInfo>> browsers = OSUtility.getInstalledBrowsersWithVersion();
    String path = browsers.get(BrowserType.CHROME).get(0).getPath();
    int port = GenericDriverTest.findFreePort();
    logger.info("will start browser in 15 secs");
    new BrowserLauncher(BrowserType.CHROME, port, path, 30, null).run();
    logger.info("Waiting for driver");
    // creates the driver
    WebDriver driver1 = WebUIDriver.getWebDriver(true, BrowserType.CHROME, "main", port);
    driver1.get("chrome://settings/");
    Assert.assertTrue(new TextFieldElement("search", By.id("search")).isElementPresent(3));
}
Also used : WebDriver(org.openqa.selenium.WebDriver) CustomEventFiringWebDriver(com.seleniumtests.driver.CustomEventFiringWebDriver) TextFieldElement(com.seleniumtests.uipage.htmlelements.TextFieldElement) BrowserType(com.seleniumtests.driver.BrowserType) List(java.util.List) ArrayList(java.util.ArrayList) Test(org.testng.annotations.Test) GenericDriverTest(com.seleniumtests.GenericDriverTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) ReporterTest(com.seleniumtests.it.reporter.ReporterTest)

Example 24 with BrowserType

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

the class TestWebUiDriver method testAttachExternalEdgeBrowser.

@Test(groups = { "it" })
public void testAttachExternalEdgeBrowser() {
    if (!SystemUtils.IS_OS_WINDOWS) {
        throw new SkipException("This test can only be done on Windows");
    }
    SeleniumTestsContextManager.getThreadContext().setTestType(TestType.WEB);
    Map<BrowserType, List<BrowserInfo>> browsers = OSUtility.getInstalledBrowsersWithVersion();
    String path = browsers.get(BrowserType.EDGE).get(0).getPath();
    int port = GenericDriverTest.findFreePort();
    // create chrome browser with the right option
    new BrowserLauncher(BrowserType.EDGE, port, path, 0, null).run();
    // creates the driver
    WebDriver driver1 = WebUIDriver.getWebDriver(true, BrowserType.EDGE, "main", port);
    driver1.get("edge://settings/");
    Assert.assertTrue(new TextFieldElement("search", By.id("search_input")).isElementPresent(3));
}
Also used : WebDriver(org.openqa.selenium.WebDriver) CustomEventFiringWebDriver(com.seleniumtests.driver.CustomEventFiringWebDriver) TextFieldElement(com.seleniumtests.uipage.htmlelements.TextFieldElement) BrowserType(com.seleniumtests.driver.BrowserType) List(java.util.List) ArrayList(java.util.ArrayList) SkipException(org.testng.SkipException) Test(org.testng.annotations.Test) GenericDriverTest(com.seleniumtests.GenericDriverTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) ReporterTest(com.seleniumtests.it.reporter.ReporterTest)

Example 25 with BrowserType

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

the class TestChromeCapabilityFactory method testNonBetaVersionBrowserAbsent.

/**
 * If beta is not requested, and non beta browser not installed, return null
 */
@Test(groups = { "ut" }, expectedExceptions = ConfigurationException.class, expectedExceptionsMessageRegExp = "Browser CHROME  is not available")
public void testNonBetaVersionBrowserAbsent() {
    when(config.getMode()).thenReturn(DriverMode.LOCAL);
    Map<BrowserType, List<BrowserInfo>> browserInfos = new HashMap<>();
    browserInfos.put(BrowserType.CHROME, Arrays.asList(new BrowserInfo(BrowserType.CHROME, "97.0", "", false, true)));
    PowerMockito.when(OSUtility.getInstalledBrowsersWithVersion(false)).thenReturn(browserInfos);
    ChromeCapabilitiesFactory capaFactory = new ChromeCapabilitiesFactory(config);
    capaFactory.createCapabilities();
}
Also used : ChromeCapabilitiesFactory(com.seleniumtests.browserfactory.ChromeCapabilitiesFactory) BrowserType(com.seleniumtests.driver.BrowserType) HashMap(java.util.HashMap) BrowserInfo(com.seleniumtests.browserfactory.BrowserInfo) ArrayList(java.util.ArrayList) List(java.util.List) 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