List of usage examples for org.openqa.selenium.support.ui ExpectedConditions presenceOfElementLocated
public static ExpectedCondition<WebElement> presenceOfElementLocated(final By locator)
From source file:com.htmlhifive.pitalium.it.assertion.exclude.CompareWithExcludesTest.java
License:Apache License
/** * ???????????exclude?<br>/* w w w . j a va 2 s.c om*/ * ??????<br> * IE711/FireFox/Chrome/Android 2.3, 4.0, 4.4, 5.1/iOS 8.1, 8.3<br> * ???? */ @Test public void excludeForBodyWithoutScroll() { String platformName = capabilities.getPlatformName(); if (!"ios".equalsIgnoreCase(platformName) && !"android".equalsIgnoreCase(platformName)) { driver.manage().window().setSize(new Dimension(1280, 2500)); } driver.get(URL_TOP_PAGE); PtlWebDriverWait wait = new PtlWebDriverWait(driver, 30); wait.untilLoad(); if (PtlTestConfig.getInstance().getEnvironment().getExecMode() == ExecMode.RUN_TEST) { wait.until(ExpectedConditions.presenceOfElementLocated(By.className("fb-like-box"))); driver.executeJavaScript( "document.getElementsByClassName('fb-like-box')[0].style.backgroundColor='red'"); } CompareTarget[] targets = { new CompareTarget(ScreenArea.of(SelectorType.TAG_NAME, "body"), EXCLUDES, true) }; assertionView.assertView("topPage", targets, HIDDEN_ELEMENTS); }
From source file:com.htmlhifive.pitalium.sample.PtlSampleTest.java
License:Apache License
@Test public void testCaptureTop() throws Exception { driver.get(""); ScreenshotArgument arg = ScreenshotArgument.builder("sampleCapture") // /*from w w w . java 2 s . com*/ .addNewTarget().addExclude(SelectorType.CLASS_NAME, "fb-like-box") .addNewTarget(SelectorType.ID, "about").build(); driver.executeScript("document.getElementById('about').style.marginTop='20px';"); // ??hifive??facebook? Wait<WebDriver> wait = new WebDriverWait(driver, 30); wait.until(ExpectedConditions .presenceOfElementLocated(By.cssSelector("iframe[title=\"fb:like_box Facebook Social Plugin\"]"))); // ?? assertionView.assertView(arg); }
From source file:com.jase.knife.BrowserEmulator.java
License:Apache License
/** * Wait for an element within a certain amount of time * @param xpath//from w w w. j a v a 2 s. co m * the element's xpath * the second */ public void waitElement(String xpath, int second) { new WebDriverWait(browser, second).until(ExpectedConditions.presenceOfElementLocated(By.xpath(xpath))); }
From source file:com.java.AppTestType_18_11_2015.java
public void ADDTOWATCHLIST(WebDriver driver, String fieldText) { String fieldType = fieldText; String field = fieldText;/*from w w w . jav a 2 s. c o m*/ try { AppKeyWords cdf = AppKeyWords.valueOf(fieldType.toUpperCase()); switch (cdf) { case FROMSEARCH: try { driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS); WebDriverWait wait = new WebDriverWait(driver, 25); //navigation to next page driver.findElement(By.linkText("2")).click(); //Thread.sleep(5000) wait.until(ExpectedConditions .presenceOfElementLocated(By.xpath("(//*[@class='e1tooltip icon_watchlist'])[1]"))); //clicking on first binocular icon which is not yet watching ListingID = driver.findElement(By.xpath( "(//*[@class='e1tooltip icon_watchlist']/../following::div[@class='rgbold jsLotID myone-black'])[2]")) .getText(); System.out.println(ListingID); driver.findElement(By.xpath("(//*[@class='e1tooltip icon_watchlist'])[1]")).click(); Thread.sleep(1000); resultDetails.setFlag(true); } catch (Exception e) { resultDetails.setFlag(false); } break; case FROMLISTING: try { driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS); driver.findElement(By.linkText("2")).click();//To go to 2nd page of the search results driver.findElement(By.xpath("(//*[@class='e1tooltip icon_watchlist']/../../a[1])[1]")).click(); ; //ListingID = driver.findElement(By.xpath("//*[contains(text(),'Lot ID:')]/span")).getText(); ListingID = driver.findElement(By.xpath("//*[@class='e2lot-result rgbold jsLotID']")).getText(); System.out.println(ListingID); driver.findElement(By.linkText("Watch This")).click(); System.out.println("clicked on watch this"); System.out.println(driver.findElement(By.xpath("//*[@class='e1WatchingThisText']")).getText()); if (driver.findElement(By.xpath("//*[@class='e1WatchingThisText']")).getText() .equalsIgnoreCase("Watching")) { System.out.println("Added to watchlist"); resultDetails.setFlag(true); } else { resultDetails.setFlag(false); System.out.println("listing is not added to watchlist1"); } System.out.println("going out of ADDTOWATCHLIST method"); } catch (Exception e) { resultDetails.setFlag(false); e.printStackTrace(); } break; case FROMEVENTPAGE: try { driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS); List<WebElement> events = driver .findElements(By.xpath("//a[@class='jsTitle' and contains(@href,'/event?eventid')]")); System.out.println("event size is: " + events.size()); Random r = new Random(); /*int randomValue = r.nextInt(listings.size()); //Getting a random value that is between 0 and (list's size)-1 */ WebDriverWait wait = new WebDriverWait(driver, 20); //selecting random event and trying to bid on first listing, if the event doesn't have open listings it will try with next event for (int i = 0; i < events.size(); i++) { events.get(r.nextInt(events.size())).click(); Thread.sleep(8000); if (driver.findElement(By.xpath("(//*[@class='e1tooltip icon_watchlist'])[1]")) .isDisplayed()) { //clicking on first binocular icon which is not yet watching ListingID = driver.findElement(By.xpath( "(//*[@class='e1tooltip icon_watchlist']/../following::div[@class='rgbold jsLotID myone-black'])[2]")) .getText(); System.out.println(ListingID); driver.findElement(By.xpath("(//*[@class='e1tooltip icon_watchlist'])[1]")).click(); Thread.sleep(1000); resultDetails.setFlag(true); break; } //go back to event page else driver.navigate().back(); } } catch (Exception e) { resultDetails.setFlag(false); e.printStackTrace(); } break; } } catch (Exception e) { e.printStackTrace(); System.out.println("listing is not added to watchlist2"); resultDetails.setFlag(false); } }
From source file:com.java.AppTestType_18_11_2015.java
public void EXACTBIDFROMWATCHINGPAGE(WebDriver driver) { try {/* ww w.ja v a 2s.co m*/ driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS); driver.navigate().to("http://e1.dev.assetnation.com/all-equipment/equipmentone-listings"); WebDriverWait wait = new WebDriverWait(driver, 25); Thread.sleep(1000); //navigation to next page driver.findElement(By.linkText("2")).click(); //Thread.sleep(5000) wait.until(ExpectedConditions .presenceOfElementLocated(By.xpath("(//*[@class='e1tooltip icon_watchlist'])[1]"))); //clicking on first binocular icon which is not yet watching driver.findElement(By.xpath("(//*[@class='e1tooltip icon_watchlist'])[1]")).click(); //Thread.sleep(5000); wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("(//a[text()='MyONE '])[2]"))); driver.findElement(By.xpath("(//a[text()='MyONE '])[2]")).click(); //Thread.sleep(5000); wait.until(ExpectedConditions.presenceOfElementLocated(By.partialLinkText("Watching"))); driver.findElement(By.partialLinkText("Watching")).click(); if (wait.until(ExpectedConditions .presenceOfElementLocated(By.xpath("(//*[contains(@value,'PLACE A BID')])[2]"))) .isDisplayed()) { driver.findElement(By.xpath("(//*[@type='radio' and @value='Exact Bid'])[2]")).click(); Thread.sleep(4000); driver.findElement(By.xpath("(//*[contains(@value,'PLACE A BID')])[2]")).click(); BIDDING_IN_LISTINGDETAILSPAGE(driver); resultDetails.setFlag(true); } else { System.out.println("there is no place a bid button in watchlist section"); } } catch (Exception e) { e.printStackTrace(); resultDetails.setErrorMessage("Listing is not available or Closed"); resultDetails.setFlag(false); } }
From source file:com.java.AppTestType_18_11_2015.java
public void MAXBIDFROMWATCHINGPAGE(WebDriver driver) { try {/*from ww w .ja va 2 s. c o m*/ driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS); driver.navigate().to("http://e1.dev.assetnation.com/all-equipment/equipmentone-listings"); WebDriverWait wait = new WebDriverWait(driver, 25); Thread.sleep(1000); //navigation to next page driver.findElement(By.linkText("2")).click(); //Thread.sleep(5000) wait.until(ExpectedConditions .presenceOfElementLocated(By.xpath("(//*[@class='e1tooltip icon_watchlist'])[1]"))); //clicking on first binocular icon which is not yet watching driver.findElement(By.xpath("(//*[@class='e1tooltip icon_watchlist'])[1]")).click(); //Thread.sleep(5000); wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("(//a[text()='MyONE '])[2]"))); driver.findElement(By.xpath("(//a[text()='MyONE '])[2]")).click(); //Thread.sleep(5000); wait.until(ExpectedConditions.presenceOfElementLocated(By.partialLinkText("Watching"))); driver.findElement(By.partialLinkText("Watching")).click(); if (wait.until(ExpectedConditions .presenceOfElementLocated(By.xpath("(//*[contains(@value,'PLACE A BID')])[2]"))) .isDisplayed()) { driver.findElement(By.xpath("(//*[contains(@value,'PLACE A BID')])[2]")).click(); BIDDING_IN_LISTINGDETAILSPAGE(driver); resultDetails.setFlag(true); } else { System.out.println("there is no 'place a bid button' in watchlist section"); } } catch (Exception e) { e.printStackTrace(); resultDetails.setErrorMessage("Listing is not available or Closed"); resultDetails.setFlag(false); } }
From source file:com.java.AppTestType_18_11_2015.java
public void BIDAMOUNTCALCULATION(WebDriver driver, String fieldText) { try {//from w ww.j a v a2 s . c o m driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS); WebDriverWait wait = new WebDriverWait(driver, 25); String page = fieldText; switch (page) { case "LOTPAGE": if (wait.until(ExpectedConditions .presenceOfElementLocated(By.xpath("(//*[contains(@value,'PLACE A BID')])[2]"))) .isDisplayed()) { driver.findElement(By.xpath("(//*[contains(@value,'PLACE A BID')])[2]")).click(); driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS); String offer_withdollar = driver .findElement(By.xpath("(//span[@class='jsMinOffer jsAmountText'])[2]")).getText(); String offer1 = offer_withdollar.replace("$", ""); String offer = offer1.substring(0, offer1.length() - 3).replace(",", ""); Integer a = Integer.parseInt(offer); System.out.println("you need to enter: " + offer); driver.findElement(By.xpath("(//input[@class='form-control jsOfferInput e1ConfirmInput'])[2]")) .sendKeys(offer); driver.findElement(By.xpath("(//input[@class='btn btn-primary jsConfirmOffer'])[2]")).click(); //CHECKING CALCULATION PART Thread.sleep(4000); String total_amount = driver .findElement(By.xpath( "(//*[@class='col-sm-12 col-xs-12 text-right myone-green jsBidTotal'])[2]")) .getText(); Integer total_amount2 = Integer .parseInt(total_amount.substring(1, total_amount.length() - 3).replace(",", "")); int t1 = (int) (a + a * 0.1); int t2 = (int) total_amount2; System.out.println("Expected total amount including buyer premium is: " + t1); System.out.println("Actual amount is: " + t2); if (t1 == t2) { resultDetails.setFlag(true); } } else { System.out.println("there is no 'place a bid button"); } break; case "LOTDETAILSPAGE": if (wait.until(ExpectedConditions .presenceOfElementLocated(By.xpath("(//*[contains(text(),'Place Bid')])"))).isDisplayed()) { driver.findElement(By.xpath("(//*[contains(text(),'Place Bid')])")).click(); driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS); String offer_withdollar = driver.findElement(By.xpath("(//span[@class='jsMinOffer'])")) .getText(); String offer1 = offer_withdollar.replace("$", ""); String offer = offer1.substring(0, offer1.length() - 3).replace(",", ""); Integer a = Integer.parseInt(offer); System.out.println("you need to enter: " + offer); driver.findElement(By.xpath("(//input[@class='jsOfferInput e1ConfirmInput'])[1]")) .sendKeys(offer); driver.findElement(By.xpath("(//button[@class='e1Buttons jsConfirmOffer e1OrangeShadow'])[1]")) .click(); //CHECKING CALCULATION PART Thread.sleep(4000); String total_amount = driver.findElement(By.xpath("(//*[@class='jsBidTotal'])[1]")).getText(); Integer total_amount2 = Integer .parseInt(total_amount.substring(1, total_amount.length() - 3).replace(",", "")); int t1 = (int) (a + a * 0.1); int t2 = (int) total_amount2; System.out.println("Expected total amount including buyer premium is: " + t1); System.out.println("Actual amount is: " + t2); if (t1 == t2) { resultDetails.setFlag(true); } } else { System.out.println("there is no 'place a bid button"); } break; } } catch (Exception e) { e.printStackTrace(); resultDetails.setErrorMessage("Listing is not available or Closed"); resultDetails.setFlag(false); } }
From source file:com.java.AppTestType_18_11_2015.java
public void SEARCHLOTINEQWITHEQID(WebDriver driver, String pagename) { driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS); try {/*w ww.j a v a2 s .co m*/ Thread.sleep(5000); if (pagename.equalsIgnoreCase("LotDetailsPage")) eqid_1 = driver.findElement(By.xpath("//*[contains(text(),'Lot ID:')]/span")).getText(); else if (pagename.equalsIgnoreCase("SEARCHRESULTPAGE")) eqid_1 = driver.findElement(By.xpath("(//div[@class='rgbold jsLotID myone-black'])[4]")).getText(); else if (pagename.equalsIgnoreCase("HOMEPAGE")) { eqid_1 = driver.findElement(By.xpath("(//div[@class='rgbold jsLotID myone-black'])[4]")).getText(); //moving to home page driver.findElement(By.xpath("//a/img[@class='logo-img img-responsive']")).click(); } else if (pagename.equalsIgnoreCase("MYONEPAGE")) { eqid_1 = driver.findElement(By.xpath("(//div[@class='rgbold jsLotID myone-black'])[4]")).getText(); //moving to home page driver.findElement(By.xpath("(//a[contains(text(),'MyONE')])[2]")).click(); } Thread.sleep(5000); //searching with above lot id driver.findElement(By.id("search")).sendKeys(eqid_1); driver.findElement(By.xpath("//*[@id='main_search']/button")).click(); WebDriverWait wait = new WebDriverWait(driver, 30); wait.until(ExpectedConditions.presenceOfElementLocated( By.xpath("(//div[@class='search-tags']/ul/li[text()='" + eqid_1 + "'])[2]"))); String actual_eqid = driver.findElement(By.xpath("(//div[@class='rgbold jsLotID myone-black'])[4]")) .getText(); //checking the size of search result elements, first 2 are invisible elements and each lot is having 2 more elements, so size should not exceed 4 int size = driver.findElements(By.xpath("(//div[@class='rgbold jsLotID myone-black'])")).size(); System.out.println("suman999999999999999999999999999999999999999999999999: " + size); if (size == 4 && actual_eqid.equalsIgnoreCase(eqid_1)) resultDetails.setFlag(true); } catch (Exception e) { System.out.println(e); resultDetails.setFlag(false); } }
From source file:com.liferay.faces.test.AlloyApplicantPortletTest.java
License:Open Source License
@Test @RunAsClient/*from ww w . ja v a2s.c o m*/ @InSequence(3000) public void preferencesAndEditMode() throws Exception { // test for both int dateLengthAfterChange = 8; int dateLengthAfterReset = 10; logger.log(Level.INFO, "preferencesMenuButton.click() ... "); selectEditMode(browser, portal); logger.log(Level.INFO, "Waiting for datePatternField to show on the page ... "); try { WebDriverWait wait = new WebDriverWait(browser, 10); wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(datePatternFieldXpath))); } catch (Exception e) { logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage()); assertTrue("datePatternField should be visible after selecting edit mode," + " but " + datePatternFieldXpath + " is not visible.", false); } logger.log(Level.INFO, "done with selectEditMode: isThere(browser, datePatternFieldXpath) = " + isThere(browser, datePatternFieldXpath)); logger.log(Level.INFO, "datePatternField.getAttribute('value') = " + datePatternField.getAttribute("value")); logger.log(Level.INFO, "resetButton.isDisplayed() = " + resetButton.isDisplayed()); // MM/dd/yyyy datePatternField.clear(); datePatternField.sendKeys("MM/dd/yy"); preferencesSubmitButton.click(); // after clicking the preferencesSubmitButton, all of the job applicant demos need to end up on the same // page. Here is a log statement that should give you a clue between the different testers as to which ones are // different from others logger.log(Level.INFO, "browser.getCurrentUrl() = " + browser.getCurrentUrl()); logger.log(Level.INFO, "browser.navigate().to(" + url + ")"); browser.navigate().to(url); try { WebDriverWait wait = new WebDriverWait(browser, 10); wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(dateOfBirthFieldXpath))); } catch (Exception e) { logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage()); assertTrue("dateOfBirthField should be visible after navigating to " + url + "," + " but " + dateOfBirthFieldXpath + " is not visible.", false); } logger.log(Level.INFO, "dateOfBirthField.getAttribute('value') = " + dateOfBirthField.getAttribute("value")); logger.log(Level.INFO, "dateOfBirthField.getAttribute('value').length() = " + dateOfBirthField.getAttribute("value").length()); assertTrue( "dateOfBirthField should have " + dateLengthAfterChange + " characters after changing preferences to MM/dd/yy, but " + dateOfBirthField.getAttribute("value").length() + " != " + dateLengthAfterChange, dateOfBirthField.getAttribute("value").length() == dateLengthAfterChange); if (isThere(browser, editPreferencesButtonXpath)) { logger.log(Level.INFO, "editPreferencesButton.click() ..."); editPreferencesButton.click(); } else { logger.log(Level.INFO, "NO editPreferencesButton isThere, so preferencesMenuItem.click() ..."); selectEditMode(browser, portal); } logger.log(Level.INFO, "Waiting for the resetButton to show on the page ..."); try { WebDriverWait wait = new WebDriverWait(browser, 10); wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(resetButtonXpath))); } catch (Exception e) { logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage()); assertTrue("resetButton should be visible after selecting edit mode," + " but " + resetButtonXpath + " is not visible.", false); } logger.log(Level.INFO, "done with selectEditMode: isThere(browser, resetButtonXpath) = " + isThere(browser, resetButtonXpath)); logger.log(Level.INFO, "browser.getCurrentUrl() = " + browser.getCurrentUrl()); logger.log(Level.INFO, "resetButton.click() ..."); resetButton.click(); // after clicking the resetButton all of the job applicant demos need to end up on the same page Here is a // log statement that should give you a clue between the different testers as to which ones are different from // others logger.log(Level.INFO, "browser.getCurrentUrl() = " + browser.getCurrentUrl()); logger.log(Level.INFO, "browser.navigate().to(" + url + ")"); browser.navigate().to(url); logger.log(Level.INFO, "Waiting for the dateOfBirthField to show on the page ..."); try { WebDriverWait wait = new WebDriverWait(browser, 10); wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(dateOfBirthFieldXpath))); } catch (Exception e) { logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage()); assertTrue("dateOfBirthField should be visible after navigating back to view mode," + " but " + dateOfBirthFieldXpath + " is not visible.", false); } logger.log(Level.INFO, "dateOfBirthField.getAttribute('value') = " + dateOfBirthField.getAttribute("value")); logger.log(Level.INFO, "dateOfBirthField.getAttribute('value').length() = " + dateOfBirthField.getAttribute("value").length()); assertTrue("date of birth has " + dateLengthAfterReset + " characters after resetting preferences", dateOfBirthField.getAttribute("value").length() == dateLengthAfterReset); }
From source file:com.liferay.faces.test.AlloyApplicantPortletTest.java
License:Open Source License
@Test @RunAsClient// w w w .j a v a2 s . c o m @InSequence(4000) public void reset() throws Exception { // because some test failures throw us into a strange state, // let's reset preferences and the page we are on logger.log(Level.INFO, "browser.navigate().to(" + url + ")"); browser.navigate().to(url); logger.log(Level.INFO, "browser.getTitle() = " + browser.getTitle()); logger.log(Level.INFO, "browser.getCurrentUrl() = " + browser.getCurrentUrl()); logger.log(Level.INFO, "isThere(browser, dateOfBirthFieldXpath) = " + isThere(browser, dateOfBirthFieldXpath)); logger.log(Level.INFO, "Waiting for the dateOfBirthField to show on the page ..."); try { WebDriverWait wait = new WebDriverWait(browser, 10); wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(dateOfBirthFieldXpath))); } catch (Exception e) { logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage()); refreshBrowser(); assertTrue("dateOfBirthField should have been visible after navigating back to view mode," + " but " + dateOfBirthFieldXpath + " was not visible.", false); } selectEditMode(browser, portal); logger.log(Level.INFO, "Waiting for the resetButton to show on the page ..."); try { WebDriverWait wait = new WebDriverWait(browser, 10); wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(resetButtonXpath))); } catch (Exception e) { logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage()); assertTrue("resetButton should be visible after selecting edit mode," + " but " + resetButtonXpath + " is not visible.", false); } logger.log(Level.INFO, "browser.getTitle() = " + browser.getTitle()); logger.log(Level.INFO, "browser.getCurrentUrl() = " + browser.getCurrentUrl()); logger.log(Level.INFO, "resetButton.click() ..."); resetButton.click(); logger.log(Level.INFO, "Waiting for the firstNameField to show on the page ..."); try { WebDriverWait wait = new WebDriverWait(browser, 10); wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(firstNameFieldXpath))); } catch (Exception e) { logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage()); refreshBrowser(); assertTrue("firstNameField should have been visible after clicking the reset button," + " but " + firstNameFieldXpath + " was not visible.", false); } }