default Actions actions() { return new Actions(getWebDriver()); } }
@Override public SelenideElement execute(SelenideElement proxy, WebElementSource locator, Object[] args) { WebElement element = locator.getWebElement(); new Actions(locator.driver().getWebDriver()).moveToElement(element).perform(); return proxy; } }
@Override public SelenideElement execute(SelenideElement proxy, WebElementSource locator, Object[] args) { SelenideElement target; if (args[0] instanceof String) { target = ElementFinder.wrap(locator.driver(), By.cssSelector((String) args[0])); } else if (args[0] instanceof WebElement) { target = WebElementWrapper.wrap(locator.driver(), (WebElement) args[0]); } else { throw new IllegalArgumentException("Unknown target type: " + args[0] + " (only String or WebElement are supported)"); } target.shouldBe(visible); new Actions(locator.driver().getWebDriver()).dragAndDrop(locator.getWebElement(), target).perform(); return proxy; } }
@BeforeEach public void setup(@TempDirectory.TempDir Path folder) throws IOException { Assumptions.assumeTrue(Boolean.getBoolean("smoke.test"), "Smoke tests disabled (set System property 'smoke.test')"); this.downloadDir = folder.toFile(); FirefoxProfile fxProfile = new FirefoxProfile(); fxProfile.setPreference("browser.download.folderList", 2); fxProfile.setPreference("browser.download.manager.showWhenStarting", false); fxProfile.setPreference("browser.download.dir", this.downloadDir.getAbsolutePath()); fxProfile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/zip,application/x-compress,application/octet-stream"); FirefoxOptions options = new FirefoxOptions().setProfile(fxProfile); this.driver = new FirefoxDriver(options); ((JavascriptExecutor) this.driver).executeScript("window.focus();"); Actions actions = new Actions(this.driver); this.enterAction = actions.sendKeys(Keys.ENTER).build(); }
private void moveToElement(WebElement element) { new Actions(browser.driver).moveToElement(element).perform(); }
/** * Waits and verifies that the texts of user status messages in the page are equal to the expected texts. * The check is done multiple times with waiting times in between to account for * timing issues due to page load, inconsistencies in Selenium API, etc. */ public void waitForTextsForAllStatusMessagesToUserEquals(String firstExpectedText, String... remainingExpectedTexts) { List<String> expectedTexts = Arrays.asList(ObjectArrays.concat(firstExpectedText, remainingExpectedTexts)); try { uiRetryManager.runUntilNoRecognizedException(new RetryableTask("Verify status to user") { @Override public void run() { // Scroll to status message because it must be visible in order to get its text new Actions(browser.driver).moveToElement(statusMessage).perform(); waitForElementVisibility(statusMessage); assertEquals(expectedTexts, getTextsForAllStatusMessagesToUser()); } }, WebDriverException.class, AssertionError.class); } catch (MaximumRetriesExceededException e) { assertEquals(expectedTexts, getTextsForAllStatusMessagesToUser()); } }
public void verifyProfilePhoto(String courseId, String studentName, String urlRegex) { String rowId = getStudentRowId(courseId, studentName); verifyImageUrl(urlRegex, browser.driver .findElement(By.id("studentphoto-c" + rowId)) .findElement(By.tagName("img")) .getAttribute("src")); WebElement photo = browser.driver.findElement(By.id("studentphoto-c" + rowId)) .findElement(By.cssSelector(".profile-pic-icon-click > img")); JavascriptExecutor jsExecutor = (JavascriptExecutor) browser.driver; jsExecutor.executeScript("arguments[0].scrollIntoView(true); window.scrollBy(0, -100);", photo); Actions action = new Actions(browser.driver); action.click(photo).build().perform(); verifyImageUrl(urlRegex, browser.driver .findElement(By.id("studentphoto-c" + rowId)) .findElement(By.cssSelector(".popover-content > .profile-pic")) .getAttribute("src")); }
/** * Scrolls element to first cell in spreadsheet, clicks on it and sends the value as keystrokes. */ void scrollElementToFirstCellAndSendKeys(WebElement spreadsheetElement, String value) { new Actions(browser.driver).moveToElement(spreadsheetElement) .click().sendKeys(value).build().perform(); }
@Override public void run() { // Scroll to status message because it must be visible in order to get its text new Actions(browser.driver).moveToElement(statusMessage).perform(); waitForElementVisibility(statusMessage); assertEquals(expectedTexts, getTextsForAllStatusMessagesToUser()); } }, WebDriverException.class, AssertionError.class);
public void dragAndDropQuestionOption(String qnType, int qnNumber, int sourceIndex, int targetIndex) throws Exception { WebElement draggedOptionElement = browser.driver.findElement(By.xpath("//div[@id='" + qnType + "OptionRow-" + sourceIndex + "-" + qnNumber + "']//span[@class='glyphicon glyphicon-resize-vertical']")); WebElement targetElement = browser.driver.findElement(By.xpath("//div[@id='" + qnType + "OptionRow-" + targetIndex + "-" + qnNumber + "']//span[@class='glyphicon glyphicon-resize-vertical']")); Actions builder = new Actions(browser.driver); // drag option to target, move 10 units above target and release // multiple movements are used to slow down drag movement and provide // enough time for the grid to create empty slots builder.clickAndHold(draggedOptionElement) .moveToElement(targetElement) .moveToElement(targetElement, 0, -10) .release() .build() .perform(); }
@Override public void execute(WebElement e) { Actions action = new Actions(frontEndDriver.getWebDriver()); action.doubleClick(e); action.perform(); e.click(); } });
public Actions withAction() { WebDriver proxiedDriver = (getDriver() instanceof WebElementFacade) ? ((WebDriverFacade) getDriver()).getProxiedDriver() : getDriver(); return new Actions(proxiedDriver); }
public J append(String text) { invoker.doJAction("Append text to Element", () -> { Actions builder = new Actions(getDriver()); builder.sendKeys(getWebElement(), text).perform(); }); return this; }
public SelenideElement pressEscape() { invoker.doJAction("Press Escape on Element", () -> { Actions builder = new Actions(getDriver()); builder.sendKeys(getWebElement(), Keys.ESCAPE).perform(); }); return this; }
@Override public boolean run(TestRun ctx) { new Actions(ctx.driver()).clickAndHold(ctx.locator("locator").find(ctx)).build().perform(); return true; } }
private void dragAndDropWithOffset(final WebElement source, final WebElement target, final int offset) { Point currentLocation = source.getLocation(); Point destination = target.getLocation(); // We need to ensure we have the source in view. An egrgarious hack to make sure we can do this. // Assumes that scrolling to the top of the page will have our source AND target in the viewable area driver.findElement(By.tagName("body")).getSize(); int xOffset = destination.x - currentLocation.x + 1; int yOffset = destination.y - currentLocation.y + offset; Actions action = new Actions(driver).dragAndDropBy(source, xOffset, yOffset); action.perform(); }
public EditIssueTypeSchemePage selectIssueType(String issueType) { final WebElement source = getIssueTypeListItemFromAvailableOptions(issueType); assertNotNull("Could not find element for issue type in 'Available Options'.", source); final Actions actions = new Actions(driver) .dragAndDrop(source, selectedOptionsWebElement); ((Locatable)source).getCoordinates().inViewPort(); //scrolls the page to make this element visible in the viewport actions.build().perform(); return this; }
@Override public void doDoubleClick() { DriverListener.setMessages(Messager.ELEMENT_DOUBLE_CLICKED.getMessage(getName()), Messager.ELEMENT_NOT_DOUBLE_CLICKED.getMessage(getNameWithLocator())); WebDriver drv = getDriver(); Actions action = new Actions(drv); action.moveToElement(element).doubleClick(element).build().perform(); }
@Override public void doRightClick() { DriverListener.setMessages(Messager.ELEMENT_RIGHT_CLICKED.getMessage(getName()), Messager.ELEMENT_NOT_RIGHT_CLICKED.getMessage(getNameWithLocator())); WebDriver drv = getDriver(); Actions action = new Actions(drv); action.moveToElement(element).contextClick(element).build().perform(); }
@Override public void doHover(Integer xOffset, Integer yOffset) { DriverListener.setMessages(Messager.ELEMENT_HOVERED.getMessage(getName()), Messager.ELEMENT_NOT_HOVERED.getMessage(getNameWithLocator())); WebDriver drv = getDriver(); Actions action = new Actions(drv); if (xOffset != null && yOffset!= null) { action.moveToElement(element, xOffset, yOffset).build().perform(); } else { action.moveToElement(element).build().perform(); } }