List of usage examples for org.openqa.selenium.interactions Actions perform
public void perform()
From source file:org.openmrs.module.mirebalais.smoke.pageobjects.AbstractPageObject.java
License:Open Source License
public void hoverOn(By elementId) { Actions builder = new Actions(driver); Actions hover = builder.moveToElement(driver.findElement(elementId)); hover.perform(); }
From source file:org.rstudio.studio.selenium.DataImportTests.java
License:Open Source License
@Test public void testImportCSVFile() throws Exception { WebElement menuEntry = MenuNavigator.getMenuItem(driver_, "Tools", "Import Dataset", "From Text File..."); menuEntry.click();//from w w w .j a va 2 s.co m final WebElement importFileDialog = DialogTestUtils.waitForModalToAppear(driver_); DialogTestUtils.waitForFocusedInput(driver_, importFileDialog); Actions typeName = new Actions(driver_); File csvFile = new File("test/org/rstudio/studio/selenium/resources/banklist.csv"); typeName.sendKeys(csvFile.getAbsolutePath()); typeName.perform(); DialogTestUtils.respondToModalDialog(driver_, "Open"); // After a moment the modal prompting for the path will disappear, and // the modal prompting for input will appear. (new WebDriverWait(driver_, 5)).until(new ExpectedCondition<Boolean>() { public Boolean apply(WebDriver d) { List<WebElement> elements = driver_.findElements(By.className("gwt-DialogBox-ModalDialog")); if (elements.size() > 0) { if (elements.get(0).getText().contains("Import Dataset")) { return true; } } return false; } }); DialogTestUtils.respondToModalDialog(driver_, "Import"); ConsoleTestUtils.waitForConsoleContainsText(driver_, "read.csv"); // Once the CSV has been read, make sure all the rows made it to the // generated object ConsoleTestUtils.beginConsoleInteraction(driver_); (new Actions(driver_)).sendKeys(Keys.ESCAPE + "nrow(banklist)" + Keys.ENTER).perform(); ConsoleTestUtils.waitForConsoleContainsText(driver_, "515"); }
From source file:org.rstudio.studio.selenium.RConsoleInteraction.java
License:Open Source License
@Test public void testBasicRInteraction() { Actions do42 = new Actions(driver_); do42.sendKeys(Keys.chord(Keys.CONTROL, "l")); do42.sendKeys(Keys.ESCAPE); do42.sendKeys("41 + 1"); do42.sendKeys(Keys.ENTER); do42.perform(); ConsoleTestUtils.waitForConsoleContainsText(driver_, "42"); }
From source file:org.rstudio.studio.selenium.RConsoleInteraction.java
License:Open Source License
@Test public void testPopupCompletion() { // Test invoking autocomplete List<WebElement> elements = driver_ .findElements(By.id(ElementIds.getElementId(ElementIds.POPUP_COMPLETIONS))); assertEquals(elements.size(), 0);//from w w w .j a v a2 s . co m Actions popup = new Actions(driver_); popup.sendKeys(Keys.ESCAPE); popup.sendKeys("print"); popup.sendKeys(Keys.TAB); popup.perform(); (new WebDriverWait(driver_, 5)).until(new ExpectedCondition<Boolean>() { public Boolean apply(WebDriver d) { List<WebElement> elements = driver_ .findElements(By.id(ElementIds.getElementId(ElementIds.POPUP_COMPLETIONS))); return elements.size() > 0; } }); // Test cancelling autocomplete once invoked Actions close = new Actions(driver_); close.sendKeys(Keys.ESCAPE).perform(); (new WebDriverWait(driver_, 5)).until(new ExpectedCondition<Boolean>() { public Boolean apply(WebDriver d) { List<WebElement> elements = driver_ .findElements(By.id(ElementIds.getElementId(ElementIds.POPUP_COMPLETIONS))); return elements.size() == 0; } }); }
From source file:org.rstudio.studio.selenium.RConsoleInteraction.java
License:Open Source License
@Test public void testPlotGeneration() { ConsoleTestUtils.resumeConsoleInteraction(driver_); Actions plotCars = new Actions(driver_); plotCars.sendKeys(Keys.ESCAPE + "plot(cars)" + Keys.ENTER); plotCars.perform(); // Wait for the Plot window to activate final WebElement plotWindow = (new WebDriverWait(driver_, 5)).until(ExpectedConditions .presenceOfElementLocated(By.id(ElementIds.getElementId(ElementIds.PLOT_IMAGE_FRAME)))); // Wait for a plot to appear in the window Assert.assertEquals(plotWindow.getTagName(), "iframe"); driver_.switchTo().frame(plotWindow); (new WebDriverWait(driver_, 5)).until(ExpectedConditions.presenceOfElementLocated(By.tagName("img"))); // Switch back to document context driver_.switchTo().defaultContent(); }
From source file:org.rstudio.studio.selenium.RConsoleInteraction.java
License:Open Source License
@Test public void testInvokeHelp() { ConsoleTestUtils.resumeConsoleInteraction(driver_); Actions help = new Actions(driver_); help.sendKeys(Keys.ESCAPE + "?lapply" + Keys.ENTER); help.perform(); // Wait for the Help window to activate final WebElement helpWindow = (new WebDriverWait(driver_, 5)).until( ExpectedConditions.presenceOfElementLocated(By.id(ElementIds.getElementId(ElementIds.HELP_FRAME)))); // Wait for help to appear in the window Assert.assertEquals(helpWindow.getTagName(), "iframe"); driver_.switchTo().frame(helpWindow); (new WebDriverWait(driver_, 5)) .until(ExpectedConditions.textToBePresentInElement(By.tagName("body"), "lapply")); // Switch back to document context driver_.switchTo().defaultContent(); }
From source file:org.rstudio.studio.selenium.SourceInteraction.java
License:Open Source License
@Test public void createAndSourceRFile() { createRFile();//from w w w. j a va 2 s. com // Type some code into the file. Note that the matching brace is auto // completed. Actions a = new Actions(driver_); a.sendKeys("f <- function() {" + Keys.ENTER); a.sendKeys(Keys.TAB + "42"); a.perform(); // Source the entire file WebElement sourceMenuEntry = MenuNavigator.getMenuItem(driver_, "Code", "Source"); sourceMenuEntry.click(); // Wait for the console to contain the string "source" ConsoleTestUtils.waitForConsoleContainsText(driver_, "source("); closeUnsavedRFile(); }
From source file:org.rstudio.studio.selenium.SourceInteraction.java
License:Open Source License
@Test public void findAndReplace() { createRFile();/*from w w w.j ava2s. c o m*/ // Type some code into the file String preReplaceCode = "foo <- 'bar'"; Actions a = new Actions(driver_); a.sendKeys(preReplaceCode + Keys.ENTER); a.perform(); // Find the ACE editor instance that the code appears in. (CONSIDER: // This is not the best way to find the code editor instance.) WebElement editor = null; List<WebElement> editors = driver_.findElements(By.className("ace_content")); for (WebElement e : editors) { if (e.getText().contains(preReplaceCode)) { editor = e; break; } } Assert.assertNotNull(editor); // Invoke find and replace WebElement findMenuEntry = MenuNavigator.getMenuItem(driver_, "Edit", "Find..."); findMenuEntry.click(); // Wait for the find and replace panel to come up (new WebDriverWait(driver_, 2)).until(ExpectedConditions .presenceOfElementLocated(By.id(ElementIds.getElementId(ElementIds.FIND_REPLACE_BAR)))); // Type the text and the text to be replaced (replace 'bar' with 'foo') Actions rep = new Actions(driver_); rep.sendKeys("bar" + Keys.TAB + "foo" + Keys.ENTER); rep.perform(); DialogTestUtils.respondToModalDialog(driver_, "OK"); Actions dismiss = new Actions(driver_); dismiss.sendKeys(Keys.ESCAPE); dismiss.perform(); // Ensure that the source has been updated Assert.assertTrue(editor.getText().contains("foo <- 'foo'")); closeUnsavedRFile(); }
From source file:org.safs.selenium.webdriver.DCDriverCommand.java
License:Open Source License
private void setFocus() { String debugmsg = StringUtils.debugmsg(false); if (params.size() < 2) { issueParameterCountFailure();/* w ww . ja va 2 s .co m*/ return; } Iterator<?> iterator = params.iterator(); String window = (String) iterator.next(); String component = (String) iterator.next(); IndependantLog.debug(debugmsg + " Setting focus to " + window + ":" + component); testRecordData.setWindowName(window); testRecordData.setCompName(component); boolean focused = false; boolean isWindow = window.equalsIgnoreCase(component); String winCompString = isWindow ? window : window + ":" + component; //wait for window and component object try { WebDriver webdriver = WDLibrary.getWebDriver(); //wait for window and component object long timeout = isWindow ? getSecsWaitForWindow() : getSecsWaitForComponent(); int status = wdgu.waitForObject(testRecordData.getAppMapName(), window, component, timeout); if (status == 0) { //TODO focus the window, How to??? focusWindow(webdriver); if (!isWindow) { //focus the component WebElement element = WDLibrary.getObject(testRecordData.getCompGuiId()); Actions focusAction = new Actions(webdriver).moveToElement(element); if ("EditBox".equalsIgnoreCase(WebDriverGUIUtilities.getCompType(element))) focusAction = focusAction.click(); focusAction.perform(); } focused = true; } else { IndependantLog.error(debugmsg + " cannot find " + winCompString); } } catch (Exception e) { IndependantLog.error( debugmsg + " cannot set focus to " + winCompString + " due to " + StringUtils.debugmsg(e)); } if (focused) { testRecordData.setStatusCode(StatusCodes.NO_SCRIPT_FAILURE); String msg = genericText.convert(TXT_SUCCESS_2, winCompString + " " + testRecordData.getCommand() + " successful.", winCompString, testRecordData.getCommand()); log.logMessage(testRecordData.getFac(), msg, GENERIC_MESSAGE); } else { issueErrorPerformingAction(FAILStrings.convert(FAILStrings.SOMETHING_NOT_FOUND, winCompString + " was not focused.", winCompString)); } }
From source file:org.safs.selenium.webdriver.lib.Component.java
License:Open Source License
/** * <em>Purpose:</em> Remove the content from Component Box, like Edit Box, Combo box.<br> * //from w ww. ja v a 2s. co m * @param libName String, the concrete Component name of class, which calls 'clearComponentBox()' method, * like 'EditBox', 'ComboBox'. * */ public void clearComponentBox(String libName) throws SeleniumPlusException { String debugmsg = getClass().getName() + ".clearComponentBox(): "; try { try { // chrome and ie are failing element.clear webelement.clear(); } catch (StaleElementReferenceException sere) { IndependantLog.warn(debugmsg + "Met " + StringUtils.debugmsg(sere)); //fresh the element and clear again. refresh(false); webelement.clear(); } //Selenium API clear() will sometimes redraw the Web Element on the page, //which will cause StaleElementReferenceException, we need to refresh it if stale refresh(true); } catch (NoSuchElementException msee) { IndependantLog.debug(debugmsg + "NoSuchElementException --Object not found."); throw new SeleniumPlusException(libName + " object not found"); } catch (Exception e) { IndependantLog.debug(debugmsg + "Met " + StringUtils.debugmsg(e)); try { refresh(true); webelement.sendKeys(Keys.chord(Keys.CONTROL, "a"), Keys.DELETE); } catch (Exception x) { IndependantLog.debug(debugmsg + "Met " + StringUtils.debugmsg(x)); try { refresh(true); Actions delete = new Actions(WDLibrary.getWebDriver()); delete.sendKeys(webelement, Keys.chord(Keys.CONTROL, "a"), Keys.DELETE); delete.perform(); } catch (Exception ex) { IndependantLog .warn(debugmsg + libName + " clear action failed, Met " + StringUtils.debugmsg(ex)); } } } finally { IndependantLog.debug(debugmsg + "Finally use SAFS Robot to clear again."); WDLibrary.inputKeys(webelement, "^a{Delete}"); } }