List of usage examples for org.openqa.selenium Keys CONTROL
Keys CONTROL
To view the source code for org.openqa.selenium Keys CONTROL.
Click Source Link
From source file:org.xframium.gesture.device.action.spi.perfecto.OpenApplicationAction.java
License:Open Source License
@Override public boolean _executeAction(WebDriver webDriver, List<Object> parameterList) { String executionId = getExecutionId(webDriver); String deviceName = getDeviceName(webDriver); String applicationName = (String) parameterList.get(0); ApplicationDescriptor appDesc = ApplicationRegistry.instance().getApplication(applicationName); if (appDesc == null) throw new ScriptConfigurationException("The Application " + applicationName + " does not exist"); if (appDesc.isWeb()) { String selectLinkOpeninNewTab = Keys.chord(Keys.CONTROL, "t"); if (webDriver.getWindowHandles() != null && webDriver.getWindowHandles().size() > 0) webDriver.findElement(By.tagName("body")).sendKeys(selectLinkOpeninNewTab); webDriver.get(appDesc.getUrl()); } else {/*from w w w. j av a 2 s .co m*/ Handset localDevice = PerfectoMobile.instance().devices().getDevice(deviceName); if (localDevice.getOs().toLowerCase().equals("ios")) PerfectoMobile.instance().application().open(executionId, deviceName, appDesc.getName(), appDesc.getAppleIdentifier()); else if (localDevice.getOs().toLowerCase().equals("android")) PerfectoMobile.instance().application().open(executionId, deviceName, appDesc.getName(), appDesc.getAndroidIdentifier()); else throw new IllegalArgumentException("Could not install application to " + localDevice.getOs()); if (webDriver instanceof ContextAware) ((ContextAware) webDriver).context("NATIVE_APP"); } return true; }
From source file:org.xmlium.test.web.commons.xml.XMLTestSteps.java
License:LGPL
protected void processStep(StepType step) throws Exception { WebElement element = null;/*w w w .j a va 2 s . c o m*/ Alert a = null; if (step.getScrollX() != null && step.getScrollY() != null) { JavascriptExecutor js = (JavascriptExecutor) getSuite().getDriver(); js.executeScript("window.scrollTo(" + step.getScrollX() + ", " + step.getScrollY() + ");"); } if (step.isBack() != null && step.isBack()) { getSuite().getDriver().navigate().back(); } if (step.isForward() != null && step.isForward()) { getSuite().getDriver().navigate().forward(); } Element e = null; if (step.getLoad() != null && step.getLoad().getKey() != null) { e = store.get(step.getLoad().getKey()); element = findElement(e.getFinds()); } if (step.getElement() != null) { if (step.getElement().getFinds() != null) { e = step.getElement(); checkStore(e); element = checkWaitFor(e); if (element == null && step.getElement().isCheckNullElement()) { return; } checkStoreValue(e, element); checkSetValue(e, element); checkSendKeys(e, element); checkClick(e, element); checkChangeState(e); checkText(e, element); checkMoveX(e, element); } } if (step.getSwitchTo() != null) { Object to = switchTo(step.getSwitchTo()); if (to instanceof Alert) { a = (Alert) to; if (step.getSwitchTo().getAlert() != null && step.getSwitchTo().getAlert().isAccept()) { a.accept(); } } else { a = null; } } if (step.getSelect() != null) { org.xmlium.testsuite.Select stepSelect = step.getSelect(); if (element != null && stepSelect.getSelectBy().getByIndex() != null) { Index index = stepSelect.getSelectBy().getByIndex(); SelectData selectData = new SelectData(); initSelectIndexes(element, index, selectData); if (selectData.selectIndex >= 0) { Select select = new Select(element); List<WebElement> options = select.getOptions(); WebElement option = options.get(selectData.selectIndex); option.click(); } else { throw new RuntimeException("selectedIndex=" + selectData.selectIndex); } } else { if (element == null) { element = findElement(step.getSelect().getFinds()); } if (element != null) { Select select = new Select(element); if (step.getSelect().getSelectBy() != null) { selectBy(select, step.getSelect().getSelectBy()); } } } } if (step.getPrettySelect() != null) { PrettySelect stepSelect = step.getPrettySelect(); if (element == null) { if (stepSelect.getFinds() != null) { element = findElement(stepSelect.getFinds()); } } if (element != null && stepSelect.getSelectBy() != null) { SelectData selectData = new SelectData(); Select select = null; select = new Select(element); Index index = null; if (stepSelect.getSelectBy().getByIndex() != null) { index = stepSelect.getSelectBy().getByIndex(); initSelectIndexes(element, index, selectData); } else if (stepSelect.getSelectBy().getByVisibleText() != null) { List<WebElement> elems = select.getOptions(); getOptionIndexBuVisibleText(stepSelect.getSelectBy().getByVisibleText(), elems, selectData); } if (selectData.selectIndex >= 0) { WebElement arrowArea = null; WebElement scrollArea = null; if (stepSelect.getSelectBy().getArrowArea() != null) { arrowArea = findElement(stepSelect.getSelectBy().getArrowArea()); } else { throw new RuntimeException("arrowArea not defined in xml"); } if (arrowArea != null) { arrowArea.click(); if (stepSelect.getSelectBy().getScrollArea() != null) { Finds scrollAreaFinds = stepSelect.getSelectBy().getScrollArea(); if (scrollAreaFinds.getFind() != null) { scrollArea = findElement(scrollAreaFinds.getFind()); } else if (scrollAreaFinds.getWaitFor() != null) { scrollArea = waitFor(scrollAreaFinds.getWaitFor()); } if (scrollArea == null) { if (scrollAreaFinds.getFind() != null || scrollAreaFinds.getWaitFor() != null) { String text = ""; if (scrollAreaFinds.getFind() != null && scrollAreaFinds.getFind().getByXPath() != null) { text = unformatValue(scrollAreaFinds.getFind().isUnformat(), scrollAreaFinds.getFind().getByXPath().getValue()); } else if (scrollAreaFinds.getWaitFor() != null && scrollAreaFinds.getWaitFor().getByXPath() != null) { text = unformatValue(scrollAreaFinds.getWaitFor().isUnformat(), scrollAreaFinds.getWaitFor().getByXPath().getValue()); } throw new RuntimeException("scrollArea not found: " + text); } else { throw new RuntimeException("scrollArea not defined in xml"); } } } if (index.isFirst() != null || index.isLast() != null) { Actions actions = new Actions(getSuite().getDriver()); String text = null; if (index.isFirst() != null && index.isFirst()) { actions.keyDown(Keys.CONTROL).sendKeys(Keys.HOME).perform(); } else if (index.isLast() != null && index.isLast()) { actions.keyDown(Keys.CONTROL).sendKeys(Keys.END).perform(); } if (index.isFirst() != null && index.isFirst()) { text = select.getOptions().get(0).getText(); } else if (index.isLast() != null && index.isLast()) { text = select.getOptions().get(select.getOptions().size() - 1).getText(); } if (stepSelect.getSelectBy().getOptionsTag() != null) { Find f = new Find(); ByXPath xPath = new ByXPath(); if (text != null && !text.isEmpty()) { xPath.setValue("//" + stepSelect.getSelectBy().getOptionsTag() + "[contains(@class, '" + stepSelect.getSelectBy().getOptionsClasses() + "') and text()='" + text + "']"); } else { xPath.setValue("(//" + stepSelect.getSelectBy().getOptionsTag() + "[contains(@class, '" + stepSelect.getSelectBy().getOptionsClasses() + "')])[" + Integer.toString(selectData.selectIndex + 1) + "]"); } f.setByXPath(xPath); WebElement optionElemnt = findElement(f); WebDriverWait wait = new WebDriverWait(getSuite().getDriver(), 30); wait.until(ExpectedConditions.elementToBeClickable(optionElemnt)); optionElemnt.click(); } } else { if (selectData.selectIndex < 0 || selectData.selectIndex >= select.getOptions().size()) { throw new RuntimeException("selectIndex: " + selectData.selectIndex + ", options.size: " + select.getOptions().size()); } WebElement option = select.getOptions().get(selectData.selectIndex); String text = option.getText(); if (text == null || text.isEmpty()) { logger.debug("text is null or empty: " + option); text = null; } if (stepSelect.getSelectBy().getOptionsTag() != null) { Find f = new Find(); ByXPath xPath = new ByXPath(); if (text != null) { xPath.setValue("//" + stepSelect.getSelectBy().getOptionsTag() + "[contains(@class, '" + stepSelect.getSelectBy().getOptionsClasses() + "') and text()='" + text + "']"); } else { xPath.setValue("(//" + stepSelect.getSelectBy().getOptionsTag() + "[contains(@class, '" + stepSelect.getSelectBy().getOptionsClasses() + "')])[" + Integer.toString(selectData.selectIndex + 1) + "]"); } f.setByXPath(xPath); WebElement optionElemnt = findElement(f); Coordinates coordinate = ((Locatable) optionElemnt).getCoordinates(); coordinate.onPage(); coordinate.inViewPort(); WebDriverWait wait = new WebDriverWait(getSuite().getDriver(), 30); wait.until(ExpectedConditions.elementToBeClickable(optionElemnt)); optionElemnt.click(); } } } else { throw new RuntimeException("can't click the arrow"); } } else if (stepSelect.getSelectBy().getByVisibleText() != null) { WebElement arrowArea = null; WebElement scrollArea = null; if (stepSelect.getSelectBy().getArrowArea() != null) { arrowArea = findElement(stepSelect.getSelectBy().getArrowArea()); } else { throw new RuntimeException("arrowArea not defined in xml"); } if (arrowArea != null) { arrowArea.click(); String scrollAreaXPath = null; if (stepSelect.getSelectBy().getScrollArea() != null) { Finds scrollAreaFinds = stepSelect.getSelectBy().getScrollArea(); if (scrollAreaFinds.getFind() != null) { scrollArea = findElement(scrollAreaFinds.getFind()); } else if (scrollAreaFinds.getWaitFor() != null) { scrollArea = waitFor(scrollAreaFinds.getWaitFor()); } if (scrollAreaXPath == null) { if (scrollAreaFinds.getFind() != null || scrollAreaFinds.getWaitFor() != null) { if (scrollAreaFinds.getFind() != null && scrollAreaFinds.getFind().getByXPath() != null) { scrollAreaXPath = unformatValue(scrollAreaFinds.getFind().isUnformat(), scrollAreaFinds.getFind().getByXPath().getValue()); } else if (scrollAreaFinds.getWaitFor() != null && scrollAreaFinds.getWaitFor().getByXPath() != null) { scrollAreaXPath = unformatValue(scrollAreaFinds.getWaitFor().isUnformat(), scrollAreaFinds.getWaitFor().getByXPath().getValue()); } // throw new RuntimeException("scrollArea // not found: " + text); } else { throw new RuntimeException("scrollArea not defined in xml"); } } } Actions actions = new Actions(getSuite().getDriver()); String text = null; // actions.keyDown(Keys.CONTROL).sendKeys(Keys.HOME).perform(); WebDriverWait wait = new WebDriverWait(getSuite().getDriver(), 30); wait.until(ExpectedConditions.elementToBeClickable(scrollArea)); actions.moveToElement(scrollArea).build().perform(); text = stepSelect.getSelectBy().getByVisibleText(); logger.debug("text: " + text); if (stepSelect.getSelectBy().getOptionsTag() != null) { Find f = new Find(); ByXPath xPath = new ByXPath(); if (text != null) { xPath.setValue(scrollAreaXPath + "/descendant::" + stepSelect.getSelectBy().getOptionsTag() + "[contains(@class, '" + stepSelect.getSelectBy().getOptionsClasses() + "') and text()='" + text + "']"); } else { xPath.setValue("(//" + stepSelect.getSelectBy().getOptionsTag() + "[contains(@class, '" + stepSelect.getSelectBy().getOptionsClasses() + "')])[" + Integer.toString(selectData.selectIndex + 1) + "]"); } f.setByXPath(xPath); logger.debug("xPath: " + xPath); WebElement optionElemnt = findElement(f); Coordinates coordinate = ((Locatable) optionElemnt).getCoordinates(); coordinate.onPage(); coordinate.inViewPort(); wait = new WebDriverWait(getSuite().getDriver(), 30); wait.until(ExpectedConditions.visibilityOf(optionElemnt)); actions.moveToElement(optionElemnt).click().build().perform(); } } } else { throw new RuntimeException("selectedIndex=" + selectData.selectIndex); } } else { if (element == null) { element = findElement(step.getPrettySelect().getFinds()); } if (element != null) { Select select = new Select(element); if (step.getPrettySelect().getSelectBy() != null) { selectBy(select, step.getPrettySelect().getSelectBy()); } } } } if (step.getSleepAfter() != null) { long sleep = step.getSleepAfter().longValue(); try { Thread.sleep(sleep); } catch (Exception e2) { // TODO: handle exception } } }
From source file:org.xmlium.test.web.commons.xml.XMLTestSteps.java
License:LGPL
protected void checkSetValue(Element e, WebElement element) throws Exception { if (e.getSetValue() != null && e.getSetValue().getKeys() != null) { BigDecimal operand1 = null; BigDecimal operand2 = null; String operation = null;// w w w . j av a 2s .c o m Boolean unformat = false; if (e.getFinds().getFind() != null) { unformat = e.getFinds().getFind().isUnformat(); } else { if (e.getFinds().getWaitFor() != null) { unformat = e.getFinds().getWaitFor().isUnformat(); } } Values values = e.getSetValue().getKeys(); List<String> keys = values.getKey(); if (keys == null) { throw new RuntimeException(e.toString() + "\n no values " + e + "!"); } String strValueExpression = unformatValue(unformat, e.getSetValue().getValueExpression()); if (strValueExpression == null || strValueExpression.isEmpty()) { throw new RuntimeException(e.toString() + " valueExpressionis null or empty!"); } String oldValue1 = null; String oldValue2 = null; if (keys.size() == 2) { oldValue1 = elementValuesMap.get(unformatValue(unformat, values.getKey().get(0))); oldValue2 = elementValuesMap.get(unformatValue(unformat, values.getKey().get(1))); if (oldValue1 == null) { throw new RuntimeException( e.toString() + "\n no value for key=" + values.getKey().get(0) + "!"); } if (oldValue2 == null) { throw new RuntimeException( e.toString() + "\n no value for key=" + values.getKey().get(1) + "!"); } } else if (keys.size() == 1) { oldValue1 = elementValuesMap.get(unformatValue(unformat, values.getKey().get(0))); if (oldValue1 == null) { throw new RuntimeException(e.toString() + "\n no value for key=" + unformatValue(unformat, values.getKey().get(0)) + "!"); } } if (oldValue1 != null && oldValue2 != null) { Matcher valueMatcher = valueExpressionStringPattern3.matcher(strValueExpression); if (valueMatcher.matches()) { String value1 = valueMatcher.group(1); // String value2 = valueMatcher.group(3); if (value1.equals("${0}")) { try { operand1 = (BigDecimal) getSuite().getCurrencyFormat().parse(oldValue1); operand2 = (BigDecimal) getSuite().getCurrencyFormat().parse(oldValue2); } catch (ParseException e2) { logger.error(e2.getMessage(), e2); } } else { try { operand2 = (BigDecimal) getSuite().getCurrencyFormat().parse(oldValue1); operand1 = (BigDecimal) getSuite().getCurrencyFormat().parse(oldValue2); } catch (ParseException e2) { logger.error(e2.getMessage(), e2); } } operation = valueMatcher.group(2); logger.debug("oldValue1=" + oldValue1); logger.debug("oldValue2=" + oldValue2); logger.debug("operand1=" + operand1); logger.debug("operand2=" + operand2); logger.debug("operation=" + operation); } else { throw new UnsupportedOperationException("not supported yet!"); } } else { Matcher valueMatcher1 = valueExpressionStringPattern1.matcher(strValueExpression); Matcher valueMatcher2 = valueExpressionStringPattern2.matcher(strValueExpression); if (valueMatcher1.matches()) { String newValue = valueMatcher1.group(1); operation = valueMatcher1.group(2); logger.debug("newValue=" + newValue); logger.debug("operation=" + operation); try { operand1 = (BigDecimal) getSuite().getCurrencyFormat().parse(newValue); operand2 = (BigDecimal) getSuite().getCurrencyFormat().parse(oldValue1); } catch (ParseException e2) { logger.error(e2.getMessage(), e2); } } else if (valueMatcher2.matches()) { String newValue = valueMatcher2.group(3); operation = valueMatcher2.group(2); logger.debug("newValue=" + newValue); logger.debug("operation=" + operation); try { operand2 = (BigDecimal) getSuite().getCurrencyFormat().parse(newValue); operand1 = (BigDecimal) getSuite().getCurrencyFormat().parse(oldValue1); } catch (ParseException e2) { logger.error(e2.getMessage(), e2); } } else { throw new UnsupportedOperationException("not supported yet!"); } } if (operand1 != null && operand2 != null && operation != null && !operation.isEmpty()) { BigDecimal value = computeValue(operation, operand1, operand2); try { element.sendKeys(Keys.chord(Keys.CONTROL, "a")); element.sendKeys(getSuite().getCurrencyFormat().format(value), Keys.ENTER); } catch (Exception e1) { logger.error(e, e1); throw e1; } } else { throw new RuntimeException(e.toString() + "operand1=" + operand1 + ", operand2=" + operand2 + ", operation=" + operation); } } else if (e.getSetValue() != null && e.getSetValue().getKeys() == null) { throw new RuntimeException(e.toString() + "\n key==null!"); } }
From source file:org.xwiki.annotation.test.po.AnnotatableViewPage.java
License:Open Source License
public void simulateCTRL_M() { WebElement body = getDriver().findElement(By.id("body")); body.sendKeys(Keys.chord(Keys.CONTROL, "m")); }
From source file:org.xwiki.flamingo.test.po.EditThemePage.java
License:Open Source License
public void setVariableValue(String variableName, String value) { WebElement variableField = getDriver() .findElement(By.xpath("//label[text() = '@" + variableName + "']/..//input")); // Remove the previous value variableField.sendKeys(Keys.chord(Keys.CONTROL, "a"), Keys.BACK_SPACE); // Write the one variableField.sendKeys(value);// w w w . j av a 2 s .c o m }
From source file:org.xwiki.test.selenium.AdministrationTest.java
License:Open Source License
@Test public void testCodeToExecutionAndAutoSandboxing() { String space = "Main"; String page = "TestConfigurable"; String codeToExecute = "#set($code = 's sh')" + "Thi${code}ould be displayed." + "#if($xcontext.hasProgrammingRights())" + "This should not be displayed." + "#end"; String heading = "#set($code = 'his sho')" + "T${code}uld also be displayed."; createConfigurableApplication(space, page, "TestSection6", true); open(space, page, "edit", "editor=object"); expandObject("XWiki.ConfigurableClass", 0); setFieldValue("XWiki.ConfigurableClass_0_codeToExecute", codeToExecute); setFieldValue("XWiki.ConfigurableClass_0_heading", heading); setFieldValue("XWiki.ConfigurableClass_0_configurationClass", ""); clickEditSaveAndView();//from w w w. ja v a 2 s . c om // Our admin will foolishly save XWiki.ConfigurableClass, giving it programming rights. open("XWiki", "ConfigurableClass", "edit", "editor=wiki"); try { // Since we modify ConfigurableClass, we must modify it back after to prevent polluting further tests. // See http://code.google.com/p/selenium/issues/detail?id=2876 . getDriver().findElement(By.id("content")).sendKeys(Keys.chord(Keys.CONTROL, "a"), Keys.chord(Keys.CONTROL, "c"), Keys.ARROW_RIGHT, "{{velocity}}Has Programming permission: $xcontext.hasProgrammingRights(){{/velocity}}"); clickEditSaveAndContinue(); // Now we look at the section for our configurable. open("XWiki", "ConfigurableClass", "view", "editor=globaladmin§ion=TestSection6"); assertTextPresent("This should be displayed."); assertTextPresent("This should also be displayed."); assertTextNotPresent("This should not be displayed."); assertTextPresent("Has Programming permission: false"); // Make sure javascript has not added a Save button. assertElementNotPresent("//div/div/p/span/input[@type='submit'][@value='Save']"); } finally { open("XWiki", "ConfigurableClass", "edit", "editor=wiki"); getDriver().findElement(By.id("content")).sendKeys(Keys.chord(Keys.CONTROL, "a"), Keys.chord(Keys.CONTROL, "v")); clickEditSaveAndContinue(); } }
From source file:org.xwiki.test.ui.annotations.elements.AnnotationsWindow.java
License:Open Source License
public void simulateCTRL_M() { RenderedWebElement body = (RenderedWebElement) getDriver().findElement(By.id("body")); body.sendKeys(Keys.CONTROL, "m"); }
From source file:org.xwiki.test.ui.WebDriverFactory.java
License:Open Source License
public WebDriver createWebDriver(String browserName) { WebDriver driver;// w ww.j ava 2 s .c o m if (browserName.startsWith("*firefox")) { // Native events are disabled by default for Firefox on Linux as it may cause tests which open many windows // in parallel to be unreliable. However, native events work quite well otherwise and are essential for some // of the new actions of the Advanced User Interaction. We need native events to be enable especially for // testing the WYSIWYG editor. See http://code.google.com/p/selenium/issues/detail?id=2331 . FirefoxProfile profile = new FirefoxProfile(); profile.setEnableNativeEvents(true); // Make sure Firefox doesn't upgrade automatically on CI agents. profile.setPreference("app.update.auto", false); profile.setPreference("app.update.enabled", false); profile.setPreference("app.update.silent", false); driver = new FirefoxDriver(profile); // Hide the Add-on bar (from the bottom of the window, with "WebDriver" written on the right) because it can // prevent buttons or links from being clicked when they are beneath it and native events are used. // See https://groups.google.com/forum/#!msg/selenium-users/gBozOynEjs8/XDxxQNmUSCsJ // We need to load a page before sending the keys otherwise WebDriver throws ElementNotVisible exception. driver.get("data:text/plain;charset=utf-8,XWiki"); driver.switchTo().activeElement().sendKeys(Keys.chord(Keys.CONTROL, "/")); } else if (browserName.startsWith("*iexplore")) { driver = new InternetExplorerDriver(); } else if (browserName.startsWith("*chrome")) { driver = new ChromeDriver(); } else if (browserName.startsWith("*phantomjs")) { DesiredCapabilities capabilities = DesiredCapabilities.phantomjs(); capabilities.setCapability("handlesAlerts", true); try { driver = new PhantomJSDriver(ResolvingPhantomJSDriverService.createDefaultService(), capabilities); } catch (IOException e) { throw new RuntimeException(e); } } else { throw new RuntimeException("Unsupported browser name [" + browserName + "]"); } // Maximize the browser window by default so that the page has a standard layout. Individual tests can resize // the browser window if they want to test how the page layout adapts to limited space. This reduces the // probability of a test failure caused by an unexpected layout (nested scroll bars, floating menu over links // and buttons and so on). driver.manage().window().maximize(); return driver; }
From source file:org.xwiki.test.wysiwyg.framework.AbstractWysiwygTestCase.java
License:Open Source License
public void selectAllContent() { getRichTextArea().sendKeys(Keys.chord(Keys.CONTROL, "a")); }
From source file:org.xwiki.test.wysiwyg.framework.AbstractWysiwygTestCase.java
License:Open Source License
public void typeControlEnter() { getRichTextArea().sendKeys(Keys.chord(Keys.CONTROL, Keys.RETURN)); }