List of usage examples for org.openqa.selenium Platform MAC
Platform MAC
To view the source code for org.openqa.selenium Platform MAC.
Click Source Link
From source file:org.emonocot.portal.driver.WebDriverFacade.java
License:Open Source License
/** * * @return the webdriver//from w ww. ja v a 2 s .co m * @throws IOException if there is a problem loading the * properties file */ private WebDriver createWebDriver() throws IOException { Resource propertiesFile = new ClassPathResource("META-INF/spring/application.properties"); Properties properties = new Properties(); properties.load(propertiesFile.getInputStream()); String webdriverMode = properties.getProperty("selenium.webdriver.mode", "local"); String driverName = properties.getProperty("selenium.webdriver.impl", "org.openqa.selenium.firefox.FirefoxDriver"); WebDriverBrowserType browser = WebDriverBrowserType.fromString(driverName); String display = properties.getProperty("selenium.display.port", ":0"); if (webdriverMode.equals("local")) { switch (browser) { case CHROME: String chromeLocation = properties.getProperty("selenium.webdriver.chromedriver.location"); Map<String, String> environment = new HashMap<String, String>(); environment.put("DISPLAY", display); ChromeDriverService chromeService = new ChromeDriverService.Builder() .usingDriverExecutable(new File(chromeLocation)).usingAnyFreePort() .withEnvironment(environment).build(); chromeService.start(); return new RemoteWebDriver(chromeService.getUrl(), DesiredCapabilities.chrome()); case SAFARI: return new SafariDriver(); case INTERNET_EXPLORER: String internetExplorerLocation = properties.getProperty("selenium.webdriver.ie.location"); InternetExplorerDriverService ieService = InternetExplorerDriverService.createDefaultService(); ieService.start(); return new RemoteWebDriver(ieService.getUrl(), DesiredCapabilities.internetExplorer()); case FIREFOX: default: FirefoxBinary firefoxBinary = new FirefoxBinary(); firefoxBinary.setEnvironmentProperty("DISPLAY", display); ProfilesIni allProfiles = new ProfilesIni(); FirefoxProfile profile = allProfiles.getProfile("default"); return new FirefoxDriver(firefoxBinary, profile); } } else { DesiredCapabilities capabilities = new DesiredCapabilities(); switch (browser) { case CHROME: capabilities = DesiredCapabilities.chrome(); break; case INTERNET_EXPLORER: capabilities = DesiredCapabilities.internetExplorer(); break; case SAFARI: capabilities = DesiredCapabilities.safari(); break; case FIREFOX: default: capabilities = DesiredCapabilities.firefox(); } String platformName = properties.getProperty("selenium.webdriver.platformName", "LINUX"); WebDriverPlatformType platform = WebDriverPlatformType.valueOf(platformName); switch (platform) { case MAC: capabilities.setPlatform(Platform.MAC); break; case WINDOWS: capabilities.setPlatform(Platform.WINDOWS); break; case LINUX: default: capabilities.setPlatform(Platform.LINUX); } return new RemoteWebDriver(new URL("http://build.e-monocot.org:4444/wd/hub"), capabilities); } }
From source file:org.glassfish.tyrus.tests.qa.SeleniumToolkit.java
License:Open Source License
public static boolean onMac() { return Platform.MAC.is(Platform.getCurrent()); }
From source file:org.jboss.arquillian.drone.webdriver.utils.Validate.java
License:Apache License
/** * Find the executable by scanning the file system and the PATH. In the case of Windows this * method allows common executable endings (".com", ".bat" and ".exe") to be omitted. * * @param command/* ww w .j a va 2 s . c o m*/ * The name of the executable to find * * @return Whether the command is executable or not. */ public static boolean isCommandExecutable(String command) throws IllegalArgumentException { File file = new File(command); if (fileExecutableChecker.canExecute(file)) { return true; } if (Platform.getCurrent().is(WINDOWS)) { file = new File(command + ".exe"); if (fileExecutableChecker.canExecute(file)) { return true; } } final List<String> pathSegmentBuilder = new ArrayList<>(); addPathFromEnvironment(pathSegmentBuilder); if (Platform.getCurrent().is(Platform.MAC)) { addMacSpecificPath(pathSegmentBuilder); } for (String pathSegment : pathSegmentBuilder) { for (String ending : ENDINGS) { file = new File(pathSegment, command + ending); if (fileExecutableChecker.canExecute(file)) { return true; } } } return false; }
From source file:org.nuxeo.ftest.cap.ITSafeEditTest.java
License:Apache License
/** * This methods checks that once a simple html input is changed within a page, the new value is stored in the * browser local storage in case of accidental loose (crash, freeze, network failure). The value can then be * restored from the local storage when re-editing the page afterwards. * * @since 5.7.1/* w w w .ja va 2 s. c o m*/ */ @Test public void testAutoSaveOnChangeAndRestore() throws Exception { if (!runTestForBrowser()) { log.warn("Browser not supported. Nothing to run."); return; } WebElement descriptionElt, titleElt; login(TEST_USERNAME, TEST_PASSWORD); open(String.format(NXDOC_URL_FORMAT, wsId)); DocumentBasePage documentBasePage = asPage(DocumentBasePage.class); documentBasePage.getEditTab(); LocalStorage localStorage = new LocalStorage(driver); localStorage.clearLocalStorage(); String currentDocumentId = getCurrentDocumentId(); descriptionElt = driver.findElement(By.name(DESCRIPTION_ELT_ID)); titleElt = driver.findElement(By.name(TITLE_ELT_ID)); log.debug("1 - " + localStorage.getLocalStorageLength()); // We change the value of the title Keys ctrlKey = Keys.CONTROL; if (Platform.MAC.equals(driver.getCapabilities().getPlatform())) { ctrlKey = Keys.COMMAND; } titleElt.click(); titleElt.sendKeys(Keys.chord(ctrlKey, "a") + Keys.DELETE + NEW_WORKSPACE_TITLE); // weird thing in webdriver: we need to call clear on an input of the // form to fire an onchange event Locator.scrollToElement(descriptionElt); descriptionElt.click(); descriptionElt.clear(); log.debug("2 - " + localStorage.getLocalStorageLength()); // avoid randoms: wait for the local storage to actually hold the saved values after 10s Locator.waitUntilGivenFunction(input -> { LocalStorage ls = new LocalStorage(driver); String content = ls.getItemFromLocalStorage(wsId); log.debug(content); return content != null && content.contains(NEW_WORKSPACE_TITLE); }); // Now must have something saved in the localstorage String lsItem = localStorage.getItemFromLocalStorage(currentDocumentId); final String lookupString = "\"" + TITLE_ELT_ID + "\":\"" + NEW_WORKSPACE_TITLE + "\""; assertTrue(lsItem != null && lsItem.length() > 0); assertTrue(lsItem.contains(lookupString)); // Let's leave the edit tab of the workspace with unsaved changes. A // popup should also prevent us from doing that, let's bypass it for tests log.debug("3 - " + localStorage.getLocalStorageLength()); bypassPopup(); driver.findElement(By.linkText("Sections")).click(); log.debug("4 - " + localStorage.getLocalStorageLength()); // Get back to edit tab. Since we didn't save, the title must be the initial one. open(String.format(NXDOC_URL_FORMAT, wsId)); documentBasePage = asPage(DocumentBasePage.class); documentBasePage.getEditTab(); localStorage = new LocalStorage(driver); titleElt = Locator.findElementWithTimeout(By.name(TITLE_ELT_ID)); String titleEltValue = titleElt.getAttribute("value"); assertEquals(WORKSPACE_TITLE, titleEltValue); log.debug("5 - " + localStorage.getLocalStorageLength()); // We must find in the localstorage an entry matching the previous // document which contains the title we edited lsItem = localStorage.getItemFromLocalStorage(currentDocumentId); assertNotNull(lsItem); assertTrue(lsItem.contains(lookupString)); log.debug("6 - " + localStorage.getLocalStorageLength()); checkSafeEditRestoreProvided(); triggerSafeEditRestore(); // We check that the title value has actually been restored titleElt = driver.findElement(By.name(TITLE_ELT_ID)); titleEltValue = titleElt.getAttribute("value"); assertEquals(NEW_WORKSPACE_TITLE, titleEltValue); // try to leave again if (documentBasePage.useAjaxTabs()) { AjaxRequestManager arm = new AjaxRequestManager(driver); arm.begin(); documentBasePage.clickOnDocumentTabLink(documentBasePage.contentTabLink, false); leaveTabPopup(false); arm.end(); } else { documentBasePage.clickOnDocumentTabLink(documentBasePage.contentTabLink, false); leavePagePopup(false); } driver.findElement(By.linkText("Sections")).click(); leavePagePopup(true); logout(); }
From source file:org.nuxeo.functionaltests.ITSafeEditTest.java
License:Open Source License
/** * This methods checks that once a simple html input is changed within a * page, the new value is stored in the browser local storage in case of * accidental loose (crash, freeze, network failure). The value can then be * restored from the local storage when re-editing the page afterwards. * * @since 5.7.1//from ww w. j av a 2 s. c o m */ @Test public void testAutoSaveOnChangeAndRestore() throws Exception { if (!runTestForBrowser()) { log.warn("Browser not supported. Nothing to run."); return; } prepare(); DocumentBasePage documentBasePage; WebElement descriptionElt, titleElt; // Log as test user and edit the created workdspace documentBasePage = login(USERNAME, PASSWORD).getContentTab().goToDocument("Workspaces").getContentTab() .goToDocument(WORKSPACE_TITLE); documentBasePage.getEditTab(); LocalStorage localStorage = new LocalStorage(driver); localStorage.clearLocalStorage(); String currentDocumentId = getCurrentDocumentId(); descriptionElt = driver.findElement(By.name(DESCRIPTION_ELT_ID)); titleElt = driver.findElement(By.name(TITLE_ELT_ID)); log.debug("1 - " + localStorage.getLocalStorageLength()); // We change the value of the title Keys ctrlKey = Keys.CONTROL; if (Platform.MAC.equals(driver.getCapabilities().getPlatform())) { ctrlKey = Keys.COMMAND; } titleElt.click(); titleElt.sendKeys(Keys.chord(ctrlKey, "a") + Keys.DELETE + NEW_WORKSPACE_TITLE); // weird thing in webdriver: we need to call clear on an input of the // form to fire an onchange event descriptionElt.click(); descriptionElt.clear(); log.debug("2 - " + localStorage.getLocalStorageLength()); // Now must have something saved in the localstorage String lsItem = localStorage.getItemFromLocalStorage(currentDocumentId); final String lookupString = "\"" + TITLE_ELT_ID + "\":\"" + NEW_WORKSPACE_TITLE + "\""; assertTrue(lsItem != null && lsItem.length() > 0); assertTrue(lsItem.contains(lookupString)); // Let's leave the edit tab of the workspace with unsaved changes. A // popup should prevent us from doing that try { documentBasePage.getContentTab(); // Should never occur fail("There are unsaved modifications pending and the page can only be left after clicking \"Leave this page\""); } catch (UnhandledAlertException e) { // Expected behavior // The following is a workaround to by pass the popup windows which // is supposed to prevent the user from leaving the page with // unsaved modifications log.debug("3 - " + localStorage.getLocalStorageLength()); byPassLeavePagePopup(); log.debug("4 - " + localStorage.getLocalStorageLength()); } // We leave the page and get back to it. Since we didn't save, the // title must be the initial one. documentBasePage.getContentTab(); documentBasePage.getEditTab(); localStorage = new LocalStorage(driver); titleElt = findElementWithTimeout(By.name(TITLE_ELT_ID)); String titleEltValue = titleElt.getAttribute("value"); assertTrue(titleEltValue.equals(WORKSPACE_TITLE)); log.debug("5 - " + localStorage.getLocalStorageLength()); // We must find in the localstorage an entry matching the previous // document which contains the title we edited lsItem = localStorage.getItemFromLocalStorage(currentDocumentId); assertTrue(lsItem.contains(lookupString)); log.debug("6 - " + localStorage.getLocalStorageLength()); checkSafeEditRestoreProvided(); triggerSafeEditResotre(); // We check that the title value has actually been restored titleElt = driver.findElement(By.name(TITLE_ELT_ID)); titleEltValue = titleElt.getAttribute("value"); assertTrue(titleEltValue.equals(NEW_WORKSPACE_TITLE)); byPassLeavePagePopup(); documentBasePage.getContentTab(); logout(); restoreSate(); }
From source file:org.qe4j.web.OpenWebDriver.java
License:Open Source License
/** * Constructs the property key to lookup the browser binary path. * * @param platform//from w w w . j a va 2s . co m * @param browser * @param version * @return property key to lookup browser binary else null if the binary is * not found or definition indicates it should use the default * binary */ protected String getBrowserBinaryPath(Platform platform, Browser browser, String version, Properties properties) { // determine platform part of property key String platformKeyPart = null; if (platform.is(Platform.LINUX)) { platformKeyPart = "linux"; } else if (platform.is(Platform.WINDOWS)) { platformKeyPart = "win"; } else if (platform.is(Platform.MAC)) { platformKeyPart = "mac"; } else { throw new IllegalArgumentException("platform " + platform + " not currently supported"); } String browserBinaryPropertyKey = "webdriver." + platformKeyPart + "." + browser.toString().toLowerCase() + "." + version; log.info("looking up webdriver browser binary path property {}", browserBinaryPropertyKey); String browserBinary = properties.getProperty(browserBinaryPropertyKey); if (browserBinary != null) { if (browserBinary.equals("")) { browserBinary = null; } else { log.info("using browser binary {}", browserBinary); } } return browserBinary; }
From source file:org.qe4j.web.OpenWebDriver.java
License:Open Source License
/** * Converts the property definition of the platform to the Selenium enum * representation of it. Throws exception if the platform is not supported * by SauceLabs (current remote execution environment). * * @param platformProperty/* w ww. j a v a2s .c o m*/ * @return Selenium platform enum */ public static Platform lookupPlatform(String platformProperty) { String platform = platformProperty.toLowerCase(); if (platform.equals("xp")) { return Platform.XP; } else if (platform.equals("vista")) { return Platform.VISTA; } else if (platform.equals("linux")) { return Platform.LINUX; } else if (platform.equals("windows")) { return Platform.WINDOWS; } else if (platform.equals("mac")) { return Platform.MAC; } else { throw new IllegalArgumentException( "platform property " + platformProperty + " is not currently supported for remote web driver"); } }
From source file:org.qe4j.web.OpenWebDriverTest.java
License:Open Source License
@Test public void getBrowserBinaryPathDefinedPath() throws IOException { Properties properties = getProperties(); String expectedBinary = "/Test/binarypath"; properties.setProperty("webdriver.mac.firefox.18", expectedBinary); OpenWebDriver driver = new OpenWebDriver(); String binaryPath = driver.getBrowserBinaryPath(Platform.MAC, Browser.FIREFOX, "18", properties); Assert.assertEquals(binaryPath, expectedBinary, "binary path"); }