List of usage examples for org.openqa.selenium.interactions Actions moveToElement
public Actions moveToElement(WebElement target)
From source file:com.liferay.cucumber.selenium.BaseWebDriverImpl.java
License:Open Source License
@Override public void mouseOver(String locator) { WebElement webElement = getWebElement(locator); scrollWebElementIntoView(webElement); WrapsDriver wrapsDriver = (WrapsDriver) webElement; WebDriver webDriver = wrapsDriver.getWrappedDriver(); Actions actions = new Actions(webDriver); actions.moveToElement(webElement); Action action = actions.build(); action.perform();/* w ww .j av a 2 s .c o m*/ }
From source file:com.livejournal.uisteps.core.Browser.java
License:Apache License
public void moveMouseOver(WrapsElement element) { try {//from w ww .ja v a 2 s . co m Actions actions = new Actions(getDriver()); actions.moveToElement(element.getWrappedElement()).build().perform(); } catch (Exception ex) { Assert.fail("Cannot move mouse over " + element + "\n" + ex); } }
From source file:com.machinepublishers.jbrowserdriver.diagnostics.Test.java
License:Apache License
private void doTests() { JBrowserDriver driver = null;/* ww w .j av a 2s . c o m*/ Thread shutdownHook = null; try { HttpServer.launch(TEST_PORT_HTTP); final File cacheDir = Files.createTempDirectory("jbd_test_cache").toFile(); final File userDataDir = Files.createTempDirectory("jbd_test_userdata").toFile(); shutdownHook = new Thread(new Runnable() { @Override public void run() { FileUtils.deleteQuietly(cacheDir); FileUtils.deleteQuietly(userDataDir); } }); Runtime.getRuntime().addShutdownHook(shutdownHook); final String mainPage = "http://" + InetAddress.getLoopbackAddress().getHostAddress() + ":" + TEST_PORT_HTTP; final int ajaxWait = 150; final Settings.Builder builder = Settings.builder().processes(TEST_PORTS_RMI) .screen(new Dimension(1024, 768)).logger(null).logJavascript(true).ajaxWait(ajaxWait) .cacheDir(cacheDir).cache(true).ignoreDialogs(false); driver = new JBrowserDriver(builder.build()); /* * Load a page */ driver.get(mainPage); test(driver.getStatusCode() == 200); long initialRequestId = HttpServer.previousRequestId(); /* * Load page from cache */ driver.get(mainPage); test(driver.getStatusCode() == 200); test(HttpServer.previousRequestId() == initialRequestId); boolean viaHeader = false; for (String line : HttpServer.previousRequest()) { if (line.toLowerCase().startsWith("via:")) { viaHeader = true; break; } } test(!viaHeader); /* * Driver reset */ driver.reset(); driver.get(mainPage); test(driver.getStatusCode() == 200); test(HttpServer.previousRequestId() == initialRequestId); driver.reset(builder.cacheDir(null).build()); driver.get(mainPage); test(driver.getStatusCode() == 200); test(HttpServer.previousRequestId() != initialRequestId); /* * Javascript logs */ int messages = 0; for (LogEntry entry : driver.manage().logs().get("javascript").filter(Level.ALL)) { ++messages; test(!StringUtils.isEmpty(entry.getMessage())); } test(messages == 3); /* * User-data directory */ driver.findElement(By.id("populate-local-storage")).click(); driver.findElement(By.id("load-from-local-storage")).click(); test("test-value".equals(driver.findElement(By.id("local-storage-value-holder")).getText())); driver.get(mainPage); driver.findElement(By.id("load-from-local-storage")).click(); test("test-value".equals(driver.findElement(By.id("local-storage-value-holder")).getText())); driver.reset(); driver.get(mainPage); driver.findElement(By.id("load-from-local-storage")).click(); test("".equals(driver.findElement(By.id("local-storage-value-holder")).getText())); driver.reset(builder.userDataDirectory(userDataDir).build()); driver.get(mainPage); driver.findElement(By.id("populate-local-storage")).click(); driver.findElement(By.id("load-from-local-storage")).click(); test("test-value".equals(driver.findElement(By.id("local-storage-value-holder")).getText())); driver.reset(); driver.get(mainPage); driver.findElement(By.id("load-from-local-storage")).click(); test("test-value".equals(driver.findElement(By.id("local-storage-value-holder")).getText())); /* * Select DOM elements */ test("test-data-attr".equals(driver.findElement(By.id("divtext1")).getAttribute("data-selected"))); test(driver.findElement(By.id("divtext1")).getAttribute("undefinedattr") == null); test(driver.findElement(By.id("divtext1")).getAttribute("innerText").equals("test1")); test(driver.findElements(By.name("divs")).size() == 2); test(driver.findElements(By.name("divs")).get(1).getAttribute("innerText").equals("test2")); test(driver.findElementByClassName("divclass").getAttribute("id").equals("divtext1")); test(driver.findElementsByClassName("divclass").get(1).getAttribute("id").equals("divtext2")); test(driver.findElementByCssSelector("#divtext1").getAttribute("id").equals("divtext1")); test(driver.findElementsByCssSelector("html > *").get(1).getAttribute("id").equals("testbody")); test(driver.findElementById("divtext1").getTagName().equals("div")); test(driver.findElementsById("divtext1").get(0).getTagName().equals("div")); test(driver.findElementByLinkText("anchor").getAttribute("id").equals("anchor1")); test(driver.findElementsByLinkText("anchor").get(1).getAttribute("id").equals("anchor2")); test(driver.findElementByName("divs").getAttribute("id").equals("divtext1")); test(driver.findElementsByName("divs").get(1).getAttribute("id").equals("divtext2")); test(driver.findElementByPartialLinkText("anch").getAttribute("id").equals("anchor1")); test(driver.findElementsByPartialLinkText("anch").get(1).getAttribute("id").equals("anchor2")); test(driver.findElementByTagName("div").getAttribute("id").equals("divtext1")); test(driver.findElementsByTagName("div").get(1).getAttribute("id").equals("divtext2")); test(driver.findElementByXPath("//*[@id='divtext1']").getAttribute("id").equals("divtext1")); test(driver.findElementByTagName("body").findElement(By.xpath("//*[@id='divtext1']")).getAttribute("id") .equals("divtext1")); test(driver.findElementsByXPath("//html/*").get(1).getAttribute("id").equals("testbody")); test(driver.findElement(By.xpath("//a[contains(@href,'1')]")).getAttribute("id").equals("anchor1")); test(driver.findElementsByXPath("//a[contains(@href,'!!!')]").isEmpty()); test(driver.findElementsByClassName("xx").isEmpty()); test(driver.findElementsByTagName("xx").isEmpty()); test(driver.findElementsByCssSelector("#xx").isEmpty()); Throwable error = null; try { driver.findElementByTagName("xx"); } catch (NoSuchElementException e) { error = e; } test(error != null); error = null; try { driver.findElementByCssSelector("#xx"); } catch (NoSuchElementException e) { error = e; } test(error != null); error = null; try { driver.findElementsByXPath("!!!"); } catch (WebDriverException e) { error = e; } test(error != null); error = null; try { driver.findElement(By.id("divtext1")).findElements(By.cssSelector("???")); } catch (WebDriverException e) { error = e; } test(error != null); /* * WebElement Equals/HashCode */ test(driver.findElements(By.name("divs")).get(0).equals(driver.findElements(By.name("divs")).get(0))); test(driver.findElements(By.name("divs")).get(0).hashCode() == driver.findElements(By.name("divs")) .get(0).hashCode()); /* * Typing text */ driver.findElement(By.id("text-input")).sendKeys("testing"); driver.findElement(By.id("text-input")).sendKeys(""); test(driver.findElement(By.id("text-input")).getAttribute("value").equals("testing")); driver.findElement(By.id("text-input")).sendKeys(JBrowserDriver.KEYBOARD_DELETE); test(driver.findElement(By.id("text-input")).getAttribute("value") == null); driver.findElement(By.id("text-input")).sendKeys("testing"); test(driver.findElement(By.id("text-input")).getAttribute("value").equals("testing")); driver.findElement(By.id("text-input")).clear(); test(driver.findElement(By.id("text-input")).getAttribute("value") == null); /* * Clicking on elements */ test(!driver.findElement(By.id("testoption2")).isSelected()); driver.findElement(By.id("testoption2")).click(); test(driver.findElement(By.id("testoption2")).isSelected()); driver.findElement(By.id("testoption1")).click(); test(driver.findElement(By.id("testoption1")).isSelected()); driver.findElement(By.id("anchor5")).click(); test("anchor clicked".equals(driver.findElement(By.id("testspan")).getText())); /* * Execute javascript */ test(((WebElement) driver.executeScript("return arguments[0];", driver.findElement(By.id("divtext1")))) .getAttribute("innerText").equals("test1")); test(((WebElement) driver.executeScript("return arguments[0].parentNode;", driver.findElement(By.id("divtext1")))).getTagName().equals("body")); test(((WebElement) ((JavascriptExecutor) driver.findElement(By.id("divtext1"))) .executeAsyncScript("arguments[0](this);")).getAttribute("innerText").equals("test1")); test((driver.executeAsyncScript("arguments[1](arguments[0].innerText);", driver.findElement(By.id("divtext1")))).equals("test1")); Map<String, Object> map = (Map<String, Object>) driver.executeScript("return {" + "key1:['value1','value2','value3'], " + "key2:5," + "key3:function(){return 'testing';}, " + "key4:undefined, key5:null, key6:1/0, key7:0/0, key8:'', key9:[], key10:{}, key11:[{},{}]," + "key12:document.getElementById('divtext1'), " + "key13:document.getElementsByName('divs'), " + "key14:[document.getElementById('divtext1'),document.getElementsByName('divs'),{subkey1:'subval1'}]};"); test(map.size() == 14); test(((List) map.get("key1")).size() == 3); test(((List) map.get("key1")).get(2).equals("value3")); test(((List) map.get("key1")).get(2) instanceof String); test(map.get("key2").equals(new Long(5))); test("function () {return 'testing';}".equals(map.get("key3")) || "function (){return 'testing';}".equals(map.get("key3"))); test(map.get("key4") == null); test(map.get("key5") == null); test(Double.isInfinite(((Double) map.get("key6")).doubleValue())); test(Double.isNaN(((Double) map.get("key7")).doubleValue())); test("".equals(map.get("key8"))); test(map.get("key9") instanceof List); test(map.get("key10") instanceof Map); test(((List) map.get("key11")).size() == 2); test(((Map) ((List) map.get("key11")).get(1)).isEmpty()); test("test1".equals(((WebElement) map.get("key12")).getAttribute("innerText"))); test(((List<WebElement>) map.get("key13")).size() == 2); test(((List<WebElement>) map.get("key13")).get(1).getAttribute("innerText").equals("test2")); test(((List) map.get("key14")).size() == 3); test(((List) ((List) map.get("key14")).get(1)).size() == 2); test(((WebElement) ((List) ((List) map.get("key14")).get(1)).get(1)).getAttribute("innerText") .equals("test2")); test(((Map) ((List) map.get("key14")).get(2)).size() == 1); test("subval1".equals(((Map) ((List) map.get("key14")).get(2)).get("subkey1"))); test(((List) driver.executeScript("return [];")).isEmpty()); test(((Map) driver.executeScript("return {};")).isEmpty()); error = null; try { driver.executeScript("invalid.execute()"); } catch (WebDriverException e) { error = e; } test(error != null); /* * DOM element properties */ WebElement element = driver.findElement(By.id("divtext1")); Point point = element.getLocation(); test(point.getX() > 0); test(point.getY() > 0); Dimension dimension = element.getSize(); test(dimension.width > 0); test(dimension.height > 0); Rectangle rect = element.getRect(); test(rect.x == point.getX()); test(rect.y == point.getY()); test(rect.width == dimension.getWidth()); test(rect.height == dimension.getHeight()); test("Testing\ntext.".equals(driver.findElement(By.id("text-node1")).getText())); test("".equals(driver.findElement(By.id("text-node2")).getText())); test("".equals(driver.findElement(By.id("text-node3")).getText())); List<WebElement> options = driver.findElementsByCssSelector("#testselect option"); test(options.size() == 2); test(options.get(0).isSelected()); test(!options.get(1).isSelected()); test(driver.findElementById("checkbox1").isSelected()); test(!driver.findElementById("checkbox2").isSelected()); /* * Cookie manager */ driver.manage().addCookie(new Cookie("testname", "testvalue")); Cookie cookie = driver.manage().getCookieNamed("testname"); test(cookie.getValue().equals("testvalue")); test(InetAddress.getLoopbackAddress().getHostAddress().equals(cookie.getDomain())); /* * Screenshots */ test(driver.getScreenshotAs(OutputType.BYTES).length > 0); /* * File Input Type */ driver.findElement(By.id("upload")).sendKeys("some-file"); test("event-test".equals(driver.findElement(By.id("file-input-onchange")).getText())); test(driver.findElement(By.id("upload")).getAttribute("value").endsWith("some-file")); /* * Javascript alerts */ driver.findElement(By.tagName("button")).click(); test(driver.switchTo().alert().getText().equals("test-alert")); driver.switchTo().alert().dismiss(); test(driver.switchTo().alert().getText().equals("test-confirm")); driver.switchTo().alert().dismiss(); test(driver.switchTo().alert().getText().equals("test-prompt")); driver.switchTo().alert().sendKeys("test-input"); driver.switchTo().alert().accept(); test(driver.findElement(By.id("testspan")).getAttribute("innerHTML").equals("test-input")); /* * Request headers */ List<String> request = HttpServer.previousRequest(); if (TEST_PORT_HTTP != 443 && TEST_PORT_HTTP != 80) { test(request.get(1).endsWith(":" + TEST_PORT_HTTP)); } test(request.size() > 1); Set<String> headers = new HashSet<String>(); for (String line : request) { if (line.contains(":")) { headers.add(line.split(":")[0].toLowerCase()); } } test(request.size() - 2 == headers.size()); /* * HTTP Post */ driver.findElement(By.id("form-submit")).click(); test(driver.getStatusCode() == 201); test("form-field=test-form-value" .equals(HttpServer.previousRequest().get(HttpServer.previousRequest().size() - 1))); /* * Frames */ driver.switchTo().frame(driver.findElementByTagName("iframe")); test(driver.findElementById("iframebody") != null); driver.switchTo().parentFrame(); test(driver.findElementById("testbody") != null); driver.switchTo().frame(0); test(driver.findElementById("iframebody") != null); driver.switchTo().defaultContent(); driver.switchTo().frame("testiframe"); test(driver.findElementById("iframebody") != null); driver.get(mainPage); test(driver.getPageSource() != null); driver.switchTo().frame(driver.findElementByTagName("iframe")); test(driver.findElementById("iframebody") != null); driver.switchTo().parentFrame(); driver.findElement(By.id("anchor3")).click(); test(driver.getPageSource() != null); driver.switchTo().frame(driver.findElementByTagName("iframe")); driver.findElement(By.id("iframe-anchor")).click(); //TODO iframe coord offset needed on any other methods? driver.pageWait(); test(HttpServer.previousRequest().get(0).startsWith("GET /iframe.htm?param=fromiframe")); driver.get(mainPage); driver.switchTo().frame(driver.findElementByTagName("iframe")); Actions actions = new Actions(driver); actions.moveToElement(driver.findElement(By.id("iframe-anchor"))); actions.click(); actions.build().perform(); driver.pageWait(); test(HttpServer.previousRequest().get(0).startsWith("GET /iframe.htm?param=fromiframe")); driver.get(mainPage); driver.switchTo().frame(driver.findElementByTagName("iframe")); driver.getMouse().click(((Locatable) driver.findElement(By.id("iframe-anchor"))).getCoordinates()); driver.getMouse().mouseMove(((Locatable) driver.findElement(By.id("iframe-anchor"))).getCoordinates(), 5, 5); driver.pageWait(); test(HttpServer.previousRequest().get(0).startsWith("GET /iframe.htm?param=fromiframe")); //TODO fingerprinting //System.out.println(driver.findElement(By.id("iframe-useragent")).getAttribute("innerHTML")); //System.out.println(driver.findElement(By.id("iframe-nested-useragent")).getAttribute("innerHTML")); /* * Redirects and cookies */ driver.get(mainPage + "/redirect/site1#testfragment"); test(HttpServer.previousRequestId() != initialRequestId); test(driver.getStatusCode() == 200); test(driver.getCurrentUrl().endsWith("/redirect/site2#testfragment")); cookie = driver.manage().getCookieNamed("JSESSIONID"); test(cookie.getValue().equals("ABC123")); test(InetAddress.getLoopbackAddress().getHostAddress().equals(cookie.getDomain())); /* * Cookies set by Javascript */ test("jsCookieValue1".equals(driver.manage().getCookieNamed("jsCookieName1").getValue())); test("jsCookieValue2".equals(driver.manage().getCookieNamed("jsCookieName2").getValue())); test("jsCookieValue3".equals(driver.manage().getCookieNamed("jsCookieName3").getValue())); test("jsCookieValue4".equals(driver.manage().getCookieNamed("jsCookieName4").getValue())); /* * Window size and position */ driver.manage().window().setSize(new Dimension(5000, 5000)); test(driver.manage().window().getSize().getWidth() == 1024); test(driver.manage().window().getSize().getHeight() == 768); driver.manage().window().setSize(new Dimension(800, 600)); test(driver.manage().window().getSize().getWidth() == 800); test(driver.manage().window().getSize().getHeight() == 600); driver.manage().window().setPosition(new Point(5000, 5000)); test(driver.manage().window().getPosition().getX() == 224); test(driver.manage().window().getPosition().getY() == 168); driver.manage().window().setPosition(new Point(20, 50)); test(driver.manage().window().getPosition().getX() == 20); test(driver.manage().window().getPosition().getY() == 50); driver.manage().window().maximize(); test(driver.manage().window().getPosition().getX() == 0); test(driver.manage().window().getPosition().getY() == 0); test(driver.manage().window().getSize().getWidth() == 1024); test(driver.manage().window().getSize().getHeight() == 768); driver.manage().window().setSize(new Dimension(800, 600)); driver.manage().window().setPosition(new Point(20, 50)); driver.manage().window().fullscreen(); test(driver.manage().window().getPosition().getX() == 0); test(driver.manage().window().getPosition().getY() == 0); test(driver.manage().window().getSize().getWidth() == 1024); test(driver.manage().window().getSize().getHeight() == 768); driver.manage().window().fullscreen(); test(driver.manage().window().getPosition().getX() == 20); test(driver.manage().window().getPosition().getY() == 50); test(driver.manage().window().getSize().getWidth() == 800); test(driver.manage().window().getSize().getHeight() == 600); driver.manage().window().setSize(new Dimension(400, 200)); driver.manage().window().setPosition(new Point(10, 30)); test(driver.manage().window().getPosition().getX() == 10); test(driver.manage().window().getPosition().getY() == 30); test(driver.manage().window().getSize().getWidth() == 400); test(driver.manage().window().getSize().getHeight() == 200); driver.manage().window().setSize(new Dimension(1024, 768)); test(driver.manage().window().getPosition().getX() == 0); test(driver.manage().window().getPosition().getY() == 0); test(driver.manage().window().getSize().getWidth() == 1024); test(driver.manage().window().getSize().getHeight() == 768); /* * Element visibility */ test(driver.findElement(By.id("iframe-anchor")).isDisplayed()); test(!driver.findElement(By.id("anchor-visibility-hidden")).isDisplayed()); test(!driver.findElement(By.id("anchor-display-none")).isDisplayed()); error = null; try { driver.findElement(By.id("anchor-visibility-hidden")).click(); } catch (ElementNotVisibleException e) { error = e; } test(error != null); error = null; try { driver.findElement(By.id("anchor-display-none")).click(); } catch (ElementNotVisibleException e) { error = e; } test(error != null); /* * Operations on elements that no longer exist */ WebElement body = driver.findElement(By.tagName("body")); test(!StringUtils.isEmpty(body.getAttribute("outerHTML"))); driver.get("about:blank"); error = null; try { body.getAttribute("outerHTML"); } catch (StaleElementReferenceException e) { error = e; } test(error != null); /* * Timeouts */ driver.manage().timeouts().pageLoadTimeout(1, TimeUnit.MILLISECONDS); error = null; try { driver.get(mainPage + "/wait-forever"); } catch (TimeoutException e) { error = e; } test(error != null); } catch (Throwable t) { outputError(testLabel("failed", curTest + 1, t)); } finally { try { driver.quit(); } catch (Throwable t) { outputError(toString(t)); } try { HttpServer.stop(); } catch (Throwable t) { outputError(toString(t)); } try { Runtime.getRuntime().removeShutdownHook(shutdownHook); shutdownHook.run(); } catch (Throwable t) { } } }
From source file:com.mroza.seleniumTests.MrozaViewPage.java
License:Open Source License
protected void clickDialogButton(String buttonName) { WebElement dialog = getVisibleDialogBox(); WebElement buttonPanel = dialog.findElement(By.className("ui-dialog-buttonpane")); List<WebElement> buttons = buttonPanel.findElements(By.tagName("button")); for (WebElement button : buttons) { List<WebElement> spanElements = button.findElements(By.tagName("span")); if (spanElements.get(1).getText().equals(buttonName)) { Actions actions = new Actions(driver); actions.moveToElement(button).click().perform(); SeleniumWaiter.waitForJQueryAndPrimeFaces(driver); break; }/*from w w w . j a va 2 s . c o m*/ } }
From source file:com.mycompany.fullslidertest.FullsliderTest.java
public void addSlideAndReorder() { createPresentation("Add slide and reorder it"); js.executeScript("$('#addslidebtn').click()"); js.executeScript("$('#addtextbtn').click()"); WebElement draggableText = driver// w w w .java 2s .c om .findElement(By.xpath("//div[@id='workspace']/div[2]/div/section[2]/div[3]")); waitForAction(); actions.dragAndDropBy(draggableText, 10, 200).build().perform(); draggableText.click(); WebElement draggableSlide1 = driver .findElement(By.xpath("//div[@id='vertical-toolbar']/div/div/div/div[1]")); WebElement draggableSlide2 = driver .findElement(By.xpath("//div[@id='vertical-toolbar']/div/div/div/div[2]")); int offset = draggableSlide2.getLocation().getY() - draggableSlide1.getLocation().getY(); Actions builder = new Actions(driver); Actions dragAndDrop = builder.moveToElement(draggableSlide1).clickAndHold().moveByOffset(0, offset + 10) .pause(500); // I found the pauses were necessary to get the test working in other dragAndDrop.release().perform(); waitForAction(); driver.quit(); }
From source file:com.nat.test.utils.PageNavigator.java
/** * Method to perform click using {@link Actions} class. Call if simple click * doesn't work for {@link ChromeDriver} * * @param driver//from w ww . j av a2s.c om * The driver that will be used for navigation * @param element * Element to click */ public static void click(WebDriver driver, WebElement element) { try { element.click(); } catch (org.openqa.selenium.WebDriverException e) { Actions action = new Actions(driver); action.moveToElement(element).perform(); action.click().perform(); } }
From source file:com.oracle.amc.sqe.util.webui.WebUIPage.java
License:Open Source License
public void moveTo(By elementPath) { Actions action = new Actions(webDriver); WebElement element = findElement(elementPath); action.moveToElement(element).build().perform(); }
From source file:com.pentaho.ctools.cde.reference.BulletChartTestCase.java
License:Apache License
/** * ############################### Test Case 1 ############################### * * Test Case Name://from w w w .ja v a 2 s.c o m * PageContent * Description: * The test case pretends validate charts presented. * Steps: * 1. Check chart 1 - No data sent * 2. Check chart 2 - Returning one value only (65) * 3. Check chart 3 - Returning name and value * 4. Check chart 4 - Title, value and marker * 5. Check chart 5 - Complete dataset */ @Test public void tc01_ChartContent_DisplayedCorrect() { this.log.info("tc01_ChartContent_DisplayedCorrect"); /* * ## Step 0 */ //Check page title wait.until(ExpectedConditions.titleIs("Bullet chart testcase")); assertEquals("Bullet chart testcase", driver.getTitle()); //Check title String title = this.elemHelper.WaitForElementPresentGetText(driver, By.cssSelector("#title > span")); assertEquals("Bullet chart test case", title); /* * ## Step 1 */ //Chart 1 //Check title String subtitle1 = this.elemHelper.WaitForElementPresentGetText(driver, By.cssSelector("#subtitle1 > span")); assertEquals("No data sent", subtitle1); //Check serie title and subtitle String cht1Title1 = this.elemHelper.WaitForElementPresentGetText(driver, By.xpath( "//div[@id='obj1']/div/*[local-name()='svg' and namespace-uri()='http://www.w3.org/2000/svg']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g'][6]/*[local-name()='text']")); assertEquals("Title", cht1Title1); String cht1Subtitle1 = this.elemHelper.WaitForElementPresentGetText(driver, By.xpath( "//div[@id='obj1']/div/*[local-name()='svg' and namespace-uri()='http://www.w3.org/2000/svg']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g'][7]/*[local-name()='text']")); assertEquals("No data", cht1Subtitle1); //Check chart WebElement cht1SizeBar = this.elemHelper.FindElement(driver, By.xpath( "//div[@id='obj1']/div/*[local-name()='svg' and namespace-uri()='http://www.w3.org/2000/svg']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g'][2]/*[local-name()='rect']")); assertNotNull(cht1SizeBar); assertEquals("202.11111111111111", cht1SizeBar.getAttribute("width")); WebElement cht1RectWhite1 = this.elemHelper.FindElement(driver, By.xpath( "//div[@id='obj1']/div/*[local-name()='svg' and namespace-uri()='http://www.w3.org/2000/svg']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g'][3]/*[local-name()='path'][1]")); WebElement cht1RectWhite2 = this.elemHelper.FindElement(driver, By.xpath( "//div[@id='obj1']/div/*[local-name()='svg' and namespace-uri()='http://www.w3.org/2000/svg']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g'][3]/*[local-name()='path'][2]")); assertNotNull(cht1RectWhite1); assertNotNull(cht1RectWhite2); assertEquals("translate(78.46666666666665,15) ", cht1RectWhite1.getAttribute("transform")); assertEquals("translate(156.9333333333333,15) ", cht1RectWhite2.getAttribute("transform")); /* * ## Step 2 */ //Chart 2 //Check title String subtitle2 = this.elemHelper.WaitForElementPresentGetText(driver, By.id("subtitle2")); assertEquals("Returning one value only (65)", subtitle2); //Check serie title and subtitle String cht2Title1 = this.elemHelper.WaitForElementPresentGetText(driver, By.xpath( "//div[@id='obj2']/div/*[local-name()='svg' and namespace-uri()='http://www.w3.org/2000/svg']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g'][6]/*[local-name()='text']")); assertEquals("Value only", cht2Title1); String cht2Subtitle1 = this.elemHelper.WaitForElementPresentGetText(driver, By.xpath( "//div[@id='obj2']/div/*[local-name()='svg' and namespace-uri()='http://www.w3.org/2000/svg']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g'][7]/*[local-name()='text']")); assertEquals("value is 65", cht2Subtitle1); //Check chart WebElement cht2SizeBar = this.elemHelper.FindElement(driver, By.xpath( "//div[@id='obj2']/div/*[local-name()='svg' and namespace-uri()='http://www.w3.org/2000/svg']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g'][2]/*[local-name()='rect']")); assertNotNull(cht2SizeBar); assertEquals("154.55555555555554", cht2SizeBar.getAttribute("width")); WebElement cht2RectWhite1 = this.elemHelper.FindElement(driver, By.xpath( "//div[@id='obj2']/div/*[local-name()='svg' and namespace-uri()='http://www.w3.org/2000/svg']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g'][3]/*[local-name()='path'][1]")); assertNotNull(cht2RectWhite1); assertEquals("translate(71.33333333333333,12.5) ", cht2RectWhite1.getAttribute("transform")); /* * ## Step 3 */ //>Chart 3 //>>Chart 31 //Check title String subtitle3 = this.elemHelper.WaitForElementPresentGetText(driver, By.id("subtitle3")); assertEquals("Returning name and value", subtitle3); //Check series title and subtitle String cht31Title1 = this.elemHelper.WaitForElementPresentGetText(driver, By.xpath( "//div[@id='obj3']/div/*[local-name()='svg' and namespace-uri()='http://www.w3.org/2000/svg']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g'][6]/*[local-name()='text']")); assertEquals("Atelier graphique", cht31Title1); String cht31Subtitle1 = this.elemHelper.WaitForElementPresentGetText(driver, By.xpath( "//div[@id='obj3']/div/*[local-name()='svg' and namespace-uri()='http://www.w3.org/2000/svg']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g'][7]/*[local-name()='text']")); assertEquals("Customer", cht31Subtitle1); //Check chart WebElement cht31SizeBar = this.elemHelper.FindElement(driver, By.xpath( "//div[@id='obj3']/div/*[local-name()='svg' and namespace-uri()='http://www.w3.org/2000/svg']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g'][2]/*[local-name()='rect']")); assertNotNull(cht31SizeBar); assertEquals("178.26666666666668", cht31SizeBar.getAttribute("width")); WebElement cht31RectWhite1 = this.elemHelper.FindElement(driver, By.xpath( "//div[@id='obj3']/div/*[local-name()='svg' and namespace-uri()='http://www.w3.org/2000/svg']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g'][3]/*[local-name()='path'][1]")); assertNotNull(cht31RectWhite1); assertEquals("translate(509.3333333333333,10) ", cht31RectWhite1.getAttribute("transform")); //>>Chart 32 //Check series title and subtitle String cht32Title1 = this.elemHelper.WaitForElementPresentGetText(driver, By.xpath( "//div[@id='obj3']/div/*[local-name()='svg' and namespace-uri()='http://www.w3.org/2000/svg']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g'][2]/*[local-name()='g'][6]/*[local-name()='text']")); assertEquals("Signal Gift Stores", cht32Title1); String cht32Subtitle1 = this.elemHelper.WaitForElementPresentGetText(driver, By.xpath( "//div[@id='obj3']/div/*[local-name()='svg' and namespace-uri()='http://www.w3.org/2000/svg']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g'][2]/*[local-name()='g'][7]/*[local-name()='text']")); assertEquals("Customer", cht32Subtitle1); //Check chart WebElement cht32SizeBar = this.elemHelper.FindElement(driver, By.xpath( "//div[@id='obj3']/div/*[local-name()='svg' and namespace-uri()='http://www.w3.org/2000/svg']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g'][2]/*[local-name()='g'][2]/*[local-name()='rect']")); assertNotNull(cht32SizeBar); assertEquals("609.5022222222223", cht32SizeBar.getAttribute("width")); WebElement cht32RectWhite1 = this.elemHelper.FindElement(driver, By.xpath( "//div[@id='obj3']/div/*[local-name()='svg' and namespace-uri()='http://www.w3.org/2000/svg']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g'][2]/*[local-name()='g'][3]/*[local-name()='path'][1]")); assertNotNull(cht32RectWhite1); assertEquals("translate(509.3333333333333,10) ", cht32RectWhite1.getAttribute("transform")); //>>Chart 33 //Check series title and subtitle String cht33Title1 = this.elemHelper.WaitForElementPresentGetText(driver, By.xpath( "//div[@id='obj3']/div/*[local-name()='svg' and namespace-uri()='http://www.w3.org/2000/svg']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g'][3]/*[local-name()='g'][6]/*[local-name()='text']")); assertEquals("Australian Collectors, Co.", cht33Title1); String cht33Subtitle1 = this.elemHelper.WaitForElementPresentGetText(driver, By.xpath( "//div[@id='obj3']/div/*[local-name()='svg' and namespace-uri()='http://www.w3.org/2000/svg']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g'][3]/*[local-name()='g'][7]/*[local-name()='text']")); assertEquals("Customer", cht33Subtitle1); //Check chart WebElement cht33SizeBar = this.elemHelper.FindElement(driver, By.xpath( "//div[@id='obj3']/div/*[local-name()='svg' and namespace-uri()='http://www.w3.org/2000/svg']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g'][3]/*[local-name()='g'][2]/*[local-name()='rect']")); assertNotNull(cht33SizeBar); assertEquals("764", cht33SizeBar.getAttribute("width")); WebElement cht33RectWhite1 = this.elemHelper.FindElement(driver, By.xpath( "//div[@id='obj3']/div/*[local-name()='svg' and namespace-uri()='http://www.w3.org/2000/svg']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g'][3]/*[local-name()='g'][3]/*[local-name()='path'][1]")); assertNotNull(cht33RectWhite1); assertEquals("translate(390.79283887468034,10) ", cht33RectWhite1.getAttribute("transform")); //>>Chart 34 String cht34Title1 = this.elemHelper.WaitForElementPresentGetText(driver, By.xpath( "//div[@id='obj3']/div/*[local-name()='svg' and namespace-uri()='http://www.w3.org/2000/svg']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g'][4]/*[local-name()='g'][6]/*[local-name()='text']")); assertEquals("La Rochelle Gifts", cht34Title1); String cht34Subtitle1 = this.elemHelper.WaitForElementPresentGetText(driver, By.xpath( "//div[@id='obj3']/div/*[local-name()='svg' and namespace-uri()='http://www.w3.org/2000/svg']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g'][4]/*[local-name()='g'][7]/*[local-name()='text']")); assertEquals("Customer", cht34Subtitle1); //Check chart WebElement cht34SizeBar = this.elemHelper.FindElement(driver, By.xpath( "//div[@id='obj3']/div/*[local-name()='svg' and namespace-uri()='http://www.w3.org/2000/svg']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g'][4]/*[local-name()='g'][2]/*[local-name()='rect']")); assertNotNull(cht34SizeBar); assertEquals("764", cht34SizeBar.getAttribute("width")); WebElement cht34RectWhite1 = this.elemHelper.FindElement(driver, By.xpath( "//div[@id='obj3']/div/*[local-name()='svg' and namespace-uri()='http://www.w3.org/2000/svg']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g'][4]/*[local-name()='g'][3]/*[local-name()='path'][1]")); assertNotNull(cht34RectWhite1); assertEquals("translate(387.8172588832487,10) ", cht34RectWhite1.getAttribute("transform")); //>>Chart 35 String cht35Title1 = this.elemHelper.WaitForElementPresentGetText(driver, By.xpath( "//div[@id='obj3']/div/*[local-name()='svg' and namespace-uri()='http://www.w3.org/2000/svg']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g'][5]/*[local-name()='g'][6]/*[local-name()='text']")); assertEquals("Baane Mini Imports", cht35Title1); String cht35Subtitle1 = this.elemHelper.WaitForElementPresentGetText(driver, By.xpath( "//div[@id='obj3']/div/*[local-name()='svg' and namespace-uri()='http://www.w3.org/2000/svg']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g'][5]/*[local-name()='g'][7]/*[local-name()='text']")); assertEquals("Customer", cht35Subtitle1); //Check chart WebElement cht35SizeBar = this.elemHelper.FindElement(driver, By.xpath( "//div[@id='obj3']/div/*[local-name()='svg' and namespace-uri()='http://www.w3.org/2000/svg']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g'][5]/*[local-name()='g'][2]/*[local-name()='rect']")); assertNotNull(cht35SizeBar); assertEquals("693.5422222222222", cht35SizeBar.getAttribute("width")); WebElement cht35RectWhite1 = this.elemHelper.FindElement(driver, By.xpath( "//div[@id='obj3']/div/*[local-name()='svg' and namespace-uri()='http://www.w3.org/2000/svg']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g'][5]/*[local-name()='g'][3]/*[local-name()='path'][1]")); assertNotNull(cht35RectWhite1); assertEquals("translate(509.3333333333333,10) ", cht35RectWhite1.getAttribute("transform")); //>>Chart 36 String cht36Title1 = this.elemHelper.WaitForElementPresentGetText(driver, By.xpath( "//div[@id='obj3']/div/*[local-name()='svg' and namespace-uri()='http://www.w3.org/2000/svg']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g'][6]/*[local-name()='g'][6]/*[local-name()='text']")); assertEquals("Mini Gifts Distributors Ltd.", cht36Title1); String cht36Subtitle1 = this.elemHelper.WaitForElementPresentGetText(driver, By.xpath( "//div[@id='obj3']/div/*[local-name()='svg' and namespace-uri()='http://www.w3.org/2000/svg']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g'][6]/*[local-name()='g'][7]/*[local-name()='text']")); assertEquals("Customer", cht36Subtitle1); //Check chart WebElement cht36SizeBar = this.elemHelper.FindElement(driver, By.xpath( "//div[@id='obj3']/div/*[local-name()='svg' and namespace-uri()='http://www.w3.org/2000/svg']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g'][6]/*[local-name()='g'][2]/*[local-name()='rect']")); assertNotNull(cht36SizeBar); assertEquals("764", cht36SizeBar.getAttribute("width")); WebElement cht36RectWhite1 = this.elemHelper.FindElement(driver, By.xpath( "//div[@id='obj3']/div/*[local-name()='svg' and namespace-uri()='http://www.w3.org/2000/svg']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g'][6]/*[local-name()='g'][3]/*[local-name()='path'][1]")); assertNotNull(cht36RectWhite1); assertEquals("translate(217.76722090261282,10) ", cht36RectWhite1.getAttribute("transform")); //>>Chart 37 String cht37Title1 = this.elemHelper.WaitForElementPresentGetText(driver, By.xpath( "//div[@id='obj3']/div/*[local-name()='svg' and namespace-uri()='http://www.w3.org/2000/svg']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g'][7]/*[local-name()='g'][6]/*[local-name()='text']")); assertEquals("Havel & Zbyszek Co", cht37Title1); String cht37Subtitle1 = this.elemHelper.WaitForElementPresentGetText(driver, By.xpath( "//div[@id='obj3']/div/*[local-name()='svg' and namespace-uri()='http://www.w3.org/2000/svg']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g'][7]/*[local-name()='g'][7]/*[local-name()='text']")); assertEquals("Customer", cht37Subtitle1); //Check chart WebElement cht37SizeBar = this.elemHelper.FindElement(driver, By.xpath( "//div[@id='obj3']/div/*[local-name()='svg' and namespace-uri()='http://www.w3.org/2000/svg']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g'][7]/*[local-name()='g'][2]/*[local-name()='rect']"), 1); assertNull(cht37SizeBar); WebElement cht37RectWhite1 = this.elemHelper.FindElement(driver, By.xpath( "//div[@id='obj3']/div/*[local-name()='svg' and namespace-uri()='http://www.w3.org/2000/svg']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g'][7]/*[local-name()='g'][3]/*[local-name()='path'][1]")); assertNotNull(cht37RectWhite1); assertEquals("translate(509.3333333333333,10) ", cht37RectWhite1.getAttribute("transform")); //>>Chart 38 String cht38Title1 = this.elemHelper.WaitForElementPresentGetText(driver, By.xpath( "//div[@id='obj3']/div/*[local-name()='svg' and namespace-uri()='http://www.w3.org/2000/svg']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g'][8]/*[local-name()='g'][6]/*[local-name()='text']")); assertEquals("Blauer See Auto, Co.", cht38Title1); String cht38Subtitle1 = this.elemHelper.WaitForElementPresentGetText(driver, By.xpath( "//div[@id='obj3']/div/*[local-name()='svg' and namespace-uri()='http://www.w3.org/2000/svg']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g'][8]/*[local-name()='g'][7]/*[local-name()='text']")); assertEquals("Customer", cht38Subtitle1); //Check chart WebElement cht38SizeBar = this.elemHelper.FindElement(driver, By.xpath( "//div[@id='obj3']/div/*[local-name()='svg' and namespace-uri()='http://www.w3.org/2000/svg']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g'][8]/*[local-name()='g'][2]/*[local-name()='rect']")); assertNotNull(cht38SizeBar); assertEquals("506.7866666666667", cht38SizeBar.getAttribute("width")); WebElement cht38RectWhite1 = this.elemHelper.FindElement(driver, By.xpath( "//div[@id='obj3']/div/*[local-name()='svg' and namespace-uri()='http://www.w3.org/2000/svg']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g'][8]/*[local-name()='g'][3]/*[local-name()='path'][1]")); assertNotNull(cht38RectWhite1); assertEquals("translate(509.3333333333333,10) ", cht38RectWhite1.getAttribute("transform")); /* * ## Step 4 */ Actions acts = new Actions(driver); acts.moveToElement(this.elemHelper.FindElement(driver, By.cssSelector("div.webdetailsFooterWebdetails"))); acts.perform(); //Chart 4 //Check title String subtitle4 = this.elemHelper.WaitForElementPresentGetText(driver, By.id("subtitle4")); assertEquals("Title, value and marker", subtitle4); //Check serie title and subtitle String cht4Title1 = this.elemHelper.WaitForElementPresentGetText(driver, By.xpath( "//div[@id='obj4']/div/*[local-name()='svg' and namespace-uri()='http://www.w3.org/2000/svg']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g'][6]/*[local-name()='text']")); assertEquals("Atelier graphique", cht4Title1); String cht4Subtitle1 = this.elemHelper.WaitForElementPresentGetText(driver, By.xpath( "//div[@id='obj4']/div/*[local-name()='svg' and namespace-uri()='http://www.w3.org/2000/svg']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g'][7]/*[local-name()='text']")); assertEquals("Subtitle", cht4Subtitle1); //Check chart WebElement cht4SizeBar = this.elemHelper.FindElement(driver, By.xpath( "//div[@id='obj4']/div/*[local-name()='svg' and namespace-uri()='http://www.w3.org/2000/svg']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g'][2]/*[local-name()='rect']")); assertNotNull(cht4SizeBar); WebElement cht4RectWhite1 = this.elemHelper.FindElement(driver, By.xpath( "//div[@id='obj4']/div/*[local-name()='svg' and namespace-uri()='http://www.w3.org/2000/svg']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g'][3]/*[local-name()='path'][1]")); assertNotNull(cht4RectWhite1); /* * ## Step 5 */ //Chart 5 //Check title String subtitle5 = this.elemHelper.WaitForElementPresentGetText(driver, By.id("subtitle5")); assertEquals("Complete dataset", subtitle5); //Check serie title and subtitle String cht5Title1 = this.elemHelper.WaitForElementPresentGetText(driver, By.xpath( "//div[@id='obj5']/div/*[local-name()='svg' and namespace-uri()='http://www.w3.org/2000/svg']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g'][6]/*[local-name()='text']")); assertEquals("Atelier graphique", cht5Title1); String cht5Subtitle1 = this.elemHelper.WaitForElementPresentGetText(driver, By.xpath( "//div[@id='obj5']/div/*[local-name()='svg' and namespace-uri()='http://www.w3.org/2000/svg']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g'][7]/*[local-name()='text']")); assertEquals("Carine Schmitt", cht5Subtitle1); //Check chart WebElement cht5SizeBar = this.elemHelper.FindElement(driver, By.xpath( "//div[@id='obj5']/div/*[local-name()='svg' and namespace-uri()='http://www.w3.org/2000/svg']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g'][2]/*[local-name()='rect']")); assertNotNull(cht5SizeBar); WebElement cht5RectWhite1 = this.elemHelper.FindElement(driver, By.xpath( "//div[@id='obj5']/div/*[local-name()='svg' and namespace-uri()='http://www.w3.org/2000/svg']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g'][3]/*[local-name()='path'][1]")); assertNotNull(cht5RectWhite1); }
From source file:com.pentaho.ctools.cde.reference.CCCV2ShowCase.java
License:Apache License
/** * ############################### Test Case 1 ############################### * * Test Case Name://from w w w . java 2s . c o m * BarChart * Description: * The test case pretends validate the bar chart information. * Steps: * 1. Check Bar Chart */ @Test public void tc01_ChartContent_DisplayedCorrect() { this.log.info("tc1_ChartContent_DisplayedCorrect"); /* * ## Step 1 - Bar Chart */ String barChartTitle = this.elemHelper.WaitForElementPresentGetText(driver, By.id("BarChartTitleRow")); assertEquals("Bar Chart", barChartTitle); // Check bars this.elemHelper.FindElement(driver, By.xpath( "//div[@id='BarChartBodyRow']/div/div/*[local-name()='svg' and namespace-uri()='http://www.w3.org/2000/svg']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g'][2]/*[local-name()='g']/*[local-name()='g']/*[local-name()='g'][1]/*[local-name()='rect'][2]")); WebElement barChartRect1 = this.elemHelper.FindElement(driver, By.xpath( "//div[@id='BarChartBodyRow']/div/div/*[local-name()='svg' and namespace-uri()='http://www.w3.org/2000/svg']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g'][2]/*[local-name()='g']/*[local-name()='g']/*[local-name()='g'][1]/*[local-name()='rect'][1]")); WebElement barChartRect2 = this.elemHelper.FindElement(driver, By.xpath( "//div[@id='BarChartBodyRow']/div/div/*[local-name()='svg' and namespace-uri()='http://www.w3.org/2000/svg']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g'][2]/*[local-name()='g']/*[local-name()='g']/*[local-name()='g'][1]/*[local-name()='rect'][2]")); WebElement barChartRect3 = this.elemHelper.FindElement(driver, By.xpath( "//div[@id='BarChartBodyRow']/div/div/*[local-name()='svg' and namespace-uri()='http://www.w3.org/2000/svg']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g'][2]/*[local-name()='g']/*[local-name()='g']/*[local-name()='g'][1]/*[local-name()='rect'][3]")); assertNotNull(barChartRect1); assertNotNull(barChartRect2); assertNotNull(barChartRect3); Double barChartRect1Width = Double.parseDouble(barChartRect1.getAttribute("width")); Double barChartRect2Width = Double.parseDouble(barChartRect2.getAttribute("width")); Double barChartRect3Width = Double.parseDouble(barChartRect3.getAttribute("width")); assertThat("Current width: " + barChartRect1Width, barChartRect1Width, greaterThan(Double.valueOf(192))); assertThat("Current width: " + barChartRect2Width, barChartRect2Width, greaterThan(Double.valueOf(250))); assertThat("Current width: " + barChartRect3Width, barChartRect3Width, greaterThan(Double.valueOf(100))); // Check bars value String barChartRectValue1 = this.elemHelper.WaitForElementPresentGetText(driver, By.xpath( "//div[@id='BarChartBodyRow']/div/div/*[local-name()='svg' and namespace-uri()='http://www.w3.org/2000/svg']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g'][2]/*[local-name()='g']/*[local-name()='g']/*[local-name()='g'][2]/*[local-name()='text'][1]")); String barChartRectValue2 = this.elemHelper.WaitForElementPresentGetText(driver, By.xpath( "//div[@id='BarChartBodyRow']/div/div/*[local-name()='svg' and namespace-uri()='http://www.w3.org/2000/svg']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g'][2]/*[local-name()='g']/*[local-name()='g']/*[local-name()='g'][2]/*[local-name()='text'][2]")); String barChartRectValue3 = this.elemHelper.WaitForElementPresentGetText(driver, By.xpath( "//div[@id='BarChartBodyRow']/div/div/*[local-name()='svg' and namespace-uri()='http://www.w3.org/2000/svg']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g'][2]/*[local-name()='g']/*[local-name()='g']/*[local-name()='g'][2]/*[local-name()='text'][3]")); assertEquals("3.68M", barChartRectValue1); assertEquals("4.99M", barChartRectValue2); assertEquals("1.98M", barChartRectValue3); // Mouse hover elements Actions acts = new Actions(driver); acts.moveToElement(barChartRect2); acts.perform(); String seriesLabel = this.elemHelper.WaitForElementPresentGetText(driver, By.xpath("//div[@class='tipsy tipsy-s']/div[2]/div/table/tbody/tr[1]/td[1]/span")); acts.perform(); String seriesValue = this.elemHelper.WaitForElementPresentGetText(driver, By.xpath("//div[@class='tipsy tipsy-s']/div[2]/div/table/tbody/tr[1]/td[3]/span")); acts.perform(); String timeLabel = this.elemHelper.WaitForElementPresentGetText(driver, By.xpath("//div[@class='tipsy tipsy-s']/div[2]/div/table/tbody/tr[2]/td[1]/span")); acts.perform(); String timeValue = this.elemHelper.WaitForElementPresentGetText(driver, By.xpath("//div[@class='tipsy tipsy-s']/div[2]/div/table/tbody/tr[2]/td[3]/span")); acts.perform(); String valueLabel = this.elemHelper.WaitForElementPresentGetText(driver, By.xpath("//div[@class='tipsy tipsy-s']/div[2]/div/table/tbody/tr[3]/td[1]/span")); acts.perform(); String valueValue = this.elemHelper.WaitForElementPresentGetText(driver, By.xpath("//div[@class='tipsy tipsy-s']/div[2]/div/table/tbody/tr[3]/td[3]/span")); assertEquals("Series", seriesLabel); assertEquals("Sales", seriesValue); assertEquals("Time", timeLabel); assertEquals("2004", timeValue); assertEquals("Value", valueLabel); assertEquals("4,987,739.84", valueValue); //To move the focus to another element, in order to remove the tooltip Actions acts2 = new Actions(driver); acts2.moveToElement(this.elemHelper.FindElement(driver, By.id("BarChartTitleRow"))); acts2.click(); acts2.perform(); }
From source file:com.pentaho.ctools.cde.reference.CCCV2ShowCase.java
License:Apache License
/** * ############################### Test Case 2 ############################### * * Test Case Name:/*from www . j ava 2s . c o m*/ * LineChart * Description: * The test case pretends validate the line chart information. * Steps: * 1. Check Line Chart */ @Test public void tc02_ChartContent_DisplayedCorrect() { this.log.info("tc02_ChartContent_DisplayedCorrect"); /* * ## Step 2 - Line Chart */ String lineChartTitle = this.elemHelper.WaitForElementPresentGetText(driver, By.id("LineChartTitleRow")); assertEquals("Line Chart", lineChartTitle); // Check lines WebElement lineChartCircle1 = this.elemHelper.FindElement(driver, By.xpath( "//div[@id='LineChartBodyRow']/div/div/*[local-name()='svg' and namespace-uri()='http://www.w3.org/2000/svg']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g'][3]/*[local-name()='g']/*[local-name()='g']/*[local-name()='g'][3]/*[local-name()='circle'][1]")); WebElement lineChartCircle2 = this.elemHelper.FindElement(driver, By.xpath( "//div[@id='LineChartBodyRow']/div/div/*[local-name()='svg' and namespace-uri()='http://www.w3.org/2000/svg']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g'][3]/*[local-name()='g']/*[local-name()='g']/*[local-name()='g'][3]/*[local-name()='circle'][7]")); WebElement lineChartCircle3 = this.elemHelper.FindElement(driver, By.xpath( "//div[@id='LineChartBodyRow']/div/div/*[local-name()='svg' and namespace-uri()='http://www.w3.org/2000/svg']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g'][3]/*[local-name()='g']/*[local-name()='g']/*[local-name()='g'][3]/*[local-name()='circle'][11]")); Double lineChartCircle1Cy = Double.parseDouble(lineChartCircle1.getAttribute("cy")); Double lineChartCircle2Cy = Double.parseDouble(lineChartCircle2.getAttribute("cy")); Double lineChartCircle3Cy = Double.parseDouble(lineChartCircle3.getAttribute("cy")); assertThat("Current cy: " + lineChartCircle1Cy, lineChartCircle1Cy, greaterThan(Double.valueOf(120))); assertThat("Current cy: " + lineChartCircle2Cy, lineChartCircle2Cy, greaterThan(Double.valueOf(136))); assertThat("Current cy: " + lineChartCircle3Cy, lineChartCircle3Cy, greaterThan(Double.valueOf(24))); // Mouse hover elements WebElement lineChartCircle4 = this.elemHelper.FindElement(driver, By.xpath( "//div[@id='LineChartBodyRow']/div/div/*[local-name()='svg' and namespace-uri()='http://www.w3.org/2000/svg']/*[local-name()='g']/*[local-name()='g']/*[local-name()='g'][3]/*[local-name()='g']/*[local-name()='g']/*[local-name()='g'][3]/*[local-name()='circle'][2]")); Actions acts = new Actions(driver); acts.moveToElement(lineChartCircle4); acts.perform(); String measuresLabel = this.elemHelper.WaitForElementPresentGetText(driver, By.xpath("//div[@class='tipsy tipsy-s']/div[2]/div/table/tbody/tr[1]/td[1]/span")); acts.perform(); String measuresValue = this.elemHelper.WaitForElementPresentGetText(driver, By.xpath("//div[@class='tipsy tipsy-s']/div[2]/div/table/tbody/tr[1]/td[3]/span")); acts.perform(); String categoryLabel = this.elemHelper.WaitForElementPresentGetText(driver, By.xpath("//div[@class='tipsy tipsy-s']/div[2]/div/table/tbody/tr[2]/td[1]/span")); acts.perform(); String categoryValue = this.elemHelper.WaitForElementPresentGetText(driver, By.xpath("//div[@class='tipsy tipsy-s']/div[2]/div/table/tbody/tr[2]/td[3]/span")); acts.perform(); String valueLineValue = this.elemHelper.WaitForElementPresentGetText(driver, By.xpath("//div[@class='tipsy tipsy-s']/div[2]/div/table/tbody/tr[4]/td[3]/span")); assertEquals("Measures", measuresLabel); assertEquals("Quantity", measuresValue); assertEquals("Category", categoryLabel); assertEquals("Feb", categoryValue); assertEquals("7,959", valueLineValue); //To move the focus to another element, in order to remove the tooltip Actions acts2 = new Actions(driver); acts2.moveToElement(this.elemHelper.FindElement(driver, By.id("LineChartTitleRow"))); acts2.click(); acts2.perform(); }