@Step("Log out")
 public void logOut() {
   wait.until(ExpectedConditions.elementToBeClickable(productPage.logoutButton));
   productPage.logoutButton.click();
   wait.until(ExpectedConditions.visibilityOf(authPage.email));
   makeScreenshot("The user should be logged out");
 }
예제 #2
0
  @Test
  public void testLogin() {
    driver.get(appUrl + "/#/login");

    WebDriverWait wait = new WebDriverWait(driver, 10);

    WebElement user =
        wait.until(
            ExpectedConditions.presenceOfElementLocated(By.cssSelector("input[type=\"text\"]")));
    user.sendKeys("demo");

    WebElement password =
        wait.until(
            ExpectedConditions.presenceOfElementLocated(
                By.cssSelector("input[type=\"password\"]")));
    password.sendKeys("demo");

    WebElement submit =
        wait.until(
            ExpectedConditions.presenceOfElementLocated(By.cssSelector("button[type=\"submit\"]")));
    submit.submit();

    boolean found =
        wait.until(
            ExpectedConditions.textToBePresentInElement(By.cssSelector("td"), "Assign Approver"));
  }
예제 #3
0
  @Test(timeOut = 20000)
  public void SearchingResultPosts() {
    // Validating Search No Results
    HomePage homePage = PageFactory.initElements(driver, HomePage.class);
    homePage.go(driver);
    homePage.search("not found");
    Assert.assertTrue(
        driver.findElement(By.xpath("//article[@id='post-0']/header/h1")).isDisplayed(),
        "Nothing Found");
    Assert.assertEquals("not found | Search Results | Automation Training", driver.getTitle());

    // Validating post results with the word "test"
    homePage.go(driver);
    homePage.waitForTitle();
    homePage.search("test");

    WebDriverWait waitForOne = new WebDriverWait(driver, 10);
    waitForOne.until(
        ExpectedConditions.presenceOfElementLocated(By.xpath("//h1[@id='site-title']/span/a")));
    waitForOne.until(
        ExpectedConditions.presenceOfElementLocated(
            By.xpath("//article[@id='post-39']/header/h1/a")));
    waitForOne.until(
        ExpectedConditions.presenceOfElementLocated(By.linkText("What software testing is")));

    driver.findElement(By.className("page-title")).isDisplayed();

    Assert.assertTrue(
        driver.findElement(By.xpath("//header/h1/span")).isDisplayed(), "SEARCH RESULTS FOR: TEST");

    waitForOne.until(ExpectedConditions.titleContains("test"));

    assert (driver.getTitle().contains(("test | Search Results | Automation Training")));
  }
 public void addFeedbackResponseComment(String addResponseCommentId, String commentText) {
   WebDriverWait wait = new WebDriverWait(browser.driver, 5);
   WebElement addResponseCommentForm = browser.driver.findElement(By.id(addResponseCommentId));
   WebElement parentContainer = addResponseCommentForm.findElement(By.xpath("../.."));
   WebElement showResponseCommentAddFormButton =
       parentContainer.findElement(By.id("button_add_comment"));
   showResponseCommentAddFormButton.click();
   wait.until(
       ExpectedConditions.elementToBeClickable(
           addResponseCommentForm.findElement(By.tagName("textarea"))));
   fillTextBox(addResponseCommentForm.findElement(By.tagName("textarea")), commentText);
   addResponseCommentForm
       .findElement(By.className("col-sm-offset-5"))
       .findElement(By.tagName("a"))
       .click();
   if (commentText.equals("")) {
     // empty comment: wait until the textarea is clickable again
     wait.until(
         ExpectedConditions.elementToBeClickable(
             addResponseCommentForm.findElement(By.tagName("textarea"))));
   } else {
     // non-empty comment: wait until the add comment form disappears
     waitForElementToDisappear(By.id(addResponseCommentId));
   }
 }
  @Test
  public void test() {
    // find a wish list
    wd.get(baseURL);
    wd.findElementByXPath(".//*[@id='term']").sendKeys("*****@*****.**");
    wd.findElementByXPath(".//*[@id='wish_list']/div[3]/div/form/fieldset[2]/input").click();

    wd.findElementByXPath(("//input[starts-with(@id,'safe_place_for_courier')]"))
        .sendKeys("home"); // use when there are dynamic elements on the page
    wd.findElementByXPath("//*[@id='add_to_cart']").click();

    WebElement checkoutmodal =
        wait.until(
            ExpectedConditions.visibilityOfElementLocated(
                By.xpath("//*[@id='shopping_buttons']/a[2]")));
    checkoutmodal.click();

    // proceed to checkout
    wd.findElementByXPath(".//*[@id='edit_cart']/section[2]/div/div[2]/span/button").click();

    // welcome page
    WebElement signinemail = wd.findElementByXPath("//*[@id='email']");
    if (signinemail.isEnabled()) signinemail.sendKeys("*****@*****.**");

    WebElement signinpassword = wd.findElementByXPath("//*[@id='password']");
    if (signinpassword.isEnabled()) signinpassword.sendKeys("logmein1");
    wd.findElementById("button_existing_customer").click();

    // Delivery
    wd.findElementById("button_continue").click();

    // Payment flow choice (QA only)
    wd.findElementByXPath(".//*[@id='content']/form/input").click();

    // Payment page
    wd.findElementByXPath(".//*[@id='payment_medium_payment_form_credit_card']").click();

    // Payment form

    wait.until(
        ExpectedConditions.visibilityOfElementLocated(
            By.id("checkout_credit_card_attributes_type")));
    new Select(wd.findElementById("checkout_credit_card_attributes_type"))
        .selectByVisibleText("Visa Debit or Electron");

    wd.findElementById("checkout_credit_card_attributes_number").sendKeys("4263971921001307");
    wd.findElementById("checkout_credit_card_attributes_name").sendKeys("Hans Peter Luhn");
    new Select(wd.findElementById("checkout_credit_card_attributes_expiry_month"))
        .selectByVisibleText("6");
    new Select(wd.findElementById("checkout_credit_card_attributes_expiry_year"))
        .selectByVisibleText("2018");
    wd.findElementById("checkout_credit_card_attributes_verification_value").sendKeys("737");

    // Skip 3DS
    wd.findElementById("checkout_skip_3d_secure").click();

    wd.findElementByXPath("//*[@id='process_payment_button']").click();

    wd.close();
  }
예제 #6
0
  public void selectDropDownValue(By locator, String text) {

    WebDriverWait wait = new WebDriverWait(driver, 10);
    webElement = wait.until(ExpectedConditions.visibilityOfElementLocated(locator));
    webElement = wait.until(ExpectedConditions.elementToBeClickable(locator));
    new Select(webElement).selectByVisibleText(text);
  }
 public void verifyCommentRowContent(
     String commentRowIdSuffix, String commentText, String giverName) {
   WebDriverWait wait = new WebDriverWait(browser.driver, 30);
   WebElement commentRow;
   try {
     commentRow =
         wait.until(
             ExpectedConditions.presenceOfElementLocated(
                 By.id("responseCommentRow" + commentRowIdSuffix)));
   } catch (TimeoutException e) {
     fail("Timeout!");
     commentRow = null;
   }
   try {
     wait.until(
         ExpectedConditions.textToBePresentInElement(
             commentRow.findElement(By.id("plainCommentText" + commentRowIdSuffix)), commentText));
   } catch (TimeoutException e) {
     fail("Not expected message");
   }
   try {
     assertTrue(commentRow.findElement(By.className("text-muted")).getText().contains(giverName));
   } catch (AssertionError e) {
     assertTrue(commentRow.findElement(By.className("text-muted")).getText().contains("you"));
   }
 }
  public static void fillShippingInformation(List<List<String>> shippingInfo) {
    if (!SeleniumController.Instance.Driver().findElement(By.id("address-list")).isDisplayed()) {
      for (int i = 0; i < shippingInfo.size(); i++) {
        SeleniumController.Instance.Driver()
            .findElement(By.id("addressFields"))
            .findElement(By.className(shippingInfo.get(i).get(0)))
            .sendKeys(shippingInfo.get(i).get(1));
        if (shippingInfo.get(i).get(0).equals("country")) {
          SeleniumController.Instance.Driver()
              .findElement(By.id("addressFields"))
              .findElement(By.className(shippingInfo.get(i).get(0)))
              .sendKeys(Keys.ENTER);
          if (shippingInfo.get(i).get(1).contains("United States")) {
            wait.until(
                ExpectedConditions.textToBePresentInElement(
                    SeleniumController.Instance.Driver()
                        .findElement(By.className("shipMethods"))
                        .findElement(By.id("shipMethods")),
                    "U.S."));

          } else
            wait.until(
                ExpectedConditions.textToBePresentInElement(
                    SeleniumController.Instance.Driver()
                        .findElement(By.className("shipMethods"))
                        .findElement(By.id("shipMethods"))
                        .findElement(By.className("shipDescription")),
                    "International"));
        }
      }
    }
  }
  @Test
  public void workWithTheIFrame() {
    driver.get("http://www.compendiumdev.co.uk/selenium/frames");
    WebDriverWait wait = new WebDriverWait(driver, Driver.DEFAULT_TIMEOUT_SECONDS);

    assertThat(driver.getTitle(), is("Frameset Example Title (Example 6)"));

    // click on "menu"."iFrames Example"
    driver.switchTo().frame("menu");
    driver.findElement(By.cssSelector("a[href='iframe.html']")).click();

    wait.until(titleIs("HTML Frames Example - iFrame Contents"));

    // click on Example 5 in the iFrame
    driver.switchTo().frame(0);
    driver.findElement(By.cssSelector("a[href='frames_example_5.html']")).click();

    wait.until(titleIs("Frameset Example Title (Example 5)"));

    // then content.load main frames page
    driver.switchTo().frame("content");
    driver.findElement(By.cssSelector("a[href='index.html']")).click();

    wait.until(titleIs("Frameset Example Title (Example 6)"));
  }
  public Page login(String userName, String password, LoginTo loginTo)
      throws IOException, InterruptedException {
    log.info("login as " + userName);

    // Wait until login page loading is completed.
    WebDriverWait wait = new WebDriverWait(driver, 30);

    wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("username")));
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("password")));

    wait.until(
        ExpectedConditions.visibilityOfElementLocated(
            new ByAll(By.className("btn-primary"), By.tagName("input"))));

    driver.findElement(By.id("username")).sendKeys(userName);
    driver.findElement(By.id("password")).sendKeys(password);

    driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);

    driver.findElement(By.className("btn-primary")).click();

    if (loginTo == LoginTo.PUBLISHER) {
      return PublisherWebAppsListPage.getPage(driver, appMServer);
    } else {
      return StoreHomePage.getPage(driver, appMServer);
    }
  }
 public void cancelAmendOrderFromDashboard() {
   wait.until(ExpectedConditions.elementToBeClickable(driver.findElement(cancelAmend)));
   driver.findElement(cancelAmend).click();
   wait.until(
       ExpectedConditions.elementToBeClickable(
           driver.findElement(By.name("Do you want to cancel changes to this order?"))));
   driver.switchTo().alert().accept(); /*Accept the alert message*/
 }
예제 #12
0
  public static void main(String[] args) throws Exception {

    // Step1
    WebDriver wd = new FirefoxDriver(); // we have created an object wd
    WebDriverWait wait = new WebDriverWait(wd, 60);

    // Step2
    wd.get("http://www.orbitz.com");

    // Step3
    wd.findElement(By.xpath("//input[@name='search.type']")).click();
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.name("ar.rt.leaveSlice.orig.key")));

    /*
     * Wait will ignore instances of NotFoundException that are encountered (thrown) by default in the 'until'
     * condition, and immediately propagate all others.
     */

    // Step4
    wd.findElement(By.name("ar.rt.leaveSlice.orig.key")).clear();

    // Step5
    wd.findElement(By.name("ar.rt.leaveSlice.orig.key")).sendKeys("DFW");

    // Step6
    wd.findElement(By.name("ar.rt.leaveSlice.dest.key")).clear();

    // Step7
    wd.findElement(By.name("ar.rt.leaveSlice.dest.key")).sendKeys("SFO");

    // Step8
    wd.findElement(By.name("ar.rt.leaveSlice.date")).clear();

    // Step9
    wd.findElement(By.name("ar.rt.leaveSlice.date")).sendKeys("11/19/15");

    // Step10
    wd.findElement(By.name("ar.rt.returnSlice.date")).clear();

    // Step11
    wd.findElement(By.name("ar.rt.returnSlice.date")).sendKeys("11/20/15");

    // Step12
    wd.findElement(By.name("search")).click();
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("sortResultsSelect")));

    // Step13
    String price =
        wd.findElement(By.xpath(".//*[@id='matrix']/div[1]/div/div/span"))
            .getText()
            .replace("$", "");
    System.out.println("The lowest price is: " + price);

    wd.close();
  }
예제 #13
0
파일: CashPage.java 프로젝트: CTAJlb/VaBank
  public void checkCashWindowUrl(String paySystem, String expURL, String waitLocator) {
    String mwh = Driver.get().getWindowHandle();
    waitSleep(5000);

    //        payCreditCardBtn.click();

    switch (paySystem) {
      case "credCards":
        wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(bankCardsErrMsgXPATH)));
        System.out.println(Driver.get().findElement(By.xpath(bankCardsErrMsgXPATH)).getText());
        Assert.assertEquals(
            Driver.get().findElement(By.xpath(bankCardsErrMsgXPATH)).getText(),
            "Произошла системная ошибка. Служба поддержки: [email protected] +44 208 123 5605");
        break;
      case "sms":
        wait.until(
            ExpectedConditions.visibilityOfElementLocated(
                By.xpath("//div[@class='payment_message sms_sent']")));
        System.out.println(Driver.get().findElement(By.xpath(smsInstructorXPATH)).getText());
        Assert.assertEquals(
            Driver.get().findElement(By.xpath(smsInstructorXPATH)).getText(),
            "На указанный вами номер отправлено SMS с инструкциями для совершения оплаты");
        break;

      default:
        Set s = Driver.get().getWindowHandles();
        // System.out.println(s);
        Iterator ite = s.iterator();

        while (ite.hasNext()) {
          String popupHandle = ite.next().toString();

          if (!popupHandle.contains(mwh)) {
            Driver.get().switchTo().window(popupHandle);
            // System.out.println(popupHandle);
          }
        }

        try {
          WebDriverWait wait1 = new WebDriverWait(Driver.get(), 90);
          wait1.until(
              ExpectedConditions.visibilityOf(Driver.get().findElement(By.xpath(waitLocator))));
          //
          // wait.until(ExpectedConditions.visibilityOf(Driver.get().findElement(By.xpath(waitLocator))));
          Assert.assertTrue(
              Driver.get().getCurrentUrl().contains(expURL),
              "URL Cash Pay System was not as expected");
        } finally {

          Driver.get().close();
          Driver.get().switchTo().window(mwh);
        }
    }
  }
  public static WebElement prospectList_AddProspectToList(
      WebDriver driver, String randomName, String emailID) throws Exception {

    WebDriverWait wait = new WebDriverWait(driver, 60);

    // Assumption - The newly created Prospect List is always on 1st Row
    wait.until(
        ExpectedConditions.textToBePresentInElementLocated(
            By.xpath(".//*[@id='prospect_row_a0']/td[3]/a"), emailID));
    Log.info(driver.findElement(By.xpath(".//*[@id='prospect_row_a0']/td[3]/a")).getText());
    Log.info(
        driver.findElement(By.xpath(".//*[@id='prospect_row_a0']/td[3]/a")).getAttribute("href"));

    String ProspectID =
        driver.findElement(By.xpath(".//*[@id='prospect_row_a0']/td[3]/a")).getAttribute("href");
    Log.info(ProspectID);

    int endIndex = ProspectID.lastIndexOf("/");
    int length =
        driver
            .findElement(By.xpath(".//*[@id='prospect_row_a0']/td[3]/a"))
            .getAttribute("href")
            .length();

    System.out.println("endIndex is " + endIndex);
    String ActProspectID = ProspectID.substring(endIndex + 1);
    System.out.println("ActProspectID is " + ActProspectID);

    if (endIndex != -1) {
      if (!(ActProspectID.contains("#"))) {
        // ProspectID = driver.getCurrentUrl().substring(endIndex+1, length);
        Log.info("Prospect id doesn't contain # " + ProspectID);
      }
    }

    driver.get("https://pi.pardot.com/list/prospect/prospect_id/" + ActProspectID);

    wait.until(
        ExpectedConditions.visibilityOfElementLocated(
            By.xpath("//span[contains(.,'Select a list to add...')]")));

    WebElement listDropDown =
        driver.findElement(By.xpath("//span[contains(.,'Select a list to add...')]"));
    listDropDown.click();

    driver.findElement(By.xpath("//li[text()='" + randomName + "']")).click();
    wait.until(
        ExpectedConditions.textToBePresentInElement(listDropDown, "Select a list to add..."));
    driver.findElement(By.xpath("//span[contains(.,'Select a list to add...')]")).submit();

    return element;
  }
  /** Find Element By Xpath */
  public void findElementByXpath(String objectLocators) {

    WebDriverWait wait = new WebDriverWait(WebDriverClass.getDriver(), 30);

    wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.xpath(objectLocators)));

    List<WebElement> list1 =
        wait.until(
            ExpectedConditions.visibilityOfAllElements(
                WebDriverClass.getDriver().findElements(By.xpath(objectLocators))));

    listOfElements = list1;
  }
예제 #16
0
 private void customiseImages(RemoteWebDriver driver) {
   driver.findElement(By.name("Choose an existing image")).click();
   WebDriverWait wait = new WebDriverWait(driver, 10);
   wait.until(ExpectedConditions.visibilityOfElementLocated(By.name("Albums")));
   driver.findElement(By.name("Saved Photos")).click();
   wait.until(ExpectedConditions.visibilityOfElementLocated(By.name("UIACollectionView")));
   driver
       .findElement(By.className("UIACollectionView"))
       .click(); // from Louis's  .FindElements(By.ClassName("UIACollectionCell"))[0]
                 // .ClickMiddleUsingCoordinates();
   wait.until(ExpectedConditions.elementToBeClickable(By.name("confirm edit icon")));
   driver.findElement(By.name("confirm edit icon")).click();
 }
 public void clickShowDataLink(String expectedID) throws InterruptedException {
   WebDriverWait wait = new WebDriverWait(getDriver(), 60);
   wait.until(ExpectedConditions.invisibilityOfElementLocated(By.id("loading-mask")));
   if (showDataink.isVisible()) {
     showDataink.click();
   } else {
     synchronized (getDriver()) {
       getDriver().wait(1000);
     }
     this.searchRequestByID(expectedID);
     wait.until(ExpectedConditions.invisibilityOfElementLocated(By.id("loading-mask")));
     showDataink.click();
   }
 }
 @Test(priority = 3)
 public void TestingPreOrderShoesDropDownBoxes() throws Exception {
   WebDriverWait myWait = new WebDriverWait(drv, 10);
   drv.manage().window().maximize();
   drv.get("http://manheim-shoe-store-test.herokuapp.com/");
   myWait.until(ExpectedConditions.visibilityOfElementLocated(By.id("brand")));
   myWait.until(ExpectedConditions.elementToBeClickable(By.id("brand")));
   Select chooseBrand = new Select(drv.findElement(By.id("brand")));
   chooseBrand.selectByValue("Acorn");
   drv.findElement(By.id("search_button")).click();
   myWait.until(
       ExpectedConditions.visibilityOfElementLocated(By.cssSelector("div[class=\"title\"]")));
   myWait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("div[class=\"title\"]")));
   Assert.assertTrue(drv.getPageSource().contains("Acorn's Shoes"));
 }
예제 #19
0
 /**
  * Wait until element is displayed.
  *
  * @param timeoutSec seconds to wait until element is displayed.
  * @param checkCondition log assert for expected conditions.
  * @return Parent instance
  */
 private ParentPanel waitForDisplayed(int timeoutSec, boolean checkCondition) {
   boolean isDisplayed;
   logAction(this, getParentClassName(), format("waitForDisplayed: %s", locator));
   long start = System.currentTimeMillis() / 1000;
   WebDriverWait wait =
       (WebDriverWait)
           new WebDriverWait(getDriver(), timeoutSec)
               .ignoring(StaleElementReferenceException.class);
   setTimeout(1);
   try {
     wait.until(ExpectedConditions.visibilityOfElementLocated(avatar.byLocator));
     isDisplayed = true;
   } catch (TimeoutException e) {
     logTechnical(
         format(
             "waitForDisplayed: [ %s ] during: [ %d ] sec ",
             locator, System.currentTimeMillis() / 1000 - start));
     isDisplayed = false;
   }
   setTimeout(TIMEOUT);
   if (checkCondition) {
     logAssertTrue(
         BUSINESS_LEVEL,
         isDisplayed,
         format("waitForDisplayed - '%s' should be displayed", getName()),
         takePassedScreenshot);
   }
   return parent;
 }
예제 #20
0
 /**
  * Check for is element present on the page.
  *
  * @return Is element present
  */
 public boolean isPresent(int timeout) {
   WebDriverWait wait = new WebDriverWait(Browser.getInstance().getWebDriver(), timeout);
   try {
     wait.until(
         (ExpectedCondition<Boolean>)
             new ExpectedCondition<Boolean>() {
               public Boolean apply(final WebDriver driver) {
                 try {
                   List<WebElement> list = driver.findElements(locator);
                   for (WebElement el : list) {
                     if (el instanceof WebElement && el.isDisplayed()) return el.isDisplayed();
                   }
                   element = driver.findElement(locator);
                 } catch (Exception e) {
                   return false;
                 }
                 return element.isDisplayed();
               }
             });
   } catch (Exception e) {
     warn(e.getMessage().substring(0, e.getMessage().indexOf("}")));
     return false;
   }
   try {
     browser
         .getWebDriver()
         .manage()
         .timeouts()
         .implicitlyWait(Integer.valueOf(browser.getImplicitlyWait()), TimeUnit.SECONDS);
     return element.isDisplayed();
   } catch (Exception e) {
     warn(e.getMessage().substring(0, e.getMessage().indexOf("waiting")));
   }
   return false;
 }
예제 #21
0
  public void Test1() {
    WebDriver dr = new FirefoxDriver();
    dr.manage().timeouts().pageLoadTimeout(15, TimeUnit.SECONDS);

    try {
      dr.get("http://www.w3schools.com/xsl/xsl_functions.asp");
    } catch (Exception e) {
      // ignore page load time out
      // e.printStackTrace();
    }
    System.out.println(dr.getCurrentUrl());
    WebDriverWait wait = new WebDriverWait(dr, 10);
    wait.until(
        ExpectedConditions.visibilityOfElementLocated(
            By.xpath("//h3[contains(.,'Accessor Functions')]")));
    System.out.println("page loaded");
    WebElement eTable =
        dr.findElement(
            By.xpath("//h3[contains(.,'Accessor Functions')]/following-sibling::table[1]"));

    Table tTable = new Table(eTable);

    System.out.println(tTable.getCellText(1, 1)); // row 1, column 1
    System.out.println(tTable.getCellText("fn,nilled", 1)); // row 2, column 1
    System.out.println(tTable.getCellText(1, "Name")); // row 1, column 1
    System.out.println(tTable.getCellText("fn,nilled", "Description")); // row 2, column 2

    dr.quit();
  }
 public static WebElement waitForElement(By by) {
   int count = 0;
   WebDriverWait wait = null;
   while (!(wait.until(ExpectedConditions.presenceOfElementLocated(by)).isDisplayed())) {
     wait = new WebDriverWait(WebDriverClass.getInstance(), 60);
     wait.pollingEvery(5, TimeUnit.MILLISECONDS);
     wait.until(ExpectedConditions.visibilityOfElementLocated(by)).isDisplayed();
     wait.until(ExpectedConditions.presenceOfElementLocated(by)).isDisplayed();
     count++;
     if (count == 100) {
       break;
     }
     return wait.until(ExpectedConditions.presenceOfElementLocated(by));
   }
   return wait.until(ExpectedConditions.presenceOfElementLocated(by));
 }
예제 #23
0
 @Override
 public void submit() {
   sumbitButton.click();
   // make sure the fancybox content is not loaded anymore
   WebDriverWait wait = new WebDriverWait(driver, AbstractTest.LOAD_TIMEOUT_SECONDS);
   wait.until(ExpectedConditions.invisibilityOfElementLocated(By.id("fancybox-content")));
 }
예제 #24
0
  @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"));
  }
예제 #25
0
  @Before
  public void setUp() throws Exception {
    DesiredCapabilities capabilities = DesiredCapabilities.iphone();
    capabilities.setCapability("build", "Parallel iOS Native App Test Suite");
    capabilities.setCapability("name", "Parallel iOS Native App Test Suite");
    capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, platformVersion);
    capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, deviceName);

    capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "iOS");
    capabilities.setCapability(MobileCapabilityType.APP, "sauce-storage:UICatalog.zip");
    capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, "");
    capabilities.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, 180);
    capabilities.setCapability(MobileCapabilityType.DEVICE_READY_TIMEOUT, 60);
    capabilities.setCapability("deviceOrientation", "portrait");
    capabilities.setCapability("appiumVersion", "1.4.16");
    capabilities.setCapability("sendKeyStrategy", "setValue"); // fastest typing method
    capabilities.setCapability(
        "noReset",
        true); // to reuse the simulator/installed app between tests, rather than restart sim

    driver =
        new IOSDriver(
            new URL(
                "http://" + SAUCE_USERNAME + ":" + SAUCE_KEY + "@ondemand.saucelabs.com:80/wd/hub"),
            capabilities);
    sessionId = (driver.getSessionId()).toString();
    wait = new WebDriverWait(driver, 15);

    // wait until main view loads
    wait.until(
        ExpectedConditions.visibilityOf(
            driver.findElement(MobileBy.AccessibilityId("date_picker_button"))));
  }
예제 #26
0
파일: WaitFor.java 프로젝트: Dacksus/abmash
  /**
   * Waits until the specified JavaScript returns a non-false value.
   *
   * @param expression the JavaScript expression to evaluate
   * @param timeout time in seconds to wait until a TimeoutException is thrown
   * @throws TimeoutException
   */
  public void evaluatedJavaScriptExpression(String expression, int timeout)
      throws TimeoutException {
    WebDriverWait wait = new WebDriverWait(browser.getWebDriver(), timeout);

    // start waiting for adequate evaluation of expression
    wait.until(new JavaScriptEvaluatedWaitCondition(browser, expression));
  }
예제 #27
0
 /**
  * Wait until element is changed text.
  *
  * @param text before change
  * @param timeoutSec seconds to wait until element is changed text
  * @param checkCondition log assert for expected conditions.
  * @return Parent instance
  */
 public ParentPanel waitForTextChanged(
     final String text, final int timeoutSec, final boolean checkCondition) {
   boolean isChanged;
   logAction(this, getParentClassName(), format("waitForTextChanged[%s]: %s", text, locator));
   long start = System.currentTimeMillis() / 1000;
   WebDriverWait wait =
       (WebDriverWait)
           new WebDriverWait(getDriver(), timeoutSec)
               .ignoring(StaleElementReferenceException.class);
   try {
     isChanged =
         wait.until(
             ExpectedConditions.not(
                 ExpectedConditions.textToBePresentInElementLocated(avatar.byLocator, text)));
   } catch (TimeoutException e) {
     logTechnical(
         format(
             "waitForTextChanged: [ %s ] during: [ %d ] sec ",
             locator, System.currentTimeMillis() / 1000 - start));
     isChanged = false;
   }
   if (checkCondition) {
     logAssertTrue(
         BUSINESS_LEVEL,
         isChanged,
         format("waitForTextChanged - '%s' text '%s' should be changed", getName(), text),
         takePassedScreenshot);
   }
   return parent;
 }
예제 #28
0
 /**
  * Wait until element has a 'value' attribute.
  *
  * @param value 'Value' Attribute of Element
  * @param timeoutSec seconds to wait until element has a 'value' attribute
  * @param checkCondition log assert for expected conditions.
  * @return Parent instance
  */
 public ParentPanel waitForValue(
     final String value, final int timeoutSec, final boolean checkCondition) {
   boolean isPresent;
   logAction(this, getParentClassName(), format("waitForValueAttribute[%s]: %s", value, locator));
   long start = System.currentTimeMillis() / 1000;
   WebDriverWait wait =
       (WebDriverWait)
           new WebDriverWait(getDriver(), timeoutSec)
               .ignoring(StaleElementReferenceException.class);
   try {
     isPresent =
         wait.until(ExpectedConditions.textToBePresentInElementValue(avatar.byLocator, value));
   } catch (TimeoutException e) {
     logTechnical(
         format(
             "waitForValueAttribute: [ %s ] during: [ %d ] sec ",
             locator, System.currentTimeMillis() / 1000 - start));
     isPresent = false;
   }
   if (checkCondition) {
     logAssertTrue(
         BUSINESS_LEVEL,
         isPresent,
         format(
             "waitForValueAttribute - '%s' should has a value attribute '%s'", getName(), value),
         takePassedScreenshot);
   }
   return parent;
 }
예제 #29
0
  /**
   * Wait for the List<WebElement> to be present in the DOM, regardless of being displayed or not.
   * Returns all elements within the current page DOM.
   *
   * @param WebDriver The driver object to be used
   * @param By selector to find the element
   * @param int The time in seconds to wait until returning a failure
   * @return List<WebElement> all elements within the current page DOM, or null (if the timeout is
   *     reached)
   */
  public static List<WebElement> waitForListElementsPresent(
      WebDriver driver, final By by, int timeOutInSeconds) {
    List<WebElement> elements;
    try {
      driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); // nullify implicitlyWait()

      WebDriverWait wait = new WebDriverWait(driver, timeOutInSeconds);
      wait.until(
          (new ExpectedCondition<Boolean>() {
            @Override
            public Boolean apply(WebDriver driverObject) {
              return areElementsPresent(driverObject, by);
            }
          }));

      elements = driver.findElements(by);
      driver
          .manage()
          .timeouts()
          .implicitlyWait(DEFAULT_WAIT_4_PAGE, TimeUnit.SECONDS); // reset implicitlyWait
      return elements; // return the element
    } catch (Exception e) {
      e.printStackTrace();
    }
    return null;
  }
예제 #30
0
 /**
  * Wait until Expected Condition.
  *
  * @param condition - Expected Condition
  * @param timeoutSec - the maximum time to wait in seconds
  * @param checkCondition log assert for expected conditions.
  * @return Parent instance
  */
 public ParentPanel waitForExpectedConditions(
     final ExpectedCondition<Boolean> condition,
     final int timeoutSec,
     final boolean checkCondition) {
   boolean isTrue;
   logAction(
       this, getParentClassName(), format("waitForExpectedCondition[%s}: %s", condition, locator));
   long start = System.currentTimeMillis() / 1000;
   WebDriverWait wait =
       (WebDriverWait)
           new WebDriverWait(getDriver(), timeoutSec)
               .ignoring(StaleElementReferenceException.class);
   setTimeout(1);
   try {
     wait.until(condition);
     isTrue = false;
   } catch (TimeoutException e) {
     logTechnical(
         format(
             "waitForExpectedCondition: [ %s ] during: [ %d ] sec ",
             locator, System.currentTimeMillis() / 1000 - start));
     isTrue = true;
   }
   setTimeout(TIMEOUT);
   if (checkCondition) {
     logAssertFalse(
         BUSINESS_LEVEL,
         isTrue,
         format("waitForExpectedCondition - '%s'", condition),
         takePassedScreenshot);
   }
   return parent;
 }