List of usage examples for org.openqa.selenium.interactions Actions moveToElement
public Actions moveToElement(WebElement target)
From source file:org.aludratest.service.gui.web.selenium.selenium2.Selenium2Wrapper.java
License:Apache License
private void hover(WebElement element) { LOGGER.debug("hover(WebElement)"); try {//from ww w .ja v a 2 s . c o m element = LocatorSupport.unwrap(element); Actions actions = new Actions(driver); actions.moveToElement(element).build().perform(); } catch (Exception e) { handleSeleniumException(e); } }
From source file:org.apache.archiva.web.test.parent.AbstractSeleniumTest.java
License:Apache License
public <V> V tryClick(By clickableLocator, Function<? super WebDriver, V> conditions, String message, int attempts, int maxWaitTimeInS) { getWebDriver().manage().window().maximize(); int count = attempts; WebDriverWait wait = new WebDriverWait(getWebDriver(), maxWaitTimeInS); V result = null;/* w ww . j av a2 s .c om*/ Exception ex = null; WebElement el = null; while (count > 0) { try { el = wait.until(ExpectedConditions.elementToBeClickable(clickableLocator)); Actions actions = new Actions(getWebDriver()); actions.moveToElement(el).click().perform(); result = wait.until(conditions); return result; } catch (Exception e) { logger.info("Error: {}, {}, {}", count, e.getClass().getName(), e.getMessage()); if (el != null) { // Elements may be stale and throw an exception, if the location is requested try { Point elLoc = el.getLocation(); logger.info("Location: x={} y={}", elLoc.getX(), elLoc.getY()); } catch (Throwable e2) { logger.info("Could not determine location"); } } ex = e; count--; } try { Thread.currentThread().sleep(500); } catch (InterruptedException e) { // Ignore } } if (ex != null) { Assert.fail(message); } return result; }
From source file:org.apache.archiva.web.test.RepositoryAdminTest.java
License:Apache License
@Test public void testManagedRepository() { // login( getAdminUsername(), getAdminPassword() ); WebDriverWait wait = new WebDriverWait(getWebDriver(), 20); WebElement el;/*from www .j av a2 s . com*/ el = wait.until(ExpectedConditions.elementToBeClickable(By.id("menu-repositories-list-a"))); tryClick(el, ExpectedConditions.presenceOfElementLocated(By.id("managed-repositories-view-a")), "Managed Repositories not activated"); el = wait.until( ExpectedConditions.elementToBeClickable(By.xpath("//a[@href='#remote-repositories-content']"))); tryClick(el, ExpectedConditions.visibilityOfElementLocated( By.xpath("//table[@id='remote-repositories-table']//td[contains(text(),'central')]")), "Remote Repositories View not available"); el = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//a[@href='#remote-repository-edit']"))); el = tryClick(el, ExpectedConditions.visibilityOfElementLocated(By.id("remote-repository-save-button")), "Repository Save Button not available"); setFieldValue("id", "myrepoid"); setFieldValue("name", "My repo name"); setFieldValue("url", "http://www.repo.org"); el = wait.until(ExpectedConditions.elementToBeClickable(By.id("remote-repository-save-button"))); Actions actions = new Actions(getWebDriver()); actions.moveToElement(el); actions.perform(); ((JavascriptExecutor) getWebDriver()).executeScript("arguments[0].scrollIntoView();", el); el.click(); el = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("remote-repositories-view-a"))); ((JavascriptExecutor) getWebDriver()).executeScript("arguments[0].scrollIntoView();", el); tryClick(By.id("menu-proxy-connectors-list-a"), ExpectedConditions .visibilityOfElementLocated(By.id("proxy-connectors-view-tabs-a-network-proxies-grid")), "Network proxies not available", 3, 10); wait.until(ExpectedConditions.textToBePresentInElementLocated(By.id("main-content"), "Proxy Connectors")); // proxy connect wait.until(ExpectedConditions.textToBePresentInElementLocated(By.id("proxy-connectors-view"), "central")); assertTextNotPresent("myrepoid"); el = wait.until(ExpectedConditions.elementToBeClickable(By.id("proxy-connectors-view-tabs-a-edit"))); el.click(); el = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("proxy-connector-btn-save"))); wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("remote-repository-edit-fieldset"))); // Another hack, don't know why the normal selectValue() does not work here ((JavascriptExecutor) getWebDriver()).executeScript("jQuery('#sourceRepoId').css('display','block')"); Select select = new Select(getWebDriver().findElement(By.xpath(".//select[@id='sourceRepoId']"))); select.selectByVisibleText("internal"); // selectValue( "sourceRepoId", "internal", true ); // Workaround // TODO: Check after upgrade of htmlunit, bootstrap or jquery // TODO: Check whats wrong here ((JavascriptExecutor) getWebDriver()).executeScript("$('#targetRepoId').show();"); // End of Workaround wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("targetRepoId"))); selectValue("targetRepoId", "myrepoid"); el.click(); wait.until( ExpectedConditions.textToBePresentInElementLocated(By.id("user-messages"), "ProxyConnector added")); wait.until(ExpectedConditions.textToBePresentInElementLocated(By.id("proxy-connectors-view"), "central")); wait.until(ExpectedConditions.textToBePresentInElementLocated(By.id("proxy-connectors-view"), "myrepoid")); tryClick(By.xpath("//i[contains(@class,'icon-resize-vertical')]//ancestor::a"), ExpectedConditions.visibilityOfAllElementsLocatedBy(By.id("proxy-connector-edit-order-div")), "Edit order view not visible", 3, 10); // clickLinkWithXPath( "//i[contains(@class,'icon-resize-vertical')]//ancestor::a"); // This is needed here for HTMLUnit Tests. Currently do not know why, wait is not working for the // list entries down // waitPage(); // el = wait.until(ExpectedConditions.presenceOfElementLocated(By.id("proxy-connector-edit-order-div"))); assertTextPresent("internal"); List<WebElement> repos = wait.until(ExpectedConditions .numberOfElementsToBe(By.xpath("//div[@id='proxy-connector-edit-order-div']/div"), 2)); Assert.assertTrue("First repo is myrepo", repos.get(0).getText().contains("myrepoid")); Assert.assertTrue("Second repo is central", repos.get(1).getText().contains("central")); // works until this point /*getSelenium().mouseDown( "xpath=//div[@id='proxy-connector-edit-order-div']/div[1]" ); getSelenium().mouseMove( "xpath=//div[@id='proxy-connector-edit-order-div']/div[2]" ); getSelenium().mouseUp( "xpath=//div[@id='proxy-connector-edit-order-div']/div[last()]" ); Assert.assertTrue( "Second repo is myrepo", getSelenium().getText("xpath=//div[@id='proxy-connector-edit-order-div']/div[2]" ).contains( "myrepoid" )); Assert.assertTrue( "First repo is central", getSelenium().getText("xpath=//div[@id='proxy-connector-edit-order-div']/div[1]" ).contains( "central" )); */ }
From source file:org.apache.geode.tools.pulse.tests.ui.PulseBase.java
License:Apache License
public void testTreeMapPopUpData(String S1, String gridIcon) { for (int i = 1; i <= 3; i++) { searchByLinkAndClick(CLUSTER_VIEW_LABEL); if (gridIcon.equals(SERVER_GROUP_GRID_ID)) { WebElement ServerGroupRadio = getWebDriver() .findElement(By.xpath("//label[@for='radio-servergroups']")); ServerGroupRadio.click();// w ww .j a v a 2 s . co m } if (gridIcon.equals(REDUNDANCY_GRID_ID)) { WebElement ServerGroupRadio = getWebDriver() .findElement(By.xpath("//label[@for='radio-redundancyzones']")); ServerGroupRadio.click(); } searchByIdAndClick(gridIcon); WebElement TreeMapMember = getWebDriver() .findElement(By.xpath("//div[@id='" + S1 + "M" + (i) + "']/div")); Actions builder = new Actions(getWebDriver()); builder.clickAndHold(TreeMapMember).perform(); int j = 1; String CPUUsageM1temp = getWebDriver() .findElement(By.xpath("//div[@id='_tooltip']/div/div/div[2]/div/div[2]/div")).getText(); String CPUUsageM1 = CPUUsageM1temp.replaceAll("[\\%]", ""); String cpuUsageM1 = JMXProperties.getInstance().getProperty("member.M" + (i) + ".cpuUsage"); assertEquals(cpuUsageM1, CPUUsageM1); String MemoryUsageM1temp = getWebDriver() .findElement(By.xpath("//div[@id='_tooltip']/div/div/div[2]/div[" + (j + 1) + "]/div[2]/div")) .getText(); String MemoryUsageM1 = MemoryUsageM1temp.replaceAll("MB", ""); String memoryUsageM1 = JMXProperties.getInstance().getProperty("member.M" + (i) + ".UsedMemory"); assertEquals(memoryUsageM1, MemoryUsageM1); String LoadAvgM1 = getWebDriver() .findElement(By.xpath("//div[@id='_tooltip']/div/div/div[2]/div[" + (j + 2) + "]/div[2]/div")) .getText(); String loadAvgM1 = JMXProperties.getInstance().getProperty("member.M" + (i) + ".loadAverage"); assertEquals(new DecimalFormat(PulseConstants.DECIMAL_FORMAT_PATTERN).format(Double.valueOf(loadAvgM1)), LoadAvgM1); String ThreadsM1 = getWebDriver() .findElement(By.xpath("//div[@id='_tooltip']/div/div/div[2]/div[" + (j + 3) + "]/div[2]/div")) .getText(); String threadsM1 = JMXProperties.getInstance().getProperty("member.M" + (i) + ".numThreads"); assertEquals(threadsM1, ThreadsM1); String SocketsM1 = getWebDriver() .findElement(By.xpath("//div[@id='_tooltip']/div/div/div[2]/div[" + (j + 4) + "]/div[2]/div")) .getText(); String socketsM1 = JMXProperties.getInstance() .getProperty("member.M" + (i) + ".totalFileDescriptorOpen"); assertEquals(socketsM1, SocketsM1); builder.moveToElement(TreeMapMember).release().perform(); } }
From source file:org.apache.geode.tools.pulse.tests.ui.PulseBase.java
License:Apache License
@Test public void testDataViewTreeMapPopUpData() { searchByLinkAndClick(CLUSTER_VIEW_LABEL); searchByLinkAndClick(DATA_DROPDOWN_ID); WebElement TreeMapMember = getWebDriver().findElement(By.id("GraphTreeMapClusterData-canvas")); Actions builder = new Actions(getWebDriver()); builder.clickAndHold(TreeMapMember).perform(); String RegionType = getWebDriver() .findElement(By.xpath("//div[@id='_tooltip']/div/div/div[2]/div/div[2]/div")).getText(); String regionType = JMXProperties.getInstance().getProperty("region.R2.regionType"); assertEquals(regionType, RegionType); String EntryCount = getWebDriver() .findElement(By.xpath("//div[@id='_tooltip']/div/div/div[2]/div[2]/div[2]/div")).getText(); String entryCount = JMXProperties.getInstance().getProperty("region.R2.systemRegionEntryCount"); assertEquals(entryCount, EntryCount); String EntrySizetemp = getWebDriver() .findElement(By.xpath("//div[@id='_tooltip']/div/div/div[2]/div[3]/div[2]/div")).getText(); float EntrySize = Float.parseFloat(EntrySizetemp); float entrySize = Float.parseFloat(JMXProperties.getInstance().getProperty("region.R2.entrySize")); entrySize = entrySize / 1024 / 1024; entrySize = Float.parseFloat(new DecimalFormat("##.####").format(entrySize)); assertEquals(entrySize, EntrySize, 0.001); builder.moveToElement(TreeMapMember).release().perform(); }
From source file:org.apache.geode.tools.pulse.tests.ui.PulseTestUtils.java
License:Apache License
public static void mouseReleaseById(String id) { verifyElementPresentById(id);//from w ww.j a v a 2 s . co m Actions action = new Actions(getDriver()); WebElement we = getDriver().findElement(By.id(id)); action.moveToElement(we).release().perform(); }
From source file:org.apache.geode.tools.pulse.tests.ui.PulseTestUtils.java
License:Apache License
public static void mouseClickAndHoldOverElementById(String id) { verifyElementPresentById(id);/*from w w w. j av a 2s . c om*/ Actions action = new Actions(getDriver()); WebElement we = getDriver().findElement(By.id(id)); action.moveToElement(we).clickAndHold().perform(); }
From source file:org.apache.zeppelin.integration.ParagraphActionsIT.java
License:Apache License
@Test public void testCreateNewButton() throws Exception { try {// w w w . j a v a 2 s . co m createNewNote(); Actions action = new Actions(driver); waitForParagraph(1, "READY"); Integer oldNosOfParas = driver.findElements(By.xpath("//div[@ng-controller=\"ParagraphCtrl\"]")).size(); collector.checkThat("Before Insert New : the number of paragraph ", oldNosOfParas, CoreMatchers.equalTo(1)); driver.findElement(By.xpath(getParagraphXPath(1) + "//span[@class='icon-settings']")).click(); driver.findElement(By.xpath(getParagraphXPath(1) + "//ul/li/a[@ng-click=\"insertNew('below')\"]")) .click(); waitForParagraph(2, "READY"); Integer newNosOfParas = driver.findElements(By.xpath("//div[@ng-controller=\"ParagraphCtrl\"]")).size(); collector.checkThat("After Insert New (using Insert New button) : number of paragraph", oldNosOfParas + 1, CoreMatchers.equalTo(newNosOfParas)); driver.findElement(By.xpath(getParagraphXPath(1) + "//span[@class='icon-settings']")).click(); driver.findElement(By.xpath(getParagraphXPath(1) + "//ul/li/a[@ng-click='removeParagraph(paragraph)']")) .click(); ZeppelinITUtils.sleep(1000, false); driver.findElement(By.xpath("//div[@class='modal-dialog'][contains(.,'delete this paragraph')]" + "//div[@class='modal-footer']//button[contains(.,'OK')]")).click(); ZeppelinITUtils.sleep(1000, false); setTextOfParagraph(1, " original paragraph "); WebElement newPara = driver .findElement(By.xpath(getParagraphXPath(1) + "//div[contains(@class,'new-paragraph')][1]")); action.moveToElement(newPara).click().build().perform(); ZeppelinITUtils.sleep(1000, false); waitForParagraph(1, "READY"); collector.checkThat("Paragraph is created above", driver .findElement(By.xpath(getParagraphXPath(1) + "//div[contains(@class, 'editor')]")).getText(), CoreMatchers.equalTo(StringUtils.EMPTY)); setTextOfParagraph(1, " this is above "); newPara = driver .findElement(By.xpath(getParagraphXPath(2) + "//div[contains(@class,'new-paragraph')][2]")); action.moveToElement(newPara).click().build().perform(); waitForParagraph(3, "READY"); collector.checkThat("Paragraph is created below", driver .findElement(By.xpath(getParagraphXPath(3) + "//div[contains(@class, 'editor')]")).getText(), CoreMatchers.equalTo(StringUtils.EMPTY)); setTextOfParagraph(3, " this is below "); collector.checkThat("The output field of paragraph1 contains", driver .findElement(By.xpath(getParagraphXPath(1) + "//div[contains(@class, 'editor')]")).getText(), CoreMatchers.equalTo(" this is above ")); collector.checkThat("The output field paragraph2 contains", driver .findElement(By.xpath(getParagraphXPath(2) + "//div[contains(@class, 'editor')]")).getText(), CoreMatchers.equalTo(" original paragraph ")); collector.checkThat("The output field paragraph3 contains", driver .findElement(By.xpath(getParagraphXPath(3) + "//div[contains(@class, 'editor')]")).getText(), CoreMatchers.equalTo(" this is below ")); collector.checkThat("The current number of paragraphs after creating paragraph above and below", driver.findElements(By.xpath("//div[@ng-controller=\"ParagraphCtrl\"]")).size(), CoreMatchers.equalTo(3)); deleteTestNotebook(driver); } catch (Exception e) { handleException("Exception in ParagraphActionsIT while testCreateNewButton ", e); } }
From source file:org.auraframework.components.ui.InputTextUITest.java
License:Apache License
@TargetBrowsers({ BrowserType.GOOGLECHROME }) public void doTestUpdateOnAttributeWithCertainEventsChrome(String url) throws Exception { open(url);/*from w w w . ja va 2s . c o m*/ String value = getCurrentModelValue(); WebDriver d = getDriver(); Actions a = new Actions(d); WebElement outputDiv = findDomElement(By.id("output")); String eventName = "dblclick"; WebElement input = auraUITestingUtil.findElementAndTypeEventNameInIt(eventName); assertModelValue(value); a.doubleClick(input).build().perform(); value = assertModelValue(eventName); assertDomEventSet(); eventName = "mousemove"; input = auraUITestingUtil.findElementAndTypeEventNameInIt(eventName); assertModelValue(value); a.moveToElement(input).moveByOffset(0, 100).build().perform(); value = assertModelValue(eventName); assertDomEventSet(); eventName = "mouseout"; input = auraUITestingUtil.findElementAndTypeEventNameInIt(eventName); assertModelValue(value); a.moveToElement(input).moveToElement(outputDiv).build().perform(); value = assertModelValue(eventName); assertDomEventSet(); eventName = "mouseover"; input = auraUITestingUtil.findElementAndTypeEventNameInIt(eventName); assertModelValue(value); outputDiv.click(); a.moveToElement(input).build().perform(); value = assertModelValue(eventName); assertDomEventSet(); eventName = "mouseup"; input = auraUITestingUtil.findElementAndTypeEventNameInIt(eventName); assertModelValue(value); input.click(); value = assertModelValue(eventName); assertDomEventSet(); eventName = "select"; input = auraUITestingUtil.findElementAndTypeEventNameInIt(eventName); assertModelValue(value); a.doubleClick(input).build().perform(); value = assertModelValue(eventName); }
From source file:org.auraframework.integration.test.components.ui.inputText.InputTextUITest.java
License:Apache License
@TargetBrowsers({ BrowserType.GOOGLECHROME }) public void doTestUpdateOnAttributeWithCertainEventsChrome(String url) throws Exception { open(url);// w w w.ja v a 2s . c om String value = getCurrentModelValue(); WebDriver d = getDriver(); Actions a = new Actions(d); WebElement outputDiv = findDomElement(By.id("output")); String eventName = "dblclick"; WebElement input = getAuraUITestingUtil().findElementAndTypeEventNameInIt(eventName); assertModelValue(value, "Value shouldn't be updated yet."); a.doubleClick(input).build().perform(); value = assertModelValue(eventName); assertDomEventSet(); eventName = "mousemove"; input = getAuraUITestingUtil().findElementAndTypeEventNameInIt(eventName); assertModelValue(value, "Value shouldn't be updated yet."); a.moveToElement(input).moveByOffset(0, 100).build().perform(); value = assertModelValue(eventName); assertDomEventSet(); eventName = "mouseout"; input = getAuraUITestingUtil().findElementAndTypeEventNameInIt(eventName); assertModelValue(value, "Value shouldn't be updated yet."); a.moveToElement(input).moveToElement(outputDiv).build().perform(); value = assertModelValue(eventName); assertDomEventSet(); eventName = "mouseover"; input = getAuraUITestingUtil().findElementAndTypeEventNameInIt(eventName); assertModelValue(value, "Value shouldn't be updated yet."); outputDiv.click(); a.moveToElement(input).build().perform(); value = assertModelValue(eventName); assertDomEventSet(); eventName = "mouseup"; input = getAuraUITestingUtil().findElementAndTypeEventNameInIt(eventName); assertModelValue(value, "Value shouldn't be updated yet."); input.click(); value = assertModelValue(eventName); assertDomEventSet(); eventName = "select"; input = getAuraUITestingUtil().findElementAndTypeEventNameInIt(eventName); assertModelValue(value, "Value shouldn't be updated yet."); a.doubleClick(input).build().perform(); value = assertModelValue(eventName); }