@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();
  }
Пример #2
0
  @Test
  public void testStateElement() {
    ElementLocator locator = mock(ElementLocator.class);
    when(locator.findElement()).thenReturn(element1);

    WebElement webElement = LocatorProxies.createWebElement(locator);

    assertThat(LocatorProxies.present(webElement)).isTrue();
    webElement.isEnabled();

    when(element1.isEnabled()).thenThrow(StaleElementReferenceException.class);

    assertThat(LocatorProxies.present(webElement)).isFalse();

    reset(element1);
    when(element1.isEnabled()).thenThrow(StaleElementReferenceException.class);

    assertThatThrownBy(
            new ThrowableAssert.ThrowingCallable() {
              @Override
              public void call() throws Throwable {
                webElement.isEnabled();
              }
            })
        .isExactlyInstanceOf(StaleElementReferenceException.class);

    verify(element1, times(6)).isEnabled();
  }
  /**
   * Case ID:77777. Test Case Name: Can't share an empty message. Created by chinhdt at 2013/12/16
   * 09:28:17
   */
  @Test
  public void test01_CantShareAnEmptyMessage() {
    info("Test 1: Can't share an empty message");

    /*Declare variables*/
    String text1 = "       ";
    String text2 = "Test case1";

    /* Step 1: Don't type in shared activity box */
    // - Connect to Intranet
    // - Click in the composer input box, don't type
    info("----Add text into activity text box-----");
    WebElement inputText = waitForAndGetElement(home.ELEMENT_ACTIVITY_TEXTBOX);
    WebElement shareButton = waitForAndGetElement(ELEMENT_SHARE_BUTTON);

    Assert.assertEquals(shareButton.isEnabled(), false);

    /*Step 2: Input space characters into shared activity box */
    // - Input space characters into shared activity box
    ((JavascriptExecutor) driver)
        .executeScript("arguments[0].textContent = '" + text1 + "';", inputText);
    Assert.assertEquals(shareButton.isEnabled(), false);

    /* Step 3: Input letters into shared activity box */
    // - in put "a" character
    type(ELEMENT_ACTIVITY_WHAT_ARE_YOU_WORKING_LABEL, "   ", false);
    type(home.ELEMENT_ACTIVITY_TEXTBOX, text2, false);
    Utils.pause(1000);
    Assert.assertEquals(shareButton.isEnabled(), true);
    info("-- Verify Share button --");
  }
Пример #4
0
 public TeamsPage addMemberInTeam(String nameMember, String email) {
   clickAddMembersBtn();
   setEmailMembers(email);
   if (selectAddForm.isDisplayed() && selectAddForm.isEnabled()) {
     clickMemberOptions();
     clickIconClose();
   } else if (fullNameForm.isDisplayed() && fullNameForm.isEnabled()) {
     setNameInvite(nameMember);
     clickSendInvitedMember();
   }
   return this;
 }
  /**
   * Verifies Alias input as follows Stores current alias for future Checks error message for more
   * than 20 characters Alias Checks error message for special characters Alias Checks confirm
   * button disabled for blank/current alias Reverts alias to previous value
   *
   * @param validationMessage
   */
  public void verifyAliasInputFieldValidations(HashMap<String, String> validationMessage) {
    clickChangeAliasButton();
    // Store the current Alias
    String currentAlias = OldAliasInput.getAttribute("value");
    // Enter a new alias
    String NewAlias = Helper.generateRandomAlphabetsString(6);
    Element.enterData(testConfig, NewAliasInput, NewAlias, "New Alias Input");
    Element.click(testConfig, uploadAndProcess, "Submit Alias Changes");

    verifyNotificationText(validationMessage.get("AliasChangeSuccessful"));
    clickChangeAliasButton();
    // Verify alias was changed
    Helper.compareEquals(
        testConfig, "Old Alias Value", NewAlias, OldAliasInput.getAttribute("value"));
    // More than 20 characters
    Element.enterData(
        testConfig, NewAliasInput, Helper.generateRandomAlphaNumericString(30), "New Alias Input");
    Element.click(testConfig, uploadAndProcess, "Submit Alias Changes");
    Element.waitForElementDisplay(testConfig, ErrorMessageOnPopUp);
    Helper.compareEquals(
        testConfig,
        "Error Message",
        validationMessage.get("LongAliasErrorMessage"),
        ErrorMessageOnPopUp.getText());
    // Special Characters
    Element.enterData(testConfig, NewAliasInput, "!@##$$$$", "New Alias Input");
    Element.click(testConfig, uploadAndProcess, "Submit Alias Changes");
    Helper.compareEquals(
        testConfig,
        "Error Message",
        validationMessage.get("SpecialCharacterInAliasErrorMessage"),
        ErrorMessageOnPopUp.getText());
    // Existing Alias
    String ExistingAlias = OldAliasInput.getAttribute("value");
    Element.enterData(testConfig, NewAliasInput, ExistingAlias, "New Alias Input");
    Helper.compareTrue(testConfig, "Confirm button is disabled", (!uploadAndProcess.isEnabled()));

    // Blank Value
    Element.enterData(testConfig, NewAliasInput, "", "New Alias Input");
    Helper.compareTrue(testConfig, "Confirm button is disabled", (!uploadAndProcess.isEnabled()));

    // Enter Older value of alias and save changes
    Element.enterData(testConfig, NewAliasInput, currentAlias, "New Alias Input");
    Element.click(testConfig, uploadAndProcess, "Submit Alias Changes");
    verifyNotificationText(validationMessage.get("AliasChangeSuccessful"));
  }
Пример #6
0
 public boolean isCurrentlyEnabled() {
   try {
     return webElement.isEnabled();
   } catch (NoSuchElementException e) {
     return false;
   } catch (StaleElementReferenceException se) {
     return false;
   }
 }
 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;
 }
  @Override
  public void type(String locator, String value) {
    WebElement webElement = getWebElement(locator);

    if (webElement.isEnabled()) {
      webElement.clear();

      webElement.sendKeys(value);
    }
  }
Пример #9
0
  @Test
  public void checkEnabledOnGoogleSearchBox() {
    // TODO: Find a sample site that has hidden elements and use it to
    // verify behavior of enabled and disabled elements.
    WebDriver d = getDriver();

    d.get("http://www.google.com");
    WebElement el = d.findElement(By.cssSelector("input[name*='q']"));

    assertTrue(el.isEnabled());
  }
  public static void type(WebDriver webDriver, String locator, String value) {
    WebElement webElement = getWebElement(webDriver, locator);

    if (!webElement.isEnabled()) {
      return;
    }

    webElement.clear();

    webElement.sendKeys(value);
  }
 public void setNonBlockingOpacity(String nonBlockingOpacity) {
   if (!nonBlockingOpacityInput.isEnabled()) {
     throw new IllegalStateException("The input for setting non blocking opacity is disabled.");
   }
   if (!nonBlockingOpacity.startsWith("0")) {
     throw new IllegalArgumentException("The opacity has to start with '0'.");
   }
   nonBlockingOpacityInput.click();
   nonBlockingOpacityInput.clear();
   nonBlockingOpacityInput.sendKeys(nonBlockingOpacity.substring(1));
 }
 protected static void clickButton(WebElement button) throws InvalidElementStateException {
   if (!button.getAttribute("type").contentEquals("submit")
       || !button.getTagName().toLowerCase().contentEquals("input")) {
     throw new InvalidElementStateException("This web element is not a button input!");
   }
   // we may wanna check if it is displayed and enabled, when performing actions.
   if (button.isDisplayed() && button.isEnabled()) {
     button.click();
   } else {
     throw new InvalidElementStateException(
         "Button by " + button.getAttribute("id") + " is disabled or not displayed!");
   }
 }
Пример #13
0
  @SuppressWarnings("finally")
  public static boolean isElementPresent(WebDriver driver, By by) throws InterruptedException {
    for (int second = 0; second < 30; second++) {
      try {
        WebElement e = driver.findElement(by);
        if (null != e && (e.isDisplayed() || e.isEnabled())) return true;
      } catch (Exception e) {
        continue;
      } finally {
        Thread.sleep(500);
      }
    }

    return false;
  }
 protected static void setCheckCheckBoxState(WebElement checkBox, boolean checked)
     throws InvalidElementStateException {
   if (!checkBox.getAttribute("type").contentEquals("checkbox")
       || !checkBox.getTagName().toLowerCase().contentEquals("input")) {
     throw new InvalidElementStateException("This web element is not a checkbox!");
   }
   // we may wanna check if it is displayed and enabled, when performing actions.
   if (checkBox.isDisplayed() && checkBox.isEnabled()) {
     if (checkBox.isSelected() != checked) {
       checkBox.click();
     }
   } else {
     throw new InvalidElementStateException(
         "Checkbox by " + checkBox.getAttribute("id") + " is disabled!");
   }
 }
  protected void doSimpleExplore(BrowserWebDriverContainer rule) {
    RemoteWebDriver driver = setupDriverFromRule(rule);
    driver.get("http://en.wikipedia.org/wiki/Randomness");

    loop:
    for (int i = 0; i < 5; i++) {
      Random random = new Random();
      List<WebElement> webElements = driver.findElements(By.tagName("a"));
      for (WebElement webElement : webElements) {
        if (random.nextInt(10) == 0 && webElement.isDisplayed() && webElement.isEnabled()) {
          webElement.click();
          break loop;
        }
      }
    }
  }
 private static void setTextElementText(
     WebElement textElement, String textInputType, String tag, String value)
     throws InvalidElementStateException {
   if (!textElement.getAttribute("type").contentEquals(textInputType)
       || !textElement.getTagName().toLowerCase().contentEquals(tag)) {
     throw new InvalidElementStateException("This web element is not a text input!");
   }
   // we may wanna check if it is displayed and enabled, when performing actions.
   if (textElement.isDisplayed() && textElement.isEnabled()) {
     textElement.click();
     textElement.clear();
     textElement.sendKeys(value);
   } else {
     throw new InvalidElementStateException(
         "Text input by " + textElement.getAttribute("id") + " is disabled or not displayed!");
   }
 }
  @Test
  @RunAsClient
  public void renderFormPortlet() throws Exception {
    browser.get(portalURL.toString());

    assertTrue("Check that page contains output element", outputField.isDisplayed());

    assertEquals("Output text set.", Bean.HELLO_JSF_PORTLET, outputField.getText());

    assertEquals("Input text set.", Bean.HELLO_JSF_PORTLET, inputField.getAttribute("value"));

    assertTrue("Submit button is not enabled", submitButton.isEnabled());
    assertNotSame(
        "Submit button onclick attribute should not be blank",
        "",
        submitButton.getAttribute("onclick"));
  }
  public String getText(By locator, int seconds) {

    String product_text = "Not Found";
    WebDriverWait wait = new WebDriverWait(driver, seconds);
    WebElement search = null;
    try {

      search = wait.until(ExpectedConditions.elementToBeClickable(driver.findElement(locator)));
      if (search.isEnabled()) {
        product_text = search.getText();
      }
      ;

    } catch (Exception e) {
      System.out.println("\nElement not found! " + e);
    }
    return product_text;
  }
Пример #19
0
  @Test
  public void checkLocationAndSizeOfBingSearchBox() {
    WebDriver d = getDriver();
    d.manage().timeouts().pageLoadTimeout(20, TimeUnit.SECONDS);

    d.get("http://www.bing.com");
    WebElement searchBox = d.findElement(By.cssSelector("input[name*='q']"));

    assertTrue(
        searchBox.getCssValue("color").contains("rgb(0, 0, 0)")
            || searchBox.getCssValue("color").contains("rgba(0, 0, 0, 1)"));
    assertEquals("", searchBox.getAttribute("value"));
    assertEquals("input", searchBox.getTagName());
    assertEquals(true, searchBox.isEnabled());
    assertEquals(true, searchBox.isDisplayed());
    assertTrue(searchBox.getLocation().getX() >= 200);
    assertTrue(searchBox.getLocation().getY() >= 100);
    assertTrue(searchBox.getSize().getWidth() >= 350);
    assertTrue(searchBox.getSize().getHeight() >= 20);
  }
  @Override
  public void typeKeys(String locator, String value) {
    WebElement webElement = getWebElement(locator);

    if (!webElement.isEnabled()) {
      return;
    }

    StringBundler sb = new StringBundler();

    sb.append(".*[");

    Set<String> keysSpecialCharsSet = _keysSpecialChars.keySet();

    for (String specialChar : keysSpecialCharsSet) {
      sb.append("\\");
      sb.append(specialChar);
    }

    sb.append("]*.*");

    if (value.matches(sb.toString())) {
      char[] chars = value.toCharArray();

      for (char c : chars) {
        String s = String.valueOf(c);

        if (keysSpecialCharsSet.contains(s)) {
          webElement.sendKeys(Keys.SHIFT, _keysSpecialChars.get(s));
        } else {
          webElement.sendKeys(s);
        }
      }
    } else {
      webElement.sendKeys(value);
    }
  }
Пример #21
0
 // TODO this requires redesign for writables
 public static boolean perform(WebHandle handle, WebDriver driver) {
   WebElement we = handle.findElement(driver);
   if (we == null) {
     // TODO this place strongly interferes with driver's implicitly wait. So, I think, personal
     // fails counter per handle needed.
     log.error(
         handle.url.graphUrl()
             + " | "
             + handle.xpath
             + "\n"
             + "Unable to .perform(WebDriver), cause search of element by stored selector is failed.");
     return false;
   }
   if (!we.isDisplayed() || !we.isEnabled()) {
     log.error(
         handle.url.graphUrl()
             + " | "
             + handle.xpath
             + "\n"
             + "Failed to .perform(WebDriver), cause element not displayed or not enabled.");
     return false;
   }
   switch (handle.eltype) {
     case clickable:
       we.click();
       break;
       //            case writable: we.sendKeys(context); break;
     case terminal:
       if (handle.isRoot()) return true;
       assert false : "terminal elements was touched";
       break;
     default:
       assert false : "this shouldn't have happened???";
       break;
   }
   return true;
 }
  @SuppressWarnings("unchecked")
  @Override
  public PeopleFinderPage render(RenderTime timer) {
    while (true) {
      timer.start();
      synchronized (this) {
        try {
          this.wait(100L);
        } catch (InterruptedException e) {
        }
      }
      try {
        // Check button is displayed and is not disabled
        WebElement searchBtn = driver.findElement(SEARCH_BUTTON);
        if (searchBtn.isEnabled()) {
          if (hasNoResultMessage()) {
            break;
          }
          if (isVisibleResults()) {
            break;
          }
          // This is the default html content hence it left to last.
          if (isHelpScreenDisplayed()) {
            if (!isVisibleResults() && !hasNoResultMessage()) {
              break;
            }
          }
        }
      } catch (NoSuchElementException nse) {
        // Repeat till we see it
      } finally {
        timer.end();
      }
    }

    return this;
  }
Пример #23
0
 /**
  * return true if the element is enabled, otherway return false
  *
  * @return
  */
 public boolean isEnabled() {
   return webElement.isEnabled();
 }
 @Override
 public boolean isEnabled(WebElement element) {
   return element.isEnabled();
 }
Пример #25
0
 private boolean isDisabledField(WebElement webElement) {
   return (isAFormElement(webElement) && (!webElement.isEnabled()));
 }
Пример #26
0
 public boolean isEnabled() {
   return (webElement != null) && (webElement.isEnabled());
 }
  public static void main(String[] args) throws InterruptedException {

    WebDriver driver = new FirefoxDriver();

    driver.manage().window().maximize();

    String contactUrl = "http://www.testdiary.com/training/selenium/selenium-test-page/";

    driver.get(contactUrl);

    (new WebDriverWait(driver, 10))
        .until(ExpectedConditions.visibilityOfElementLocated(By.id("seleniumbox")));

    // Declaring a local variable of type "WebElement" to initialize the
    // value of the webElement (seleniumCheckbox) and webElement
    // (restCheckbox)
    WebElement seleniumCheckbox = driver.findElement(By.id("seleniumbox"));
    WebElement restCheckbox = driver.findElement(By.id("restapibox"));

    // wait was covered in prvious tutorial
    (new WebDriverWait(driver, 30))
        .until(ExpectedConditions.elementToBeClickable(seleniumCheckbox));

    // Declaring a local variable of type "Boolean" to initialize the
    // value of the webElement (checkSelenium) and webElement (checkRestApi)
    // Using the isSelected method we check if the check box is selected or
    // not.
    Boolean checkSelenium = seleniumCheckbox.isSelected();
    Boolean checkRestApi = restCheckbox.isSelected();

    // use an if condition to check if boolean returned false
    // If false then it was not selected
    // click and select the checkbox
    if (checkSelenium == false) {
      seleniumCheckbox.click();
      System.out.println("Test has selected Selenium checkbox");
    } else {
      System.out.println("Selenium checkbox was selected on default");
    }

    // Repeat the process for checkRestAapi
    if (checkRestApi == false) {
      restCheckbox.click();
      System.out.println("Test has selected Rest api checkbox");
    } else {
      System.out.println("Rest Api checkbox was selected on default");
    }

    // Check if Save button is displayed on the WebPage
    WebElement saveButton = driver.findElement(By.id("demo"));

    Boolean checkSaveIsDisplayed = saveButton.isDisplayed();

    if (checkSaveIsDisplayed == true) {
      System.out.println("save button is displayed");
    }

    // Check if Save button is not enabled on the WebPage

    Boolean checkSaveIsEnabled = saveButton.isEnabled();

    if (checkSaveIsEnabled == false) {
      System.out.println("save button is not enabled");
    }

    // Click on a radio button then check if the save button is now enabled

    WebElement javaRadioButton = driver.findElement(By.id("java1"));

    (new WebDriverWait(driver, 30)).until(ExpectedConditions.elementToBeClickable(javaRadioButton));

    javaRadioButton.click();

    // check if it is now enabled
    checkSaveIsEnabled = saveButton.isEnabled();
    if (checkSaveIsEnabled == true) {
      System.out.println("save button is enabled");
    }

    driver.close();

    System.exit(0);
  }
 public boolean isEnabled() {
   return wrappedElement.isEnabled();
 }