List of usage examples for org.openqa.selenium WebDriver manage
Options manage();
From source file:org.apache.zeppelin.ZeppelinITUtils.java
License:Apache License
public static void turnOnImplicitWaits(WebDriver driver) { driver.manage().timeouts().implicitlyWait(AbstractZeppelinIT.MAX_IMPLICIT_WAIT, TimeUnit.SECONDS); }
From source file:org.auraframework.components.ui.menu.MenuUITest.java
License:Apache License
/** * Test case : W-2235117 menuItem should reposition itself relative to its trigger when attachToBody attribute is * set/*from w ww . j av a2 s . c o m*/ * * @throws MalformedURLException * @throws URISyntaxException TODO: Uncomment test once W-2235117 is fixed */ public void _testMenuPostionWhenMenuItemAttachToBody() throws MalformedURLException, URISyntaxException { open(MENUTEST_ATTACHTOBODY_APP); String menuItem3 = "actionItemAttachToBody3"; WebDriver driver = this.getDriver(); WebElement actionItem3 = driver.findElement(By.className(menuItem3)); // Need to make the screen bigger so WebDriver doesn't need to scroll driver.manage().window().setSize(new Dimension(1366, 768)); String trigger = "triggerAttachToBody"; String menuList = "actionMenuAttachToBody"; String triggerGlobalId = auraUITestingUtil.getCmpGlobalIdGivenElementClassName(trigger); String menuListGlobalId = auraUITestingUtil.getCmpGlobalIdGivenElementClassName(menuList); WebElement menuLabel = driver.findElement(By.className(trigger)); WebElement menu = driver.findElement(By.className(menuList)); menuLabel.click(); assertTrue("Action Menu list should be expanded", menu.getAttribute("class").contains("visible")); verifyMenuPositionedCorrectly(triggerGlobalId, menuListGlobalId, "Menu List is not positioned correctly when the menuList rendered on the page"); String triggerLeftPosBeforeClick = auraUITestingUtil.getBoundingRectPropOfElement(triggerGlobalId, "left"); actionItem3.click(); String triggerLeftPosAfterClickOnItem2 = auraUITestingUtil.getBoundingRectPropOfElement(triggerGlobalId, "left"); assertEquals("Menu Item position changed after clicking on Item2", triggerLeftPosBeforeClick, triggerLeftPosAfterClickOnItem2); int currentWidth = driver.manage().window().getSize().width; int currentHeight = driver.manage().window().getSize().height; driver.manage().window().setSize(new Dimension(currentWidth - 200, currentHeight - 100)); verifyMenuPositionedCorrectly(triggerGlobalId, menuListGlobalId, "Menu List is not positioned correctly after the resize"); }
From source file:org.auraframework.integration.test.ClientOutOfSyncUITest.java
License:Apache License
/** * This test verifies that changes to components which are dynamically received are correctly identified * after the client is restarted. This is complex to make work: dynamically received defs must be * persisted with sufficient versioning information which is later restored (during client restart / framework * init), then sent to the server so the server can detect the version change and trigger a client out-of-date * message.//from ww w . ja va2 s. co m * * This test verifies the behavior by retrieving a component from the server, modifying its source on the server, * reloading the page, then requesting the same component from the server, asserting that the new source is returned. * Without persisting the component version on the client, the server would never know the client's version of * the component we're loading is out of date and after a page reload the old component would be displayed. * * See W-2909975 for additional details. */ // This tests persistent storage, exclude on Safari based browsers @ExcludeBrowsers({ BrowserType.SAFARI, BrowserType.IPAD, BrowserType.IPHONE }) public void _testReloadAfterMarkupChange() throws Exception { DefDescriptor<ComponentDef> cmpDesc = addSourceAutoCleanup(ComponentDef.class, String.format(baseComponentTag, "", "<div>cmp" + new Date().getTime() + "</div>")); DefDescriptor<ApplicationDef> appDesc = addSourceAutoCleanup(ApplicationDef.class, String.format( baseApplicationTag, "template='auraStorageTest:componentDefStorageTemplate'", "<ui:button label='loadCmp' press='{!c.loadCmp}'/><div id='container' aura:id='container'>app</div>" + "<aura:handler event='aura:initialized' action='{!c.initialized}'/>")); String cmpDefString = cmpDesc.getNamespace() + ":" + cmpDesc.getName(); DefDescriptor<?> controllerDesc = Aura.getDefinitionService().getDefDescriptor(appDesc, DefDescriptor.JAVASCRIPT_PREFIX, ControllerDef.class); addSourceAutoCleanup(controllerDesc, "{" + "loadCmp:function(cmp){$A.createComponent('" + cmpDefString + "', {}, function(newCmp){ cmp.find('container').set('v.body', newCmp); });}," + "initialized:function(cmp){window.initialized=true;}" + "}"); open(appDesc); // Retrieve cmp from server and wait for callback output getAuraUITestingUtil().findDomElement(By.cssSelector("button")).click(); getAuraUITestingUtil().waitUntil(new ExpectedCondition<Boolean>() { @Override public Boolean apply(WebDriver d) { String text = getText(By.cssSelector("#container")); return text.startsWith("cmp"); } }, "Text of app never updated after retrieving component from server"); // Update the source of the component we retrieve from storage String newCmpText = "<div>cmpNew" + new Date().getTime() + "</div>"; updateStringSource(cmpDesc, String.format(baseComponentTag, "", newCmpText)); // Wait for dynamically received component def to be persisted. // ComponentDefStorage will exist because a dynamic cmp is fetched final String getPersistedDef = "var callback = arguments[arguments.length - 1];" + "if (!$A) { callback('Aura not initialized'); return; };" + "var storage = $A.storageService.getStorage('ComponentDefStorage');" + "if (!storage) { callback('No storage'); return; };" + "storage.get('markup://" + cmpDefString + "').then(function(item) { callback(item ? 'SUCCESS' : 'empty') });"; getAuraUITestingUtil().waitUntil(new ExpectedCondition<Boolean>() { @Override public Boolean apply(WebDriver d) { d.manage().timeouts().setScriptTimeout(1, TimeUnit.SECONDS); Object result = ((JavascriptExecutor) getDriver()).executeAsyncScript(getPersistedDef); return "SUCCESS".equals(result); } }, "Definition never persisted on client after server call"); getDriver().navigate().refresh(); // After refresh, the page will fire the getApplication bootstrap action, which will get a ClientOutOfSync // as the response, dump the storages and reload. Instead of trying to wait for the double reload, wait for // Aura Fwk + the app to finish loading (window.initialize) then create def storage (which won't exist // because no dynamic defs have been received) and verify it is empty. getAuraUITestingUtil().waitUntil(new ExpectedCondition<Boolean>() { @Override public Boolean apply(WebDriver d) { String script = "var callback = arguments[arguments.length - 1];" + "if (!window.initialized || !$A) { callback(null); return; }" + "if (!$A.storageService.getStorage('ComponentDefStorage')) {" + " $A.storageService.initStorage({name: 'ComponentDefStorage', persistent: true, secure: false, maxSize: 442368, expiration: 3600, debugLogging: true, clearOnInit: false});" + "}" + "var storage = $A.storageService.getStorage('ComponentDefStorage');" + "storage.getAll().then(" + " function(items){ callback(Object.keys(items)) }," + " function() { callback(null); }" + ")"; Object result = null; try { result = ((JavascriptExecutor) getDriver()).executeAsyncScript(script); } catch (WebDriverException e) { // If the page reloads during our script WebDriver will throw an error. if (!e.getMessage().contains("document unloaded while waiting for result")) { throw e; } } return result != null && ((ArrayList<?>) result).size() == 0; } }, "Storages never cleared after reload"); // The page will reload after the storage is cleared so wait for it to be fully initialized then retrieve // the original component from the server and verify it has the updated source. getAuraUITestingUtil().waitForAuraInit(); getAuraUITestingUtil().findDomElement(By.cssSelector("button")).click(); getAuraUITestingUtil().waitForElementTextContains(By.cssSelector("#container"), "cmpNew", true); }
From source file:org.auraframework.integration.test.components.ui.menu.MenuUITest.java
License:Apache License
/** * Test case : W-2235117 menuItem should reposition itself relative to its trigger when attachToBody attribute is * set// w w w . ja v a2 s. com */ // For env reason the test is failing on Luna Autobuild, will run the test on jenkins only for now. // // W-3140286 @UnAdaptableTest @Flapper @Test public void testMenuPositionWhenMenuItemAttachToBody() throws Exception { open(MENUTEST_ATTACHTOBODY_APP); WebDriver driver = this.getDriver(); // save current dimension and reset it after test finishes // if not chrome would remember the size we set here and // that would affect other tests Dimension originalDimension = getDriver().manage().window().getSize(); // dimensions for testing Dimension initialDimension = new Dimension(800, 600); Dimension newDimension = new Dimension(600, 500); String trigger = "triggerAttachToBody"; String menuList = "actionMenuAttachToBody"; String triggerGlobalId = getAuraUITestingUtil().getCmpGlobalIdGivenElementClassName(trigger); String menuListGlobalId = getAuraUITestingUtil().getCmpGlobalIdGivenElementClassName(menuList); WebElement menuLabel = driver.findElement(By.className(trigger)); WebElement menu = driver.findElement(By.className(menuList)); try { // set initial size to make sure we have room to resize later driver.manage().window().setSize(initialDimension); waitForWindowResize(initialDimension); // Verify menulist and trigger are properly aligned openMenu(menuLabel, menu); waitForMenuPositionedCorrectly(triggerGlobalId, menuListGlobalId, "Menu List is not positioned correctly when the menuList rendered on the page"); // Select menu item and verify still aligned String triggerLeftPosBeforeClick = getAuraUITestingUtil().getBoundingRectPropOfElement(triggerGlobalId, "left"); // elements String menuItem3 = "actionItemAttachToBody3"; WebElement actionItem3 = driver.findElement(By.className(menuItem3)); WebElement actionItem3Element = getAnchor(actionItem3); actionItem3Element.click(); waitForMenuText(menuLabel, "Inter Milan"); String triggerLeftPosAfterClick = getAuraUITestingUtil().getBoundingRectPropOfElement(triggerGlobalId, "left"); assertEquals("Menu Item position changed after clicking on Item3", triggerLeftPosBeforeClick, triggerLeftPosAfterClick); // Resize window with menulist open and verify realigns properly openMenu(menuLabel, menu); driver.manage().window().setSize(newDimension); waitForWindowResize(newDimension); waitForMenuPositionedCorrectly(triggerGlobalId, menuListGlobalId, "Menu List is not positioned correctly after the resize"); } finally { // always reset size for other tests driver.manage().window().setSize(originalDimension); waitForWindowResize(originalDimension); } }
From source file:org.auraframework.integration.test.http.WebDriverFilter.java
License:Apache License
/** * Make sure driver is already at the target domain since a Cookie will be * set for tracking.//ww w.j a v a 2 s .c o m * * @param driver */ public WebDriverFilter(WebDriver driver) { super(((RemoteWebDriver) driver).getSessionId().toString()); driver.manage().addCookie(new Cookie(getCookieName(), "$A")); }
From source file:org.bigtester.ate.model.asserter.PagePropertyCorrectnessAsserter.java
License:Apache License
/** * {@inheritDoc}// w ww .ja v a 2 s . com */ @Override public void assertER() { WebDriver webDriver = getResultPage().getMyWd().getWebDriver();// NOPMD if (null == webDriver) { throw new IllegalStateException("webDriver is not correctly populated."); } for (int i = 0; i < stepERValue.getValue().size(); i++) { StepErPageProperty sErPP = stepERValue.getValue().get(i); if (sErPP.getTestDataContext().getContextFieldValue() .equalsIgnoreCase(AssertType.PAGE_PROPERTY_CORRECTNESS)) { String assertProperty = sErPP.getAssertProperty(); boolean correctFlag; if (PagePropertyType.COOKIE.equalsIgnoreCase(assertProperty)) { Cookie cki = new Cookie(sErPP.getAssertValue(), sErPP.getAssertValue()); if (webDriver.manage().getCookies().contains(cki)) { correctFlag = true; } else { correctFlag = false; } } else if (PagePropertyType.PAGE_TITLE.equalsIgnoreCase(assertProperty)) { if (webDriver.getTitle().equals(sErPP.getAssertValue())) { correctFlag = true; } else { correctFlag = false; } } else { correctFlag = true; } if (correctFlag) { ItemCompareResult icr = new ItemCompareResult(sErPP.getAssertProperty(), sErPP.getAssertValue(), EnumAssertResult.PAGEPROPERTYCORRECT.toString(), sErPP.getAssertPriority(), EnumAssertResult.PAGEPROPERTYCORRECT); getExecResult().getComparedItemResults().put(sErPP.getIdColumn(), icr); super.appendAssertReportMSG(icr); } else { ItemCompareResult icr = new ItemCompareResult(sErPP.getAssertProperty(), sErPP.getAssertValue(), EnumAssertResult.PAGEPROPERTYNOTCORRECT.toString(), sErPP.getAssertPriority(), EnumAssertResult.PAGEPROPERTYNOTCORRECT); getExecResult().getComparedItemResults().put(sErPP.getIdColumn(), icr); getExecResult().getFailedItemResults().put(sErPP.getIdColumn(), icr); EnumAssertPriority failPriority = getStepERValue().getValue().get(i).getAssertPriority(); if (failPriority.equals(EnumAssertPriority.HIGH)) { setFlagFailCase(true); } super.appendAssertReportMSG(icr); } } } }
From source file:org.callimachusproject.webdriver.helpers.WebBrowserDriver.java
License:Apache License
public void waitForFrameToClose(final String frameName) { driver.switchTo().window(driver.getWindowHandle()); if (frameName != null) { try {//from w ww . j a v a 2 s . com driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); new WebDriverWait(driver, 60).until(new ExpectedCondition<Boolean>() { public Boolean apply(WebDriver driver) { return driver.findElements(By.name(frameName)).isEmpty(); } public String toString() { return "frame " + frameName + " to be absent"; } }); } finally { driver.manage().timeouts().implicitlyWait(IMPLICITLY_WAIT, TimeUnit.SECONDS); } } waitForScript(); }
From source file:org.callimachusproject.webdriver.helpers.WebBrowserDriver.java
License:Apache License
public void waitUntilTextPresent(final By locator, final String needle) { waitForScript();// w w w . ja v a2 s.co m try { driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); Wait<WebDriver> wait = new WebDriverWait(driver, 60); Boolean present = wait.until(new ExpectedCondition<Boolean>() { public Boolean apply(WebDriver driver) { for (WebElement element : driver.findElements(locator)) { try { if (element.getText().contains(needle)) { return true; } } catch (StaleElementReferenceException e) { continue; } } return null; } public String toString() { return "text " + needle + " to be present in " + locator; } }); assertTrue(present); } finally { driver.manage().timeouts().implicitlyWait(IMPLICITLY_WAIT, TimeUnit.SECONDS); } }
From source file:org.cerberus.engine.execution.impl.SeleniumServerService.java
License:Open Source License
@Override public void startServer(TestCaseExecution tCExecution) throws CerberusException { //message used for log purposes String logPrefix = "[" + tCExecution.getTest() + " - " + tCExecution.getTestCase() + "] "; try {//from w w w . j av a 2 s.c o m LOG.info(logPrefix + "Start Selenium Server"); /** * Set Session */ LOG.debug(logPrefix + "Setting the session."); String system = tCExecution.getApplicationObj().getSystem(); /** * Get the parameters that will be used to set the servers * (selenium/appium) If timeout has been defined at the execution * level, set the selenium & appium wait element with this value, * else, take the one from parameter */ Integer cerberus_selenium_pageLoadTimeout, cerberus_selenium_implicitlyWait, cerberus_selenium_setScriptTimeout, cerberus_selenium_wait_element, cerberus_appium_wait_element; if (!tCExecution.getTimeout().isEmpty()) { cerberus_selenium_wait_element = Integer.valueOf(tCExecution.getTimeout()); cerberus_appium_wait_element = Integer.valueOf(tCExecution.getTimeout()); } else { cerberus_selenium_wait_element = this.getTimeoutSetInParameterTable(system, "cerberus_selenium_wait_element", 90000, logPrefix); cerberus_appium_wait_element = this.getTimeoutSetInParameterTable(system, "cerberus_appium_wait_element", 90000, logPrefix); ; } cerberus_selenium_pageLoadTimeout = this.getTimeoutSetInParameterTable(system, "cerberus_selenium_pageLoadTimeout", 90000, logPrefix); cerberus_selenium_implicitlyWait = this.getTimeoutSetInParameterTable(system, "cerberus_selenium_implicitlyWait", 0, logPrefix); cerberus_selenium_setScriptTimeout = this.getTimeoutSetInParameterTable(system, "cerberus_selenium_setScriptTimeout", 90000, logPrefix); LOG.debug(logPrefix + "TimeOut defined on session : " + cerberus_selenium_wait_element); Session session = new Session(); session.setCerberus_selenium_implicitlyWait(cerberus_selenium_implicitlyWait); session.setCerberus_selenium_pageLoadTimeout(cerberus_selenium_pageLoadTimeout); session.setCerberus_selenium_setScriptTimeout(cerberus_selenium_setScriptTimeout); session.setCerberus_selenium_wait_element(cerberus_selenium_wait_element); session.setCerberus_appium_wait_element(cerberus_appium_wait_element); session.setHost(tCExecution.getSeleniumIP()); session.setPort(tCExecution.getPort()); tCExecution.setSession(session); LOG.debug(logPrefix + "Session is set."); /** * SetUp Capabilities */ LOG.debug(logPrefix + "Set Capabilities"); DesiredCapabilities caps = this.setCapabilities(tCExecution); session.setDesiredCapabilities(caps); LOG.debug(logPrefix + "Set Capabilities - retreived"); /** * SetUp Driver */ LOG.debug(logPrefix + "Set Driver"); WebDriver driver = null; AppiumDriver appiumDriver = null; if (tCExecution.getApplicationObj().getType().equalsIgnoreCase("GUI")) { if (caps.getPlatform().is(Platform.ANDROID)) { appiumDriver = new AndroidDriver(new URL("http://" + tCExecution.getSession().getHost() + ":" + tCExecution.getSession().getPort() + "/wd/hub"), caps); driver = (WebDriver) appiumDriver; } else if (caps.getPlatform().is(Platform.MAC)) { appiumDriver = new IOSDriver(new URL("http://" + tCExecution.getSession().getHost() + ":" + tCExecution.getSession().getPort() + "/wd/hub"), caps); driver = (WebDriver) appiumDriver; } else { driver = new RemoteWebDriver(new URL("http://" + tCExecution.getSession().getHost() + ":" + tCExecution.getSession().getPort() + "/wd/hub"), caps); } } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase("APK")) { appiumDriver = new AndroidDriver(new URL("http://" + tCExecution.getSession().getHost() + ":" + tCExecution.getSession().getPort() + "/wd/hub"), caps); driver = (WebDriver) appiumDriver; } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase("IPA")) { appiumDriver = new IOSDriver(new URL("http://" + tCExecution.getSession().getHost() + ":" + tCExecution.getSession().getPort() + "/wd/hub"), caps); driver = (WebDriver) appiumDriver; } else if (tCExecution.getApplicationObj().getType().equalsIgnoreCase("FAT")) { sikuliService.doSikuliAction(session, "openApp", null, tCExecution.getCountryEnvironmentParameters().getIp()); } /** * Defining the timeout at the driver level. Only in case of not * Appium Driver (see * https://github.com/vertigo17/Cerberus/issues/754) */ if (driver != null && appiumDriver == null) { driver.manage().timeouts().pageLoadTimeout(cerberus_selenium_pageLoadTimeout, TimeUnit.MILLISECONDS); driver.manage().timeouts().implicitlyWait(cerberus_selenium_implicitlyWait, TimeUnit.MILLISECONDS); driver.manage().timeouts().setScriptTimeout(cerberus_selenium_setScriptTimeout, TimeUnit.MILLISECONDS); } tCExecution.getSession().setDriver(driver); tCExecution.getSession().setAppiumDriver(appiumDriver); /** * If Gui application, maximize window Get IP of Node in case of * remote Server */ if (tCExecution.getApplicationObj().getType().equalsIgnoreCase("GUI") && !caps.getPlatform().equals(Platform.ANDROID)) { driver.manage().window().maximize(); getIPOfNode(tCExecution); /** * If screenSize is defined, set the size of the screen. */ if (!tCExecution.getScreenSize().equals("")) { Integer screenWidth = Integer.valueOf(tCExecution.getScreenSize().split("\\*")[0]); Integer screenLength = Integer.valueOf(tCExecution.getScreenSize().split("\\*")[1]); setScreenSize(driver, screenWidth, screenLength); } tCExecution.setScreenSize(getScreenSize(driver)); } tCExecution.getSession().setStarted(true); } catch (CerberusException exception) { LOG.error(logPrefix + exception.toString()); throw new CerberusException(exception.getMessageError()); } catch (MalformedURLException exception) { LOG.error(logPrefix + exception.toString()); MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.VALIDATION_FAILED_URL_MALFORMED); mes.setDescription(mes.getDescription().replace("%URL%", tCExecution.getSession().getHost() + ":" + tCExecution.getSession().getPort())); throw new CerberusException(mes); } catch (UnreachableBrowserException exception) { LOG.error(logPrefix + exception.toString()); MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.VALIDATION_FAILED_SELENIUM_COULDNOTCONNECT); mes.setDescription(mes.getDescription().replace("%SSIP%", tCExecution.getSeleniumIP())); mes.setDescription(mes.getDescription().replace("%SSPORT%", tCExecution.getSeleniumPort())); throw new CerberusException(mes); } catch (Exception exception) { LOG.error(logPrefix + exception.toString()); MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.EXECUTION_FA_SELENIUM); mes.setDescription(mes.getDescription().replace("%MES%", exception.toString())); throw new CerberusException(mes); } }
From source file:org.cerberus.engine.execution.impl.SeleniumServerService.java
License:Open Source License
private void setScreenSize(WebDriver driver, Integer width, Integer length) { driver.manage().window().setPosition(new Point(0, 0)); driver.manage().window().setSize(new Dimension(width, length)); }