@Test public void testAbcd() throws Exception { driver.get(baseUrl + "/"); driver.findElement(By.linkText("Sign In")).click(); driver.findElement(By.linkText("Sign In")).getText(); driver.findElement(By.xpath("//input[@name='loginName']")).clear(); driver.findElement(By.xpath("//input[@name='loginName']")).sendKeys("*****@*****.**"); driver.findElement(By.xpath("//input[@name='password']")).clear(); driver.findElement(By.xpath("//input[@name='password']")).sendKeys("demo123"); driver.findElement(By.xpath("//input[@type='image']")).click(); driver.findElement(By.linkText("Money")).click(); driver.findElement(By.linkText("Portfolio")).click(); driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); WebElement table = driver.findElement(By.id("table-holding-data")); if (table.isDisplayed()) { List<WebElement> rows = table.findElements(By.tagName("tr")); System.out.println("Row Count - " + rows.size()); Iterator<WebElement> i = rows.iterator(); System.out.println("Table has following content"); while (i.hasNext()) { WebElement row = i.next(); List<WebElement> columns = row.findElements(By.tagName("td")); Iterator<WebElement> j = columns.iterator(); while (j.hasNext()) { WebElement column = j.next(); System.out.print(column.getText()); System.out.print(" | "); } System.out.println("--------------------"); } System.out.println("Table content is printed"); } else { System.out.println("Table not found"); } }
@Test @Ignore( "I would love for this to work consistently but it fails too often between releases to use as an example") public void multiSelectWithUserInteractions() { WebElement multiSelect; multiSelect = driver.findElement(By.cssSelector("select[multiple='multiple']")); List<WebElement> multiSelectOptions = multiSelect.findElements(By.tagName("option")); // in real life, clicking on a multi select item without holding down // CTRL will deselect all others and select only that one item Actions actions = new Actions(driver); actions .click(multiSelectOptions.get(0)) .click(multiSelectOptions.get(1)) .click(multiSelectOptions.get(2)) .perform(); clickSubmitButton(); new WebDriverWait(driver, 10).until(ExpectedConditions.titleIs("Processed Form Details")); assertEquals( "Expected only 1 match", 1, driver.findElements(By.cssSelector("[id^='_valuemultipleselect']")).size()); }
@Test public void testShouldClickOnGraphVisualElements() { driver.get(pages.svgPage); WebElement svg = driver.findElement(By.cssSelector("svg")); if (isFirefox30(driver) && isNativeEventsEnabled(driver)) { System.out.println( "Not testing SVG elements with Firefox 3.0 and native events as" + " this functionality is not working."); return; } List<WebElement> groupElements = svg.findElements(By.cssSelector("g")); assertEquals(5, groupElements.size()); groupElements.get(1).click(); WebElement resultElement = driver.findElement(By.id("result")); waitFor(elementTextToEqual(resultElement, "slice_red")); assertEquals("slice_red", resultElement.getText()); groupElements.get(2).click(); resultElement = driver.findElement(By.id("result")); waitFor(elementTextToEqual(resultElement, "slice_green")); assertEquals("slice_green", resultElement.getText()); }
// ODI6.x-628:Number formatting public void numberFormat() { String dmName = "US_AIRWAYS"; gotoreports(dmName); pickAvalidDate(); try { new WebDriverWait(driver, 10) .until(ExpectedConditions.frameToBeAvailableAndSwitchToIt("reportContent")); WebElement page = new WebDriverWait(driver, 10) .until(ExpectedConditions.visibilityOfElementLocated(By.id("CrystalViewer"))); List<WebElement> check = page.findElements(By.tagName("span")); for (int i = 0; i < check.size(); i++) { content = check.get(i).getText(); if (content.equals("Call Volume")) { contentValue = check.get(i + 1).getText(); System.out.println(contentValue); decimalcheck(contentValue, "example", 0); System.out.println(contentValue); } if (content.equals("Call Duration (minutes)")) { contentValue = check.get(i + 1).getText(); decimalcheck(contentValue, "In call duration", 2); } else if (content.equals("Average Call Duration (minutes)")) { contentValue = check.get(i + 1).getText(); decimalcheck(contentValue, "In average call duration", 2); } else if (content.equals("Average Call Duration for Transferred Calls (minutes)")) { contentValue = check.get(i + 1).getText(); decimalcheck(contentValue, "In average call duration for transfered calls", 2); } else if (content.equals("Peak Hour Average Call Duration (minutes)")) { contentValue = check.get(i + 1).getText(); decimalcheck(contentValue, "In peak hour average call duration", 2); } else if (content.equals("Average Weekly Call Volume")) { contentValue = check.get(i + 1).getText(); decimalcheck(contentValue, "Average Weekly call volume", 1); } if (content.equals("Transfer Rate (All)")) { String percentage = check.get(i + 1).getText(); String[] contentValues = percentage.split("%"); contentValue = contentValues[0]; System.out.println(contentValue); decimalcheck(contentValue, "In Transfer Rate ", 1); } else if (content.equals("Containment Rate (All)")) { String percentage = check.get(i + 1).getText(); String[] contentValues = percentage.split("%"); contentValue = contentValues[0]; System.out.println(contentValue); // System.out.println(NumberFormat.getNumberInstance(Locale.US).format(contentValue)); decimalcheck(contentValue, "In Containment Rate ", 1); } } ReportFile.addTestCase( "ODI6.x-628:CSSR numbers Formatting", "ODI6.x-628:CSSR numbers Formatting => Pass"); } catch (Exception e) { driver.quit(); e.printStackTrace(); } driver.quit(); }
// ----------------------These functions require a driver public static List<WebElement> createWebElementsList( WebDriver driver, WebElement component, By by) { List<WebElement> webElements; driver.manage().timeouts().implicitlyWait(0, TimeUnit.MILLISECONDS); // Quickly webElements = component.findElements(by); driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS); return webElements; }
@Ignore({MARIONETTE}) @Test(expected = InvalidSelectorException.class) public void testShouldThrowInvalidSelectorExceptionWhenXPathReturnsWrongTypeInElementFindElements() { assumeFalse("Ignoring xpath error test in IE6", TestUtilities.isIe6(driver)); driver.get(pages.formPage); WebElement body = driver.findElement(By.tagName("body")); body.findElements(By.xpath("count(//input)")); }
@Ignore({MARIONETTE}) @Test(expected = InvalidSelectorException.class) public void testShouldThrowInvalidSelectorExceptionWhenXPathIsSyntacticallyInvalidInElementFindElements() { assumeFalse("Ignoring xpath error test in IE6", TestUtilities.isIe6(driver)); driver.get(pages.formPage); WebElement body = driver.findElement(By.tagName("body")); body.findElements(By.xpath("this][isnot][valid")); }
@Ignore(SELENESE) public void testShouldIgnoreScriptElements() { driver.get(javascriptEnhancedForm); WebElement labelForUsername = driver.findElement(By.id("labelforusername")); String text = labelForUsername.getText(); assertThat(labelForUsername.findElements(By.tagName("script")).size(), is(1)); assertThat(text, not(containsString("document.getElementById"))); assertThat(text, is("Username:")); }
@NotYetImplemented(HTMLUNIT) @Test public void testShouldClickOnGraphTextElements() { assumeFalse("IE version < 9 doesn't support SVG", isOldIe(driver)); driver.get(pages.svgPage); WebElement svg = driver.findElement(By.cssSelector("svg")); List<WebElement> textElements = svg.findElements(By.cssSelector("text")); WebElement appleElement = findAppleElement(textElements); assertNotNull(appleElement); appleElement.click(); WebElement resultElement = driver.findElement(By.id("result")); wait.until(elementTextToEqual(resultElement, "text_apple")); assertEquals("text_apple", resultElement.getText()); }
/** * User interactions can be unpredictable. Seem good with mouse or keyboard but less so with * combined mouse + keyboard * * <p>Use when 'normal' webdriver does not work * * <p>e.g. a normal webDriver click does a ctrl+click an action does a click * * <p>but using action to do a ctrl+click does not work reliably for everybody */ @Test public void multiSelect123WithUserInteractions() { WebElement multiSelect; multiSelect = driver.findElement(By.cssSelector("select[multiple='multiple']")); List<WebElement> multiSelectOptions = multiSelect.findElements(By.tagName("option")); // in real life, clicking on a multi select item without holding down // CTRL will deselect all others and select only that one item Actions actions = new Actions(driver); // actions.keyUp(Keys.CONTROL).perform(); // click on the first one // also deselects number 4 actions.click(multiSelectOptions.get(0)).perform(); // Press Control + Left mouse button for 2 and 3 actions .keyDown(Keys.CONTROL) .click(multiSelectOptions.get(1)) .click(multiSelectOptions.get(2)) .keyUp(Keys.CONTROL) .build() .perform(); clickSubmitButton(); new WebDriverWait(driver, 10).until(ExpectedConditions.titleIs("Processed Form Details")); List<WebElement> selectedItems = driver.findElements(By.cssSelector("[id^='_valuemultipleselect']")); try { assertEquals("Expected 3 matches", 3, selectedItems.size()); assertEquals("ms1", selectedItems.get(0).getText()); assertEquals("ms2", selectedItems.get(0).getText()); assertEquals("ms3", selectedItems.get(0).getText()); fail("What browser and WebDriver combination did you use? This normally fails"); } catch (AssertionFailedError e) { assertTrue("either I've done something wrong or this is not reliable enough", true); } }
@Test public void testShouldClickOnGraphTextElements() { driver.get(pages.svgPage); WebElement svg = driver.findElement(By.cssSelector("svg")); List<WebElement> textElements = svg.findElements(By.cssSelector("text")); if (isFirefox30(driver) && isNativeEventsEnabled(driver)) { System.out.println( "Not testing SVG elements with Firefox 3.0 and native events as" + " this functionality is not working."); return; } WebElement appleElement = findAppleElement(textElements); assertNotNull(appleElement); appleElement.click(); WebElement resultElement = driver.findElement(By.id("result")); waitFor(elementTextToEqual(resultElement, "text_apple")); assertEquals("text_apple", resultElement.getText()); }
@NotYetImplemented(HTMLUNIT) @Test public void testShouldClickOnGraphVisualElements() { assumeFalse("IE version < 9 doesn't support SVG", isOldIe(driver)); driver.get(pages.svgPage); WebElement svg = driver.findElement(By.cssSelector("svg")); List<WebElement> groupElements = svg.findElements(By.cssSelector("g")); assertEquals(5, groupElements.size()); groupElements.get(1).click(); WebElement resultElement = driver.findElement(By.id("result")); wait.until(elementTextToEqual(resultElement, "slice_red")); assertEquals("slice_red", resultElement.getText()); groupElements.get(2).click(); resultElement = driver.findElement(By.id("result")); wait.until(elementTextToEqual(resultElement, "slice_green")); assertEquals("slice_green", resultElement.getText()); }
@Override public List<WebElement> findElements(final WebElement element, final By by, int seconds) { return element.findElements(by); }
// ODI6.x-627:generate cssr report with valid filters and check the number if they are reasonable public void cssrNumbers() { int CallVolumeValue = 0, TransfersValue = 0, PeakHourValue = 0; double roundOff = 0, AverageCallValue = 0; String dmName = "US_AIRWAYS"; gotoreports(dmName); pickAvalidDate(); try { new WebDriverWait(driver, 10) .until(ExpectedConditions.frameToBeAvailableAndSwitchToIt("reportContent")); WebElement page = new WebDriverWait(driver, 10) .until(ExpectedConditions.visibilityOfElementLocated(By.id("CrystalViewer"))); List<WebElement> check = page.findElements(By.tagName("span")); for (int i = 0; i < check.size(); i++) { String content = (check.get(i).getText()); if (content.equals("Call Volume")) { String CallVolume = (check.get(i + 1).getText()); String[] CallVolumes = CallVolume.split("\\s"); CallVolumeValue = Integer.parseInt(CallVolumes[1]); System.out.println(CallVolumeValue); } else if (content.equals("Transfers (All)")) { String TransfersAll = (check.get(i + 1).getText()); String[] Tvalues = TransfersAll.split("\\s"); TransfersValue = Integer.parseInt(Tvalues[1]); System.out.println(TransfersValue); } else if (content.equals("Peak Hour Call Volume")) { String PeakHourCallVolume = (check.get(i + 1).getText()); String[] PeakHourCallValues = PeakHourCallVolume.split("\\s"); PeakHourValue = Integer.parseInt(PeakHourCallValues[1]); } else if (content.equals("Call Duration (minutes)")) { String CallDuration = (check.get(i + 1).getText()); String[] CallDurationValues = CallDuration.split("\\s"); double CallDurationValue = Double.parseDouble(CallDurationValues[1]); double x = CallDurationValue / CallVolumeValue; roundOff = Math.round(x * 100.0) / 100.0; } else if (content.equals("Average Call Duration (minutes)")) { String AverageCallDuration = (check.get(i + 1).getText()); String[] AverageCallDurationValues = AverageCallDuration.split("\\s"); AverageCallValue = Double.parseDouble(AverageCallDurationValues[1]); } } try { if (CallVolumeValue >= TransfersValue) { logger.info("the call volume is greater than the Transfer"); System.out.println("CallVolumeValue >= TransfersValue"); } if (PeakHourValue <= CallVolumeValue) { System.out.println("PeakHourValue <= CallVolumeValue"); } if (AverageCallValue == roundOff) { System.out.println("Average Call Duration =Call Duration (minutes)/Call Volume"); } } catch (Exception e) { e.printStackTrace(); } ReportFile.addTestCase( "ODI6.x-627:CSSR numbers must be reasonable", "ODI6.x-627:CSSR numbers must be reasonable => Pass"); } catch (Exception e) { e.printStackTrace(); } ReportFile.WriteToFile(); driver.quit(); }
@Override public List<WebElement> findElements(By by) { return webElement.findElements(by); }