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 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? }
// Method checking if the edited profile is displayed back to the user and if illegal string like // URL and email id are stripped off from "profile essay" sections private void verifyChanges() { List<WebElement> allElements = driver.findElements(By.cssSelector("div[id='about_myself'] p")); for (WebElement element1 : allElements) { if (element1.getText().contains("www.") || element1.getText().contains(".com")) ; ripOffTextAboutMe++; } List<WebElement> allElements2 = driver.findElements(By.cssSelector("div[id='who_im_looking_for'] p")); for (WebElement element2 : allElements2) { if (element2.getText().contains("www.") || element2.getText().contains(".com")) ; ripOffTextPartnerSearch++; } List<WebElement> allElement3 = driver.findElements(By.cssSelector("ul[class='profileInformation'] li")); for (WebElement element3 : allElement3) { // System.out.println(element3.getText()); if (element3.getText().contains("Mixed") || element3.getText().contains("4ft. 10in.")) profileChangeCheck++; } if (profileChangeCheck > 0) System.out.println("SUCCESS: The changes made in the basic profile are visible"); if (ripOffTextAboutMe != 0) System.out.println( "SUCCESS: The About Myself section has ripped off any illegal strings like URL and Email id"); if (ripOffTextPartnerSearch != 0) System.out.println( "SUCCESS: The What I am Looking For section has ripped off any illegal strings like URL and Email id"); }
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 testUntitled2() throws Exception { driver.get(baseUrl + "php4dvd/"); WebElement userNameWebEdit = driver.findElement(By.id("username")); WebElement passwordWebEdit = driver.findElement(By.name("password")); WebElement subminButton = driver.findElement(By.name("submit")); userNameWebEdit.clear(); userNameWebEdit.sendKeys("admin"); passwordWebEdit.clear(); passwordWebEdit.sendKeys("admin"); subminButton.click(); }
private void checkDemoPage(String lang) throws InterruptedException { checkElementVisible("page_loader", false); checkElementVisible("login_widget", false); checkElementVisible("webapp_ctx", true); checkElementVisible("error_window", false); checkElementVisible("success_window", true); // Extra check checkWidgetsOnLogin(); // Check success message assertEquals( "Success message doesn't match", getLabelText(lang, "LL_DEMO_MSG"), driver.findElement(By.id("ok_msg")).getText()); // Click on close button driver.findElement(By.id("success_window")).findElement(By.className("b-close")).click(); Thread.sleep(1000); checkElementVisible("webapp_ctx", true); checkElementVisible("error_window", false); checkElementVisible("success_window", false); // Check color of message WebElement dmsg = driver.findElement(By.className("demo")); assertEquals( "demo message color doesn't match", "rgba(128, 128, 128, 1)", dmsg.getCssValue("color")); checkButtonById(lang, "ll_error", true); checkButtonById(lang, "ll_logout", true); // Check & Press error button WebElement err = driver.findElement(By.id("ll_error")); err.click(); Thread.sleep(500); checkErrorWin( lang, "C-DEMO", getLabelText(lang, "LL_INFO_MSG"), getLabelText(lang, "LL_DETAIL_MSG_1") + "\n" + getLabelText(lang, "LL_DETAIL_MSG_2")); }
@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 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 testLogin() throws Exception { // open | /webui/ | driver.get(baseUrl + "webui/"); // type | id=loginPanel_grdLogin_rowUser_txtUserId | GardenAdmin driver.findElement(By.id("loginPanel_txtUserId")).clear(); driver.findElement(By.id("loginPanel_txtUserId")).sendKeys("GardenAdmin"); // fireEvent | id=loginPanel_grdLogin_rowUser_txtUserId | blur // not needed for webdriver // type | id=loginPanel_grdLogin_rowPassword_txtPassword | GardenAdmin driver.findElement(By.id("loginPanel_txtPassword")).clear(); driver.findElement(By.id("loginPanel_txtPassword")).sendKeys("GardenAdmin"); // fireEvent | id=loginPanel_grdLogin_rowPassword_txtPassword | blur // not needed for webdriver // click | id=loginPanel_grdLogin_rowSelectRole_chkSelectRole-real | driver.findElement(By.id("loginPanel_chkSelectRole-real")).click(); // click | loginPanel_Ok | 10 driver.findElement(By.id("loginPanel_Ok")).click(); // waitForElementPresent | id=rolePanel_grdChooseRole_rowclient_lstClient-btn | for (int second = 0; ; second++) { if (second >= 60) fail("timeout"); try { if (isElementPresent(By.id("rolePanel_lstClient-btn"))) break; } catch (Exception e) { } Thread.sleep(1000); } WebElement lstClient = driver.findElement(By.id("rolePanel_lstClient")); if (lstClient != null && lstClient.isDisplayed()) { // click | id=rolePanel_grdChooseRole_rowclient_lstClient-btn | driver.findElement(By.id("rolePanel_lstClient-btn")).click(); // click | css=#rolePanel_grdChooseRole_rowclient_lstClient_GardenWorld > td.z-comboitem-text // | driver .findElement(By.cssSelector("#rolePanel_lstClient_GardenWorld > td.z-comboitem-text")) .click(); Thread.sleep(1000); } // click | id=rolePanel_grdChooseRole_rowRole_lstRole-btn | driver.findElement(By.id("rolePanel_lstRole-btn")).click(); // click | css=#rolePanel_grdChooseRole_rowRole_lstRole_GardenWorld_Admin > td.z-comboitem-text // | driver .findElement(By.cssSelector("#rolePanel_lstRole_GardenWorld_Admin > td.z-comboitem-text")) .click(); Thread.sleep(1000); // click | id=rolePanel_grdChooseRole_rowOrganisation_lstOrganisation-btn | driver.findElement(By.id("rolePanel_lstOrganisation-btn")).click(); // click | css=#rolePanel_grdChooseRole_rowOrganisation_lstOrganisation_HQ > td.z-comboitem-text // | driver .findElement(By.cssSelector("#rolePanel_lstOrganisation_HQ > td.z-comboitem-text")) .click(); // click | rolePanel_Ok | driver.findElement(By.id("rolePanel_Ok")).click(); // waitForElementPresent | loginUserAndRole | for (int second = 0; ; second++) { if (second >= 60) fail("timeout"); try { if (isElementPresent(By.id("loginUserAndRole"))) break; } catch (Exception e) { } Thread.sleep(1000); } // assertText | loginUserAndRole | [email protected]/GardenWorld Admin assertEquals( "[email protected]/GardenWorld Admin", driver.findElement(By.id("loginUserAndRole")).getText()); }
@Test public void LFTMain() throws Exception { JavascriptExecutor js = (JavascriptExecutor) webDriver; selenium.open(baseUrl); selenium.type("id=id_username", sender); selenium.type("id=id_password", "123abc"); selenium.click("css=input[type=\"submit\"]"); selenium.waitForPageToLoad("2000"); System.out.println("First: The page title is " + selenium.getTitle()); // code to upload file driver.findElement(By.linkText("Compose")).click(); selenium.waitForPageToLoad("3000"); // Runtime.getRuntime().exec("C:\\Users\\Sneha\\Desktop\\IE.exe"); Runtime.getRuntime().exec("C:\\Users\\Sneha\\Desktop\\silver_autoit.exe"); Functions.MyWaitfunc(driver, "//*[@id='uploader_browse']"); WebElement ele = driver.findElement(By.xpath("//*[@id='uploader_browse']")); ele.click(); // ele.sendKeys("C:\\Users\\Sneha\\Desktop\\Lighthouse.jpg"); // send secure mail // driver.findElement(By.id("secure")).click(); driver.findElement(By.id("addrin")).sendKeys(recipient); driver.findElement(By.id("id_subject")).sendKeys(stringToTest_tc001); String torun = "document.getElementById('tinymce').innerHTML='Hi there!'"; driver.findElement(By.id("addrsubmit")).click(); /*selenium.waitForPageToLoad("3000"); Thread.sleep(100); js.executeScript(torun); System.out.println((String)js.executeScript("return document.title")); */ driver.switchTo().frame("id_body_ifr"); selenium.typeKeys("//body[@id='tinymce']", "Finally wohoooo!!"); driver.switchTo().defaultContent(); driver.findElement(By.id("submitter")).click(); /* code only if it is LFT String per_done="//html/body/div/div[2]/div[4]/form/fieldset/div[9]/div/div/div/div[2]/table[2]/tbody/tr/td[3]/span"; NoSuchElementException e1 = null; // code to wait for file to be uploaded for (int second = 0;; second++) { if (second >= 60) {fail("timeout");} try { if (driver.findElement(By.xpath(per_done)).getText().equalsIgnoreCase("548 KB")) break; } catch (Exception e) {} Thread.sleep(1000); } */ // mail body /* code to run if LFT //System.out.println((String)js. if((this.doesWebElementExist(driver,By.xpath(per_done))) && (driver.findElement(By.xpath(per_done)).getText().equalsIgnoreCase("548 KB"))) {//driver.findElement(By.id("submitter")).click(); } else throw e1; */ /* this section if confirm dialog pops up! this.MyWaitfunc("//html/body/div[4]/div[11]/div/button/span"); if(driver.findElement(By.xpath("//html/body/div[4]/div[11]/div/button/span")).isDisplayed()) driver.findElement(By.xpath("//html/body/div[4]/div[11]/div/button/span")).click(); else System.out.println("Confirm dialog not up yet!"); */ // to check if mail was sent successfully String success_str_xpath = "//html/body/div/div[2]/div[3]/ul/li"; Functions.MyWaitfunc(driver, success_str_xpath); if ((Functions.doesWebElementExist(driver, By.xpath(success_str_xpath))) && (driver .findElement(By.xpath(success_str_xpath)) .getText() .contains("Successfully sent the email"))) System.out.println("SUCCESS:Mail successfully sent !"); else { System.out.println("FAIL:Mail NOT SENT !"); System.out.println(driver.findElement(By.xpath(success_str_xpath)).getText()); Exception e1 = null; throw e1; } }
private void test_image_picker(WebDriver driver) { // Check both files exist File f1 = null; File f2 = null; try { ClassLoader cl = ImagePickerTest.class.getClassLoader(); f1 = new File(cl.getResource("image_picker_1.png").toURI()); assertTrue(f1.exists()); f2 = new File(cl.getResource("image_picker_2.png").toURI()); assertTrue(f2.exists()); } catch (URISyntaxException e) { e.printStackTrace(); } assertNotNull(f1); assertNotNull(f2); // Login CStudioSeleniumUtil.try_login( driver, CStudioSeleniumUtil.AUTHOR_USER, CStudioSeleniumUtil.AUTHOR_PASSWORD, true); // Navigate to Widget CStudioSeleniumUtil.navigate_to_image_picker_widget(driver); // Upload right file size CStudioSeleniumUtil.click_on(driver, By.id("xf-4$xf-20$imageSrcAltTextTest-imageButton")); // Check popup dialog appears WebElement popup = driver.findElement(By.id("cstudio-wcm-popup-div_c")); assertTrue(popup.isDisplayed()); WebElement input = driver.findElement(By.xpath("/html/body/div[3]/div/div[2]/div/div/div/form/input")); input.sendKeys(f1.getAbsolutePath()); WebElement upload = driver.findElement(By.xpath("/html/body/div[3]/div/div[2]/div/div/div/form/input[2]")); upload.click(); new WebDriverWait(driver, CStudioSeleniumUtil.SHORT_TIMEOUT) .until( new ExpectedCondition<Boolean>() { public Boolean apply(WebDriver d) { WebElement e = d.findElement(By.id("xf-4$xf-20$imageSrcAltTextTest$xf-206$$a")); return e != null && e.getAttribute("class").contains("xforms-alert-inactive"); } }); WebElement mark = driver.findElement(By.id("xf-4$xf-20$imageSrcAltTextTest$xf-206$$a")); assertTrue(mark.getAttribute("class").contains("xforms-alert-inactive")); // Delete uploaded image CStudioSeleniumUtil.click_on(driver, By.id("xf-4$xf-20$imageSrcAltTextTest-deleteButton")); WebElement filename = driver.findElement(By.id("xf-4$xf-20$imageSrcAltTextTest$xf-206-filename")); assertTrue(filename.getText().equals("250W X 130H")); // Upload any image CStudioSeleniumUtil.click_on(driver, By.id("xf-4$xf-20$imageSrcTest-imageButton")); // Check popup dialog appears popup = driver.findElement(By.id("cstudio-wcm-popup-div_c")); assertTrue(popup.isDisplayed()); input = driver.findElement(By.xpath("/html/body/div[3]/div/div[2]/div/div/div/form/input")); input.sendKeys(f2.getAbsolutePath()); upload = driver.findElement(By.xpath("/html/body/div[3]/div/div[2]/div/div/div/form/input[2]")); upload.click(); new WebDriverWait(driver, CStudioSeleniumUtil.SHORT_TIMEOUT) .until( new ExpectedCondition<Boolean>() { public Boolean apply(WebDriver d) { WebElement e = d.findElement(By.id("xf-4$xf-20$imageSrcTest$xf-237-filename")); return e != null && e.getText().equals("/static-assets/images/image_picker_2.png"); } }); // Delete uploaded image CStudioSeleniumUtil.click_on(driver, By.id("xf-4$xf-20$imageSrcTest-deleteButton")); filename = driver.findElement(By.id("xf-4$xf-20$imageSrcTest$xf-237-filename")); assertTrue(filename.getText().equals("")); // Close driver CStudioSeleniumUtil.exit(driver); }