@Test(expected = NoSuchElementException.class) public void shouldBeAbleToClickInAFrame() throws InterruptedException { WebDriver d = getDriver(); d.get("http://docs.wpm.neustar.biz/testscript-api/index.html"); assertEquals("__MAIN_FRAME__", getCurrentFrameName(d)); d.switchTo().frame("classFrame"); assertEquals("classFrame", getCurrentFrameName(d)); // This should cause a reload in the frame "classFrame" d.findElement(By.linkText("HttpClient")).click(); // Wait for new content to load in the frame. WebDriverWait wait = new WebDriverWait(d, 10); wait.until(ExpectedConditions.titleContains("HttpClient")); // Frame should still be "classFrame" assertEquals("classFrame", getCurrentFrameName(d)); // Check if a link "clearCookies()" is there where expected assertEquals("clearCookies", d.findElement(By.linkText("clearCookies")).getText()); // Make sure it was really frame "classFrame" which was replaced: // 1. move to the other frame "packageFrame" d.switchTo().defaultContent().switchTo().frame("packageFrame"); assertEquals("packageFrame", getCurrentFrameName(d)); // 2. the link "clearCookies()" shouldn't be there anymore d.findElement(By.linkText("clearCookies")); }
private void SpecialNeeds() throws IOException { // Click Special Needs driver .findElement( By.xpath( "//ul[@class='vertical-tabs-list']/li/a/strong[contains(text(), \"Special Needs\")]")) .click(); // Select Special Needs Select SpecialNeeds = new Select(driver.findElement(By.id("edit-special-needs"))); // Select Learning Center SpecialNeeds.selectByVisibleText("Learning Center"); // Select Early Syllabus SpecialNeeds.selectByVisibleText("Early syllabus"); // Click Apply driver.findElement(By.id("edit-special-needs-apply-filter")).click(); // Check Result Received or Not try { assertTrue( func.isTextPresent(driver.findElement(By.className("search-total-results")).getText())); } catch (Error e) { verificationErrors.append(e.toString()); } // Click All Selections driver.findElement(By.linkText("Clear All Selections")).click(); }
@Test public void testLoginMaster2() throws Exception { driver.get(baseUrl + "/login.html"); driver.findElement(By.name("j_username")).clear(); driver.findElement(By.name("j_username")).sendKeys("*****@*****.**"); driver.findElement(By.name("j_password")).clear(); driver.findElement(By.name("j_password")).sendKeys("master"); driver.findElement(By.xpath("//input[@value='Login']")).click(); driver.findElement(By.linkText("Sign out")).click(); }
@Test public void testSearchFeature() { // find search, check if search works by sending a search time, see that results exist WebElement element = driver.findElement(By.name("search_block_form")); element.sendKeys("Laboon"); element.sendKeys(Keys.RETURN); assert (driver.findElement(By.name("Laboon")) != null); // is it good enough? }
@Test public void testBookSearch5() throws Exception { driver.get(baseUrl + "/proyectoBiblioteca/"); new Select(driver.findElement(By.name("type"))).selectByVisibleText("Editorial"); driver.findElement(By.name("search")).clear(); driver.findElement(By.name("search")).sendKeys("De Bolsillo"); driver.findElement(By.xpath("//button[@type='submit']")).click(); assertEquals( "Libros Encontrados", driver.findElement(By.cssSelector("div.panel-heading")).getText()); }
/* Given: Logged into a valid account When: I look at the navigation bar Then: I will see a link for my user profile */ @Test public void testProfile(){ driver.findElement(By.id("navbar_username")).clear(); driver.findElement(By.id("navbar_username")).sendKeys("Aytros"); driver.findElement(By.id("navbar_password")).clear(); driver.findElement(By.id("navbar_password")).sendKeys("Mystra@428"); driver.findElement(By.value("Log in")).click(); String test = driver.findElement(By.linkText("Aytros")).getAttribute("title"); assertTrue(test.contains("Profile")); }
@Test public void switchToFrameByElement() { WebDriver d = getDriver(); d.get("http://docs.wpm.neustar.biz/testscript-api/index.html"); assertEquals("__MAIN_FRAME__", getCurrentFrameName(d)); d.switchTo().frame(d.findElement(By.name("packageFrame"))); assertEquals("packageFrame", getCurrentFrameName(d)); d.switchTo().defaultContent(); assertEquals("__MAIN_FRAME__", getCurrentFrameName(d)); d.switchTo().frame(d.findElement(By.name("packageFrame"))); assertEquals("packageFrame", getCurrentFrameName(d)); }
@Test public void testMyFirstWebDriver() throws Exception { driver.get(baseUrl + "/HotelApp/"); driver.findElement(By.linkText("New User Register Here")).isDisplayed(); driver.findElement(By.xpath(".//*[@id='username']")).clear(); driver.findElement(By.xpath(".//*[@id='username']")).sendKeys(""); driver.findElement(By.id("password")).clear(); driver.findElement(By.id("password")).sendKeys(""); driver.findElement(By.id("login")).click(); // actualText = driver.findElement(By.id("username_span")).getText(); actualText = driver.findElement(By.cssSelector(".login_error")).getText(); assertEquals(expectedText, actualText); }
private void TypesOfSchool() throws IOException { // Click Type of School driver.findElement(By.cssSelector("strong")).click(); // Click Private driver.findElement(By.id("edit-public-private-private")).click(); // Move School Size Slider // TODO Slider not working properly WebElement Slider1 = driver.findElement(By.id("population_jq_slider")); Actions moveSlider1 = new Actions(driver); Action action1 = moveSlider1.dragAndDropBy(Slider1, 0, 10).build(); action1.perform(); // Select Religious Affiliation new Select(driver.findElement(By.id("edit-religious-affiliation"))) .selectByVisibleText("Church of Christ"); // Move Tuition Range Slider // TODO Slider not working properly WebElement Slider2 = driver.findElement(By.id("tuition_range_jq_slider")); Actions moveSlider2 = new Actions(driver); Action action2 = moveSlider2.dragAndDropBy(Slider2, 0, 10).build(); action2.perform(); // Click Apply driver.findElement(By.id("edit-type-of-school-apply-filter")).click(); // Check Result Received or Not try { assertTrue( func.isTextPresent(driver.findElement(By.className("search-total-results")).getText())); } catch (Error e) { verificationErrors.append(e.toString()); } // Click All Selections driver.findElement(By.linkText("Clear All Selections")).click(); }
private void SearchButton() throws IOException { // Enter Text To Be Search driver.findElement(By.id("edit-keys")).clear(); driver.findElement(By.id("edit-keys")).sendKeys("Abilene"); // Click Search driver.findElement(By.id("edit-submit")).click(); // Check Result Received or Not try { assertTrue( func.isTextPresent(driver.findElement(By.className("search-total-results")).getText())); } catch (Error e) { verificationErrors.append(e.toString()); } // Click All Selections driver.findElement(By.linkText("Clear All Selections")).click(); }
private boolean isElementPresent(By by) { try { driver.findElement(by); return true; } catch (NoSuchElementException e) { return false; } }
@Test public void testAddCampaign() throws Exception { driver.get(baseUrl + "/"); driver.findElement(By.id("username")).clear(); driver.findElement(By.id("username")).sendKeys("test"); driver.findElement(By.id("password")).clear(); driver.findElement(By.id("password")).sendKeys("test"); driver.findElement(By.cssSelector("button.btn.btn-default")).click(); driver.findElement(By.linkText("Campaigns")).click(); driver.findElement(By.cssSelector("button.btn.btn-default")).click(); driver.findElement(By.xpath("(//button[@type='button'])[2]")).click(); driver.findElement(By.cssSelector("div.input-group > input.form-control")).clear(); driver.findElement(By.cssSelector("div.input-group > input.form-control")).sendKeys("test2"); driver.findElement(By.cssSelector("span.input-group-btn > button.btn.btn-default")).click(); new Select(driver.findElement(By.cssSelector("select.form-control"))) .selectByVisibleText("test2"); driver.findElement(By.xpath("//button[@type='button']")).click(); }
@Test public void testWeather() throws Exception { driver.get(baseUrl + "/"); driver.findElement(By.linkText("Edmonton")).click(); for (int second = 0; ; second++) { if (second >= 60) fail("timeout"); try { if (isElementPresent(By.id("cityjump"))) break; } catch (Exception e) { } Thread.sleep(1000); } // Warning: verifyTextPresent may require manual changes try { assertTrue( driver .findElement(By.cssSelector("BODY")) .getText() .matches("^[\\s\\S]*Current Conditions[\\s\\S]*$")); } catch (Error e) { verificationErrors.append(e.toString()); } // Warning: verifyTextPresent may require manual changes try { assertTrue( driver .findElement(By.cssSelector("BODY")) .getText() .matches("^[\\s\\S]*Forecast[\\s\\S]*$")); } catch (Error e) { verificationErrors.append(e.toString()); } // Warning: verifyTextPresent may require manual changes try { assertTrue( driver .findElement(By.cssSelector("BODY")) .getText() .matches("^[\\s\\S]*Edmonton City Centre Airport[\\s\\S]*$")); } catch (Error e) { verificationErrors.append(e.toString()); } }
private WebElement findElement(final By locator) { (new WebDriverWait(driver, 30, 1000)) .until(ExpectedConditions.presenceOfElementLocated(locator)); (new WebDriverWait(driver, 30, 1000)) .until(ExpectedConditions.visibilityOfElementLocated(locator)); WebElement element = driver.findElement(locator); if (element.isEnabled() == false) ((JavascriptExecutor) driver).executeScript("arguments[0].disabled = false", element); return element; }
@Test public void shouldSwitchBackToMainFrameIfLinkInFrameCausesTopFrameReload() throws Exception { WebDriver d = getDriver(); String expectedTitle = "Unique title"; d.get("http://localhost:2310/common/frameset.html"); assertEquals(expectedTitle, d.getTitle()); d.switchTo().frame(0); d.findElement(By.linkText("top")).click(); // Wait for new content to load in the frame. expectedTitle = "XHTML Test Page"; WebDriverWait wait = new WebDriverWait(d, 10); wait.until(ExpectedConditions.titleIs(expectedTitle)); assertEquals(expectedTitle, d.getTitle()); WebElement element = d.findElement(By.id("amazing")); assertNotNull(element); }
@Test public void testFindKioskFlow() throws Exception { driver.findElement(By.xpath("//a[contains(@href, '/fluffbox-rwx/kiosk/find')]")).click(); driver.findElement(By.id("searchCriteria")).sendKeys("Ft. Lauderdale"); driver.findElement(By.id("searchButton")).click(); WebElement walgreensInsideLink = waitForDynamicElement(By.linkText("Walgreens (Inside)")); walgreensInsideLink.click(); WebElement gMapInfoWindow = waitForDynamicElement(By.cssSelector("div.gmnoprint > div.gmnoprint > div > div")); assertThat(gMapInfoWindow.getText(), containsString("3895 W Broward Blvd")); WebElement winnDixieOutsideLink = waitForDynamicElement(By.linkText("Winn Dixie (Outside)")); winnDixieOutsideLink.click(); gMapInfoWindow = waitForDynamicElement(By.cssSelector("div.gmnoprint > div.gmnoprint > div > div")); assertThat(gMapInfoWindow.getText(), containsString("1531 N State Road 7")); }
@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 public void testHasContact() { // Check if webpage has "contact us" // these is not found, fail the test try { driver.findElement(By.xpath("//*[@id='nodesinblock-21']/article/section/p[1]/a")); } catch (NoSuchElementException nseex) { fail(); } }
private void AreaOfStudy() throws IOException, InterruptedException { // Click Area of School driver .findElement( By.xpath( "//ul[@class='vertical-tabs-list']/li/a/strong[contains(text(), \"Area of Study\")]")) .click(); // Select One Area Study new Select(driver.findElement(By.id("edit-area-of-study-parent"))) .selectByVisibleText("Area, Ethnic, Cultural, and Gender Studies"); // Wait For Another Select List To Load Thread.sleep(5000); // Select Subareas of Study new Select(driver.findElement(By.xpath("//div[@id='child-area-of-study-wrapper']//select"))) .selectByVisibleText("Area, Ethnic, Cultural, and Gender Studies, Other"); // Click Apply driver.findElement(By.id("edit-area-of-study-apply-filter")).click(); // Check Result Received or Not try { assertTrue( func.isTextPresent(driver.findElement(By.className("search-total-results")).getText())); } catch (Error e) { verificationErrors.append(e.toString()); } // Click All Selections driver.findElement(By.linkText("Clear All Selections")).click(); }
// Delete CSR @Test public void Test5() throws Exception { driver.get(baseUrl + "/#/host/magehostmanager.magemojo.com/configuration/ssl"); driver.findElement(By.xpath("//a[contains(text(),'www.Testing5.com')]")).click(); assertEquals( "Download CSR www.Testing5.com", driver.findElement(By.xpath("//legend[4]")).getText()); driver.findElement(By.xpath("(//button[@type='button'])[8]")).click(); assertEquals( "Confirmation Window", driver.findElement(By.cssSelector("h3.modal-title.ng-binding")).getText()); assertTrue(isElementPresent(By.xpath("//div[3]/button[2]"))); driver.findElement(By.xpath("//div[3]/button")).click(); for (int second = 0; ; second++) { if (second >= 60) fail("timeout"); try { if ("Successfully deleted the CSR." .equals(driver.findElement(By.xpath("//div[@id='toast-container']/div")).getText())) break; } catch (Exception e) { } Thread.sleep(1000); } for (int second = 0; ; second++) { if (second >= 60) fail("timeout"); try { if (!isElementPresent(By.xpath("//a[contains(text(),'www.Testing5.com')]"))) break; } catch (Exception e) { } Thread.sleep(1000); } }
private void ActivitiesOfInterest() throws IOException { // Click Activities of Interest driver .findElement( By.xpath( "//ul[@class='vertical-tabs-list']/li/a/strong[contains(text(), \"Activities of Interest\")]")) .click(); // Click Student Newspaper Checkbox // TODO Do not use number in locator driver.findElement(By.xpath("//div[11]/input")).click(); // Click TV Station Checkbox // TODO Do not use number in locator driver.findElement(By.xpath("//div[13]/input")).click(); // Click Apply driver.findElement(By.id("edit-activities-interests-apply-filter")).click(); // Check Result Received or Not try { assertTrue( func.isTextPresent(driver.findElement(By.className("search-total-results")).getText())); } catch (Error e) { verificationErrors.append(e.toString()); } // Click All Selections driver.findElement(By.linkText("Clear All Selections")).click(); }
private void Location() throws IOException { // Click Location driver .findElement( By.xpath( "//ul[@class='vertical-tabs-list']/li/a/strong[contains(text(), \"Location\")]")) .click(); // Click West Checkbox // TODO Do not use number in Locator driver.findElement(By.xpath("//fieldset[6]/div/div[4]/div/div[3]/input")).click(); // Click South Checkbox // TODO Do not use number in Locator driver.findElement(By.xpath("//fieldset[6]/div/div[4]/div/div[6]/input")).click(); // Click Apply driver.findElement(By.id("edit-location-apply-filter")).click(); // Check Result Received or Not try { assertTrue( func.isTextPresent(driver.findElement(By.className("search-total-results")).getText())); } catch (Error e) { verificationErrors.append(e.toString()); } // Click All Selections driver.findElement(By.linkText("Clear All Selections")).click(); }
public void optionalClick(final By locator) { WebElement we = null; try { we = driver.findElement(locator); we.click(); } catch (StaleElementReferenceException ser) { } catch (NoSuchElementException nse) { } catch (Exception e) { // staticlogger.info( e.getMessage() ); } }
@Test public void testClientOptions() throws Exception { driver.get(baseUrl + "/login"); driver.findElement(By.id("inputEmail")).clear(); driver.findElement(By.id("inputEmail")).sendKeys("*****@*****.**"); driver.findElement(By.id("inputPassword")).clear(); driver.findElement(By.id("inputPassword")).sendKeys("qwerty"); driver.findElement(By.xpath("//button")).click(); driver.findElement(By.id("blockButton")).click(); driver.findElement(By.xpath("//p[3]/button")).click(); driver.findElement(By.xpath("//button[3]")).click(); driver.findElement(By.id("blockButton")).click(); driver.findElement(By.xpath("//p[3]/button")).click(); driver.findElement(By.id("discard")).click(); }
@Test public void test35() throws Exception { driver.get(baseUrl + "/accountType/list"); driver.findElement(By.xpath("//strong[text()='Direct Customer']")).click(); driver.findElement(By.cssSelector("a.submit.edit > span")).click(); driver.findElement(By.id("creditLimitAsDecimal")).clear(); driver.findElement(By.id("creditLimitAsDecimal")).sendKeys("300.00"); driver.findElement(By.cssSelector("a.submit.save > span")).click(); driver.findElement(By.xpath("//strong[text()='Direct Customer']")).click(); driver.findElement(By.cssSelector("a.submit.edit > span")).click(); driver.findElement(By.id("creditLimitAsDecimal")).clear(); driver.findElement(By.id("creditLimitAsDecimal")).sendKeys("200.00"); driver.findElement(By.cssSelector("a.submit.save > span")).click(); driver.findElement(By.xpath("//strong[text()='Direct Customer']")).click(); Assert.assertEquals(driver.getPageSource().contains("US$200.00"), true); }
private void Sports() throws IOException { // Click Sports driver .findElement( By.xpath("//ul[@class='vertical-tabs-list']/li/a/strong[contains(text(), \"Sports\")]")) .click(); // Select Sports Select Sports = new Select(driver.findElement(By.id("edit-varsity-sports"))); // Select Baseball Sports.selectByVisibleText("baseball"); // Select Basketball Sports.selectByVisibleText("basketball"); // Click Apply driver.findElement(By.id("edit-varsity-sports-apply-filter")).click(); // Check Result Received or Not try { assertTrue( func.isTextPresent(driver.findElement(By.className("search-total-results")).getText())); } catch (Error e) { verificationErrors.append(e.toString()); } // Click All Selections driver.findElement(By.linkText("Clear All Selections")).click(); }
private WebElement waitForDynamicElement(By locator) throws Exception { WebElement dynamicElement = null; for (int second = 0; ; second++) { if (second >= 60) fail("timeout"); try { dynamicElement = driver.findElement(locator); break; } catch (Exception e) { } Thread.sleep(1000); } return dynamicElement; }
@Test public void testOtsi() throws Exception { driver.get(baseUrl + "/"); driver.findElement(By.linkText("Kandidaadid")).click(); // Warning: waitForTextPresent may require manual changes for (int second = 0; ; second++) { if (second >= 60) fail("timeout"); try { if (driver .findElement(By.cssSelector("BODY")) .getText() .matches("^[\\s\\S]*Vana Kala[\\s\\S]*$")) break; } catch (Exception e) { } Thread.sleep(1000); } driver.findElement(By.id("nimi")).clear(); driver.findElement(By.id("nimi")).sendKeys("Magdalena"); try { assertEquals("Magdalena", driver.findElement(By.id("nimi")).getAttribute("value")); } catch (Error e) { verificationErrors.append(e.toString()); } driver.findElement(By.id("sButton")).click(); // Warning: waitForTextPresent may require manual changes for (int second = 0; ; second++) { if (second >= 60) fail("timeout"); try { if (driver .findElement(By.cssSelector("BODY")) .getText() .matches("^[\\s\\S]*Magdalena Malejeva[\\s\\S]*$")) break; } catch (Exception e) { } Thread.sleep(1000); } // Warning: verifyTextNotPresent may require manual changes try { assertFalse( driver .findElement(By.cssSelector("BODY")) .getText() .matches("^[\\s\\S]*Vana Kala[\\s\\S]*$")); } catch (Error e) { verificationErrors.append(e.toString()); } }
@Test public void shouldBeAbleToSwitchToIFrameThatHasNoNameNorId() { server.setGetHandler( new HttpRequestCallback() { @Override public void call(HttpServletRequest req, HttpServletResponse res) throws IOException { res.getOutputStream() .println("<html>" + "<body>" + " <iframe></iframe>" + "</body>" + "</html>"); } }); WebDriver d = getDriver(); d.get(server.getBaseUrl()); WebElement el = d.findElement(By.tagName("iframe")); d.switchTo().frame(el); }
@Ignore // Ignored because you need to kickstart Python SimpleHTTPServer before it can run @Test public void shouldSwitchToTheRightFrame_issue226() { // NOTE: before starting this test, // run `python -m SimpleHTTPServer` from within `test/testcase-issue_226`. // This will launch a minimal webserver to serve the pages for this test. WebDriver d = getDriver(); // Load "outside.html" and check it's the right one d.get("http://localhost:8000/outside.html"); assertTrue(d.getPageSource().contains("Editing testDotAtEndDoesNotDelete")); assertEquals(2, d.findElements(By.tagName("iframe")).size()); // Find the iframe with class "gwt-RichTextArea" WebElement iframeRichTextArea = d.findElement(By.className("gwt-RichTextArea")); // Switch to the iframe via WebElement and check it's the right one d.switchTo().frame(iframeRichTextArea); assertEquals(0, d.findElements(By.tagName("title")).size()); assertFalse(d.getPageSource().contains("Editing testDotAtEndDoesNotDelete")); assertEquals(0, d.findElements(By.tagName("iframe")).size()); // Switch back to the main frame and check it's the right one d.switchTo().defaultContent(); assertEquals(2, d.findElements(By.tagName("iframe")).size()); // Switch again to the iframe, this time via it's "frame number" (i.e. 0 to n) d.switchTo().frame(0); assertEquals(0, d.findElements(By.tagName("title")).size()); assertFalse(d.getPageSource().contains("Editing testDotAtEndDoesNotDelete")); assertEquals(0, d.findElements(By.tagName("iframe")).size()); // Switch back to the main frame and check it's the right one d.switchTo().defaultContent(); assertEquals(2, d.findElements(By.tagName("iframe")).size()); // Switch to the second frame via it's "frame number" d.switchTo().frame(1); assertEquals(1, d.findElements(By.tagName("title")).size()); assertEquals(0, d.findElements(By.tagName("iframe")).size()); assertTrue(d.getPageSource().contains("WYSIWYG Editor Input Template")); // Switch again to the main frame d.switchTo().defaultContent(); assertEquals(2, d.findElements(By.tagName("iframe")).size()); }