List of usage examples for org.openqa.selenium.interactions Actions moveToElement
public Actions moveToElement(WebElement target)
From source file:com.virtusa.isq.vtaf.runtime.SeleniumTestBase.java
License:Apache License
/** * Double clicks on a link, button, checkbox or radio button. If the double * click action causes a new page to load <br> * (like a link usually does), call waitForPageToLoad. <br> * <br>//from w w w . j a v a2 s.com * * @param locator * the locator */ private void doDoubleClick(final ObjectLocator locator) { // Retrieve the actual object name from the object repository int counter = getRetryCount(); WebDriver driver = getDriver(); String objectName = locator.getLogicalName(); String objectID = locator.getActualLocator(); try { // First chacking whether the element is present checkForNewWindowPopups(); WebElement element = checkElementPresence(objectID); /* * START DESCRIPTION following for loop was added to make the * command more consistent try the command for give amount of time * (can be configured through class variable RETRY) command will be * tried for "RETRY" amount of times or until command works. any * exception thrown within the tries will be handled internally. * * can be exited from the loop under 2 conditions 1. if the command * succeeded 2. if the RETRY count is exceeded */ while (counter > 0) { try { counter--; element.click(); Actions dClick = new Actions(driver); dClick.moveToElement(element).doubleClick(); dClick.build().perform(); /* selenium.doubleClick(objectID); */ reportresult(true, "DOUBLE CLICK :" + objectName + "", "PASSED", ""); break; } catch (StaleElementReferenceException staleElementException) { element = checkElementPresence(objectID); } catch (Exception e) { sleep(retryInterval); if (!(counter > 0)) { e.printStackTrace(); reportresult(true, "DOUBLE CLICK :" + objectName + "", "FAILED", "DOUBLE CLICK command cannot access Element (" + objectName + ") [" + objectID + "] "); checkTrue(false, true, "DOUBLE CLICK command cannot access Element (" + objectName + ") [" + objectID + "] "); } } } /* * END DESCRIPTION */ } catch (Exception e) { // if object not found exception is raised fail the test cases e.printStackTrace(); reportresult(true, "DOUBLE CLICK :" + objectName + "", "FAILED", "DOUBLE CLICK command :Element (" + objectName + ") [" + objectID + "] not present"); checkTrue(false, true, "DOUBLE CLICK command :Element (" + objectName + ") [" + objectID + "] not present"); } }
From source file:com.virtusa.isq.vtaf.runtime.SeleniumTestBase.java
License:Apache License
/** * Simulates a keypress in to an input field as though you typed it key by * key from the keyboard.<br>//from w w w . j a va2s.c o m * The keys should be seperated form a | charater to be typed correctly.<br> * <br> * * Example: A|B|C|ctrl|\n|\t|1|2|3 <br> * <br> * * @param objectName * : Logical name of the web element assigned by the automation * scripter * @param objValue * the obj value */ public final void keyPress(final String objectName, final Object objValue) { String value = checkNullObject(objValue, "KEYPRESS"); WebDriver driver = getDriver(); int counter = getRetryCount(); String[] valueStringsArr = value.split("\\|"); // Getting the actual object identification from the object map String objectID = ObjectMap.getObjectSearchPath(objectName, locatorIdentifire); try { // Check whether the element present checkForNewWindowPopups(); WebElement element = checkElementPresence(objectID); /* * START DESCRIPTION following for loop was added to make the * command more consistent try the command for give amount of time * (can be configured through class variable RETRY) command will be * tried for "RETRY" amount of times or until command works. any * exception thrown within the tries will be handled internally. * * can be exited from the loop under 2 conditions 1. if the command * succeeded 2. if the RETRY count is exceeded */ while (counter > 0) { try { counter--; // Calling the actual command element.sendKeys(""); Actions getFocus = new Actions(driver); getFocus.moveToElement(element).build().perform(); for (int strLocation = 0; strLocation < valueStringsArr.length; strLocation++) { if (!valueStringsArr[strLocation].isEmpty()) { super.sleep(Integer.parseInt("1000")); type(valueStringsArr[strLocation]); } } reportresult(true, "KEYPRESS :" + objectName + "", "PASSED", "Input Value = " + value); break; } catch (StaleElementReferenceException staleElementException) { element = checkElementPresence(objectID); } catch (Exception e) { sleep(retryInterval); if (!(counter > 0)) { e.printStackTrace(); reportresult(true, "KEYPRESS :" + objectName + "", "FAILED", "KEYPRESS command cannot access :Element (" + objectName + ") [" + objectID + "] [Input Value = " + value + "]"); checkTrue(false, true, "KEYPRESS command cannot access :Element (" + objectName + ") [" + objectID + "] [Input Value = " + value + "]"); } } } /* * END DESCRIPTION */ } catch (Exception e) { // if any exception was raised, report a test failure e.printStackTrace(); reportresult(true, "KEYPRESS :" + objectName + "", "FAILED", "KEYPRESS command :Element (" + objectName + ") [" + objectID + "] [Input Value = " + value + "] not present"); checkTrue(false, true, "KEYPRESS command :Element (" + objectName + ") [" + objectID + "] [Input Value = " + value + "] not present"); } }
From source file:com.virtusa.isq.vtaf.runtime.SeleniumTestBase.java
License:Apache License
/** * Simulates a user hovering a mouse over the specified element. <br> * //www.j a v a2s . co m * @param objectName * : Logical name of the web element assigned by the automation * scripter * * */ public final void mouseOver(final String objectName) { String objectID = ""; int counter = getRetryCount(); WebDriver driver = getDriver(); try { // Retrieve the correct object locator from the object map objectID = ObjectMap.getObjectSearchPath(objectName, locatorIdentifire); // first verify whether the element is present in the current web // pagge checkForNewWindowPopups(); WebElement element = checkElementPresence(objectID); /* * START DESCRIPTION following while loop was added to make the * command more consistent try the command for give amount of time * (can be configured through class variable RETRY) command will be * tried for "RETRY" amount of times untill command works. any * exception thrown within the tries will be handled internally. * * can be exitted from the loop under 2 conditions 1. if the command * succeeded 2. if the RETRY count is exceeded */ while (counter > 0) { try { counter--; Actions builder = new Actions(driver); // call for selenium web driver command builder.moveToElement(element).build().perform(); // if not exception is called consider and report the result // as passed reportresult(true, "MOUSE OVER :" + objectName + "", "PASSED", ""); // if the testcase passed move out from the loop break; } catch (StaleElementReferenceException staleElementException) { element = checkElementPresence(objectID); } catch (Exception e) { sleep(retryInterval); if (!(counter > 0)) { e.printStackTrace(); reportresult(true, "MOUSE OVER :" + objectName + "", "FAILED", "MOUSE OVER command cannot access Element (" + objectName + ") [" + objectID + "] "); checkTrue(false, true, "MOUSE OVER command cannot access Element (" + objectName + ") [" + objectID + "] "); } } } /* * END DESCRIPTION */ } catch (Exception e) { e.printStackTrace(); /* * VTAF result reporter call */ reportresult(true, "MOUSE OVER :" + objectName + "", "FAILED", "MOUSE OVER command :Element (" + objectName + ") [" + objectID + "] not present"); /* * VTAF specific validation framework reporting */ checkTrue(false, true, "MOUSE OVER command :Element (" + objectName + ") [" + objectID + "] not present"); } }
From source file:com.virtusa.isq.vtaf.runtime.SeleniumTestBase.java
License:Apache License
/** * Right clicks on an web element.//from w ww . ja v a2s . co m * * @param objectName * : Logical name of the object to be doubleclicked. * * */ public final void rightClick(final String objectName) { // Retrieve the actual object name from the object repository String objectID = ObjectMap.getObjectSearchPath(objectName, locatorIdentifire); int counter = getRetryCount(); try { // First chacking whether the element is present checkForNewWindowPopups(); WebElement element = checkElementPresence(objectID); /* * START DESCRIPTION following for loop was added to make the * command more consistent try the command for give amount of time * (can be configured through class variable RETRY) command will be * tried for "RETRY" amount of times or until command works. any * exception thrown within the tries will be handled internally. * * can be exited from the loop under 2 conditions 1. if the command * succeeded 2. if the RETRY count is exceeded */ while (counter > 0) { try { counter--; Actions rClick = new Actions(getDriver()); rClick.moveToElement(element).contextClick(element); rClick.build().perform(); /* selenium.doubleClick(objectID); */ reportresult(true, "RIGHT CLICK :" + objectName + "", "PASSED", ""); break; } catch (StaleElementReferenceException staleElementException) { element = checkElementPresence(objectID); } catch (Exception e) { // TODO Auto-generated catch block if (!(counter > 0)) { e.printStackTrace(); reportresult(true, "RIGHT CLICK :" + objectName + "", "FAILED", "RIGHT CLICK command cannot access Element (" + objectName + ") [" + objectID + "] "); checkTrue(false, true, "RIGHT CLICK command cannot access Element (" + objectName + ") [" + objectID + "] "); } } } /* * END DESCRIPTION */ } catch (Exception e) { // if object not found exception is raised fail the test cases e.printStackTrace(); reportresult(true, "RIGHT CLICK :" + objectName + "", "FAILED", "RIGHT CLICK command :Element (" + objectName + ") [" + objectID + "] not present"); checkTrue(false, true, "RIGHT CLICK command :Element (" + objectName + ") [" + objectID + "] not present"); } }
From source file:com.virtusa.isq.vtaf.runtime.SeleniumTestBase.java
License:Apache License
/** * Checks the contents of a bar chart against the expected values. *///from www . j av a 2s . co m private StringBuffer insightBarChartContentCheck(String chartName, ArrayList<String> chartnames, ArrayList<String> chartvalues, ArrayList<String> chartpercentages, int startingele, String chartElementXpath) { // Portlet content variables WebDriver driver = getDriver(); ArrayList<String> chartelementnames = chartnames; ArrayList<String> chartelementvalues = chartvalues; ArrayList<String> chartpercentage = chartpercentages; int startingelement = startingele; int arraycounter = 0; StringBuffer verificationErrors = new StringBuffer(); int actCategoryCount = 0; int actElementCnt = 0; int elementOffset = 0; int firstChild = 0; ArrayList<String> htmlElementNames = new ArrayList<String>(); ArrayList<String> htmlElementValues = new ArrayList<String>(); Actions action = new Actions(driver); jsExecutor = (JavascriptExecutor) driver; // Checking chart structure // The first loop of the pie chart check if (chartName.contains("text")) { elementOffset = 3; firstChild = 4; } else if (chartName.contains("img")) { elementOffset = 2; firstChild = 3; } List<WebElement> locateElementsThree = driver.findElements(By .xpath(chartName + "//child::*[position()=" + firstChild + " and name()='g']/child::*[position()=2 " + "and name()='g']/child::*[position()=2 " + "and name()='g']/child::*[name()='rect']")); System.out.println("### :" + locateElementsThree); actCategoryCount = locateElementsThree.size(); List<WebElement> locateElementsFour = driver .findElements(By.xpath(chartName + "//child::*[position()=2 and name()='g']")); actElementCnt = locateElementsFour.size(); for (int i = startingelement; i < actCategoryCount + startingelement; i++) { // Accessing the elements in the pie chart // ELEMENT ELEMENT ELEMENT ELEMENT ELEMENT ELEMENT ELEMENT ELEMENT // ELEMENT ELEMENT ELEMENT try { try { action = new Actions(driver); action = new Actions(driver); WebElement chartHeaderEle = driver.findElement(By.xpath(chartElementXpath)); jsExecutor.executeScript("var evObj = document.createEvent('MouseEvents');" + "evObj.initMouseEvent(\"mouseover\",true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);" + "arguments[0].dispatchEvent(evObj);", chartHeaderEle); Thread.sleep(1000); WebElement elementTwo = driver.findElement(By.xpath(chartName + "//child::*[position()=" + firstChild + " and name()='g']/child::*[position()=2 and name()='g']/child::*[position()=2 " + "and name()='g']/child::*[position()=" + i + " and name()='rect']")); Thread.sleep(1000); jsExecutor.executeScript("var evObj = document.createEvent('MouseEvents');" + "evObj.initMouseEvent(\"mouseover\",true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);" + "arguments[0].dispatchEvent(evObj);", elementTwo); Thread.sleep(1000); } catch (Exception ex) { if (ex.getMessage().contains("Alert")) { action = new Actions(driver); action.moveToElement(driver.findElement(By.xpath(chartName + "//child::*[position()=" + firstChild + " and name()='g']/child::*[position()=2 and name()='g']/child::*[position()=2 and name()='g']/child::*[position()=" + i + " and name()='rect']"))).build().perform(); } } try { driver.findElements(By.xpath(chartName + "/child::*[name()='g' and position()=" + (actElementCnt + elementOffset) + "]")); } catch (Error e) { verificationErrors.append("\n" + e.toString()); } try { String chartstr12 = driver.findElement(By.xpath( chartName + "/child::*[name()='g' and position()=" + (actElementCnt + elementOffset) + "]//*[name()='text' and position()=" + 1 + "]")) .getText(); htmlElementNames.add(chartstr12); } catch (Error e) { verificationErrors.append("\n" + e.toString()); } try { String chartstr22 = driver.findElement(By.xpath( chartName + "/child::*[name()='g' and position()=" + (actElementCnt + elementOffset) + "]//*[name()='text' and position()=" + 2 + "]")) .getText(); htmlElementValues.add(chartstr22); } catch (Error e) { verificationErrors.append("\n" + e.toString()); } arraycounter = arraycounter + 1; } catch (Error e) { verificationErrors.append("\n" + e.toString()); } catch (Exception e1) { verificationErrors.append("\n" + e1.toString()); } } for (int i = 0; i < chartelementnames.size(); i++) { boolean isElementNameMatched = false; if (htmlElementValues.contains(chartelementvalues.get(i))) { // Get the indexes of duplicate entries ArrayList<Integer> indexes = new ArrayList<Integer>(); for (int j = 0; j < htmlElementValues.size(); j++) { if (htmlElementValues.get(j).equals(chartelementvalues.get(i))) { indexes.add(j); for (int k = 0; k < indexes.size(); k++) { if (htmlElementNames.get(indexes.get(k)).equals(chartelementnames.get(i))) { isElementNameMatched = true; break; } else { continue; } } } } } else { verificationErrors.append("\n Element :" + i + " Element value = " + chartelementvalues.get(i) + " is not present. Actual Value :- " + htmlElementValues.get(i) + "\n"); } if (htmlElementNames.contains(chartelementnames.get(i))) { isElementNameMatched = true; continue; } if (!isElementNameMatched) { verificationErrors .append("\n Element :" + i + " Expected element name = " + chartelementnames.get(i) + " is different from the " + "actual names :- " + htmlElementNames); } } return verificationErrors; }
From source file:com.vmware.gemfire.tools.pulse.tests.PulseAbstractTest.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 = driver.findElement(By.xpath("//label[@for='radio-servergroups']")); ServerGroupRadio.click();//from www .j a va 2 s . co m } if (gridIcon.equals(REDUNDANCY_GRID_ID)) { WebElement ServerGroupRadio = driver.findElement(By.xpath("//label[@for='radio-redundancyzones']")); ServerGroupRadio.click(); } searchByIdAndClick(gridIcon); WebElement TreeMapMember = driver.findElement(By.xpath("//div[@id='" + S1 + "M" + (i) + "']/div")); Actions builder = new Actions(driver); builder.clickAndHold(TreeMapMember).perform(); int j = 1; String CPUUsageM1temp = driver .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 = driver .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 = driver .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(df2.format(Double.valueOf(loadAvgM1)), LoadAvgM1); String ThreadsM1 = driver .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 = driver .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:com.vmware.gemfire.tools.pulse.tests.PulseAbstractTest.java
License:Apache License
@Test public void testDataViewTreeMapPopUpData() { searchByLinkAndClick(CLUSTER_VIEW_LABEL); searchByLinkAndClick(DATA_DROPDOWN_ID); WebElement TreeMapMember = driver.findElement(By.id("GraphTreeMapClusterData-canvas")); Actions builder = new Actions(driver); builder.clickAndHold(TreeMapMember).perform(); String RegionType = driver.findElement(By.xpath("//div[@id='_tooltip']/div/div/div[2]/div/div[2]/div")) .getText();/*from ww w . j ava 2 s. c om*/ String regionType = JMXProperties.getInstance().getProperty("region.R2.regionType"); assertEquals(regionType, RegionType); String EntryCount = driver.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 = driver .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); builder.moveToElement(TreeMapMember).release().perform(); }
From source file:com.vmware.gemfire.tools.pulse.tests.PulseBaseTest.java
License:Apache License
public void mouseReleaseById(String id) { verifyElementPresentById(id);//from ww w . j a va 2 s.c om Actions action = new Actions(driver); WebElement we = driver.findElement(By.id(id)); action.moveToElement(we).release().perform(); }
From source file:com.vmware.gemfire.tools.pulse.tests.PulseTest.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 = driver.findElement(By.xpath("//label[@for='radio-servergroups']")); ServerGroupRadio.click();/*from ww w. jav a 2 s . c o m*/ } if (gridIcon.equals(REDUNDANCY_GRID_ID)) { WebElement ServerGroupRadio = driver.findElement(By.xpath("//label[@for='radio-redundancyzones']")); ServerGroupRadio.click(); } searchByIdAndClick(gridIcon); WebElement TreeMapMember = driver.findElement(By.xpath("//div[@id='" + S1 + "M" + (i) + "']/div")); Actions builder = new Actions(driver); builder.clickAndHold(TreeMapMember).perform(); int j = 1; String CPUUsageM1temp = driver .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"); Assert.assertEquals(cpuUsageM1, CPUUsageM1); String MemoryUsageM1temp = driver .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"); Assert.assertEquals(memoryUsageM1, MemoryUsageM1); String LoadAvgM1 = driver .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"); Assert.assertEquals(df2.format(Double.valueOf(loadAvgM1)), LoadAvgM1); String ThreadsM1 = driver .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"); Assert.assertEquals(threadsM1, ThreadsM1); String SocketsM1 = driver .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"); Assert.assertEquals(socketsM1, SocketsM1); builder.moveToElement(TreeMapMember).release().perform(); } }
From source file:com.vmware.gemfire.tools.pulse.tests.PulseTest.java
License:Apache License
@Test public void testDataViewTreeMapPopUpData() { searchByLinkAndClick(CLUSTER_VIEW_LABEL); searchByLinkAndClick(DATA_DROPDOWN_ID); WebElement TreeMapMember = driver.findElement(By.id("GraphTreeMapClusterData-canvas")); Actions builder = new Actions(driver); builder.clickAndHold(TreeMapMember).perform(); String RegionType = driver.findElement(By.xpath("//div[@id='_tooltip']/div/div/div[2]/div/div[2]/div")) .getText();/* ww w . ja v a 2s .c o m*/ String regionType = JMXProperties.getInstance().getProperty("region.R2.regionType"); Assert.assertEquals(regionType, RegionType); String EntryCount = driver.findElement(By.xpath("//div[@id='_tooltip']/div/div/div[2]/div[2]/div[2]/div")) .getText(); String entryCount = JMXProperties.getInstance().getProperty("region.R2.systemRegionEntryCount"); Assert.assertEquals(entryCount, EntryCount); String EntrySizetemp = driver .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)); Assert.assertEquals(entrySize, EntrySize); builder.moveToElement(TreeMapMember).release().perform(); }