Search in sources :

Example 21 with NgWebElement

use of com.github.sergueik.jprotractor.NgWebElement in project selenium_java by sergueik.

the class NgButtonIntegrationTest method testButtonNgIf.

@Test
public void testButtonNgIf() {
    // if (isCIBuild) { // Alert not handled by PhantomJS
    // return;
    // }
    getPageContent("ng_watch_ng_if.htm");
    WebElement button = seleniumDriver.findElement(By.cssSelector("button.btn"));
    ngDriver.waitForAngular();
    CommonFunctions.highlight(button);
    NgWebElement ng_button = new NgWebElement(ngDriver, button);
    assertThat(ng_button, notNullValue());
    assertThat(ng_button.getAttribute("ng-click"), equalTo("house.frontDoor.open()"));
    assertThat(ng_button.getText(), equalTo("Open Door"));
    ngDriver.waitForAngular();
    try {
        state = ((Boolean) ng_button.evaluate("!house.frontDoor.isOpen")).booleanValue();
    } catch (Exception ex) {
        System.err.println("evaluate was not handled : " + ex.getStackTrace().toString());
    }
    assertTrue(state);
    button.click();
    try {
        // confirm alert
        seleniumDriver.switchTo().alert().accept();
    } catch (NoAlertPresentException ex) {
    // Alert not present - ignore
    } catch (WebDriverException ex) {
        System.err.println("Alert was not handled : " + ex.getStackTrace().toString());
        return;
    }
    button = seleniumDriver.findElement(By.cssSelector("button.btn"));
    CommonFunctions.highlight(button);
    ng_button = new NgWebElement(ngDriver, button);
    assertThat(ng_button, notNullValue());
    assertThat(ng_button.getAttribute("ng-click"), equalTo("house.frontDoor.close()"));
    assertThat(ng_button.getText(), equalTo("Close Door"));
    try {
        state = ((Boolean) ng_button.evaluate("house.frontDoor.isOpen")).booleanValue();
    } catch (Exception ex) {
        // [JavaScript Error: "e is null"] ?
        System.err.println("evaluate was not handled : " + ex.getStackTrace().toString());
    }
    assertTrue(state);
}
Also used : NoAlertPresentException(org.openqa.selenium.NoAlertPresentException) NgWebElement(com.github.sergueik.jprotractor.NgWebElement) NgWebElement(com.github.sergueik.jprotractor.NgWebElement) WebElement(org.openqa.selenium.WebElement) WebDriverException(org.openqa.selenium.WebDriverException) IOException(java.io.IOException) NoAlertPresentException(org.openqa.selenium.NoAlertPresentException) WebDriverException(org.openqa.selenium.WebDriverException) Test(org.junit.Test)

Example 22 with NgWebElement

use of com.github.sergueik.jprotractor.NgWebElement in project selenium_java by sergueik.

the class NgCalculatorIntegrationTest method testAddition.

@Test
public void testAddition() {
    NgWebElement element = ngDriver.findElement(NgBy.model("first"));
    assertThat(element, notNullValue());
    highlight(element);
    element.sendKeys("40");
    element = ngDriver.findElement(NgBy.model("second"));
    assertThat(element, notNullValue());
    highlight(element);
    element.sendKeys("2");
    element = ngDriver.findElement(NgBy.options("value for (key, value) in operators"));
    assertThat(element, notNullValue());
    element.click();
    element = ngDriver.findElement(NgBy.buttonText("Go!"));
    assertThat(element, notNullValue());
    assertThat(element.getText(), containsString("Go"));
    element.click();
    element = ngDriver.findElement(NgBy.binding("latest"));
    assertThat(element, notNullValue());
    assertThat(element.getText(), equalTo("42"));
    highlight(element);
}
Also used : NgWebElement(com.github.sergueik.jprotractor.NgWebElement) Test(org.junit.Test)

Example 23 with NgWebElement

use of com.github.sergueik.jprotractor.NgWebElement in project selenium_java by sergueik.

the class NgCssContainingTextTest method test5.

@Test
public void test5() {
    Object[] results = new Object[] { "Software Engineer", "Senior Javascript Developer" };
    String cellTextPackedRegexp = "__REGEXP__/(?:Software Engineer|Senior Javascript Developer)/i";
    NgWebElement ngTableElement = null;
    // Arrange
    try {
        WebElement tableElement = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("example")));
        ngTableElement = new NgWebElement(ngDriver, tableElement);
    } catch (RuntimeException timeoutException) {
        return;
    }
    // Assert
    assertThat(ngTableElement, notNullValue());
    actions.moveToElement(ngTableElement.getWrappedElement()).build().perform();
    List<WebElement> cellElements = ngTableElement.findElements(NgBy.cssContainingText("tbody > tr > td:nth-child(2)", cellTextPackedRegexp));
    assertThat(cellElements.size(), greaterThan(0));
    cellElements.stream().forEach(CommonFunctions::highlight);
    cellElements.stream().map(o -> o.getText()).forEach(System.err::println);
    assertThat(cellElements.stream().map(o -> o.getText()).collect(Collectors.toSet()), hasItems(results));
}
Also used : WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) BeforeClass(org.junit.BeforeClass) NgWebElement(com.github.sergueik.jprotractor.NgWebElement) Date(java.util.Date) WebDriver(org.openqa.selenium.WebDriver) SimpleDateFormat(java.text.SimpleDateFormat) WebElement(org.openqa.selenium.WebElement) Assert.assertThat(org.junit.Assert.assertThat) Is.is(org.hamcrest.core.Is.is) ParseException(java.text.ParseException) Alert(org.openqa.selenium.Alert) Actions(org.openqa.selenium.interactions.Actions) Before(org.junit.Before) AfterClass(org.junit.AfterClass) Dimension(org.openqa.selenium.Dimension) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Keys(org.openqa.selenium.Keys) ExpectedConditions(org.openqa.selenium.support.ui.ExpectedConditions) By(org.openqa.selenium.By) Matchers(org.hamcrest.Matchers) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) Collectors(java.util.stream.Collectors) NgBy(com.github.sergueik.jprotractor.NgBy) TimeUnit(java.util.concurrent.TimeUnit) AnyOf.anyOf(org.hamcrest.core.AnyOf.anyOf) List(java.util.List) NgWebDriver(com.github.sergueik.jprotractor.NgWebDriver) LocalDate(java.time.LocalDate) DateMatchers.sameOrBefore(org.exparity.hamcrest.date.DateMatchers.sameOrBefore) NgWebElement(com.github.sergueik.jprotractor.NgWebElement) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) NgWebElement(com.github.sergueik.jprotractor.NgWebElement) WebElement(org.openqa.selenium.WebElement) Test(org.junit.Test)

Example 24 with NgWebElement

use of com.github.sergueik.jprotractor.NgWebElement in project selenium_java by sergueik.

the class NgCssContainingTextTest method test4.

@Test
public void test4() {
    NgWebElement ngTableElement = null;
    // Arrange
    try {
        WebElement tableElement = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("example")));
        ngTableElement = new NgWebElement(ngDriver, tableElement);
    } catch (RuntimeException timeoutException) {
        return;
    }
    // Assert
    assertThat(ngTableElement, notNullValue());
    actions.moveToElement(ngTableElement.getWrappedElement()).build().perform();
    List<WebElement> cellElements = ngTableElement.findElements(NgBy.cssContainingText("tbody > tr > td:nth-child(2)", "Software Engineer"));
    assertThat(cellElements.size(), greaterThan(0));
    cellElements.stream().forEach(CommonFunctions::highlight);
    cellElements.stream().map(o -> o.getText()).forEach(System.err::println);
}
Also used : WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) BeforeClass(org.junit.BeforeClass) NgWebElement(com.github.sergueik.jprotractor.NgWebElement) Date(java.util.Date) WebDriver(org.openqa.selenium.WebDriver) SimpleDateFormat(java.text.SimpleDateFormat) WebElement(org.openqa.selenium.WebElement) Assert.assertThat(org.junit.Assert.assertThat) Is.is(org.hamcrest.core.Is.is) ParseException(java.text.ParseException) Alert(org.openqa.selenium.Alert) Actions(org.openqa.selenium.interactions.Actions) Before(org.junit.Before) AfterClass(org.junit.AfterClass) Dimension(org.openqa.selenium.Dimension) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Keys(org.openqa.selenium.Keys) ExpectedConditions(org.openqa.selenium.support.ui.ExpectedConditions) By(org.openqa.selenium.By) Matchers(org.hamcrest.Matchers) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) Collectors(java.util.stream.Collectors) NgBy(com.github.sergueik.jprotractor.NgBy) TimeUnit(java.util.concurrent.TimeUnit) AnyOf.anyOf(org.hamcrest.core.AnyOf.anyOf) List(java.util.List) NgWebDriver(com.github.sergueik.jprotractor.NgWebDriver) LocalDate(java.time.LocalDate) DateMatchers.sameOrBefore(org.exparity.hamcrest.date.DateMatchers.sameOrBefore) NgWebElement(com.github.sergueik.jprotractor.NgWebElement) NgWebElement(com.github.sergueik.jprotractor.NgWebElement) WebElement(org.openqa.selenium.WebElement) Test(org.junit.Test)

Example 25 with NgWebElement

use of com.github.sergueik.jprotractor.NgWebElement in project selenium_java by sergueik.

the class NgDatePickerIntegrationTest method testHighlightCurrentMonthDays.

// @Ignore
@Test
public // uses Embedded calendar
void testHighlightCurrentMonthDays() {
    NgWebElement ng_datepicker = null;
    // Arrange
    final String searchText = "Embedded calendar";
    try {
        (new WebDriverWait(driver, 5)).until(new ExpectedCondition<Boolean>() {

            @Override
            public Boolean apply(WebDriver d) {
                // cannot use Java streams here ?
                Iterator<WebElement> elements = d.findElements(By.className("col-sm-6")).iterator();
                Boolean result = false;
                WebElement element = null;
                while (elements.hasNext() && !result) {
                    element = elements.next();
                    String text = element.getText();
                    result = text.contains(searchText);
                }
                if (result) {
                    actions.moveToElement(element).build().perform();
                }
                return result;
            }
        });
    } catch (Exception e) {
        System.err.println("Exception: " + e.toString());
    }
    // Act
    try {
        ng_datepicker = ngDriver.findElement(NgBy.model("data.embeddedDate", "[data-ng-app]"));
        assertThat(ng_datepicker, notNullValue());
        actions.moveToElement(ng_datepicker.getWrappedElement()).build().perform();
        highlight(ng_datepicker);
    // System.err.println("Embedded: " + ng_datepicker.getText());
    } catch (Exception e) {
        System.err.println("Exception: " + e.toString());
    }
    WebElement[] dates = ng_datepicker.findElements(NgBy.repeater("dateObject in week.dates")).toArray(new WebElement[0]);
    assertTrue(dates.length >= 28);
    Boolean foundDate = false;
    int start = 0, end = dates.length;
    for (int cnt = 0; cnt != dates.length; cnt++) {
        if (start == 0 && Integer.parseInt(dates[cnt].getText()) == 1) {
            start = cnt;
        }
        if (cnt > start && Integer.parseInt(dates[cnt].getText()) == 1) {
            end = cnt;
        }
    }
    for (int cnt = start; cnt != end; cnt++) {
        WebElement date = dates[cnt];
        highlight(date);
        if (date.getAttribute("class").contains("current")) {
            foundDate = true;
        }
    }
    // Assert
    assertTrue(foundDate);
}
Also used : WebDriver(org.openqa.selenium.WebDriver) NgWebDriver(com.github.sergueik.jprotractor.NgWebDriver) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) Iterator(java.util.Iterator) NgWebElement(com.github.sergueik.jprotractor.NgWebElement) NgWebElement(com.github.sergueik.jprotractor.NgWebElement) WebElement(org.openqa.selenium.WebElement) WebDriverException(org.openqa.selenium.WebDriverException) IOException(java.io.IOException) StaleElementReferenceException(org.openqa.selenium.StaleElementReferenceException) Test(org.junit.Test)

Aggregations

NgWebElement (com.github.sergueik.jprotractor.NgWebElement)44 Test (org.junit.Test)41 WebElement (org.openqa.selenium.WebElement)39 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)14 IOException (java.io.IOException)10 Pattern (java.util.regex.Pattern)10 Matcher (java.util.regex.Matcher)9 NoAlertPresentException (org.openqa.selenium.NoAlertPresentException)9 WebDriverException (org.openqa.selenium.WebDriverException)9 NgWebDriver (com.github.sergueik.jprotractor.NgWebDriver)8 Ignore (org.junit.Ignore)7 StaleElementReferenceException (org.openqa.selenium.StaleElementReferenceException)7 WebDriver (org.openqa.selenium.WebDriver)7 WebDriverWait (org.openqa.selenium.support.ui.WebDriverWait)7 NoSuchElementException (org.openqa.selenium.NoSuchElementException)5 Dimension (org.openqa.selenium.Dimension)4 NgBy (com.github.sergueik.jprotractor.NgBy)3 ParseException (java.text.ParseException)3 SimpleDateFormat (java.text.SimpleDateFormat)3 LocalDate (java.time.LocalDate)3