Search in sources :

Example 36 with NgWebElement

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

the class NgMultiSelectIntegrationTest method testSelectAll.

// @Ignore
@Test
public void testSelectAll() {
    // Given we are using multiselect directive for selecting cars
    NgWebElement ng_directive = ngDriver.findElement(NgBy.model("selectedCar"));
    assertThat(ng_directive, notNullValue());
    assertTrue(ng_directive.getTagName().equals("am-multiselect"));
    WebElement toggleSelect = ng_directive.findElement(By.cssSelector("button[ng-click='toggleSelect()']"));
    assertThat(toggleSelect, notNullValue());
    assertTrue(toggleSelect.isDisplayed());
    toggleSelect.click();
    // When selected all cars via 'check all' link
    wait.until(ExpectedConditions.visibilityOf(ng_directive.findElement(By.cssSelector("button[ng-click='checkAll()']"))));
    WebElement checkAll = ng_directive.findElement(By.cssSelector("button[ng-click='checkAll()']"));
    assertThat(checkAll, notNullValue());
    assertTrue(checkAll.isDisplayed());
    CommonFunctions.highlight(checkAll);
    checkAll.click();
    // Then every car is selected
    List<WebElement> cars = ng_directive.findElements(NgBy.repeater("i in items"));
    int selectedCarCount = 0;
    for (WebElement car : cars) {
        assertTrue((boolean) (new NgWebElement(ngDriver, car).evaluate("i.checked")));
        System.err.println("* " + car.getText());
        selectedCarCount++;
    }
    assertThat(cars.size(), equalTo(selectedCarCount));
    // And the button text shows the total number of cars selected
    WebElement button = ngDriver.findElement(By.cssSelector("am-multiselect > div > button"));
    String buttonTextPattern = "There are (\\d+) car\\(s\\) selected";
    String buttonText = button.getText();
    assertTrue(buttonText.matches(buttonTextPattern));
    System.err.println(buttonText);
    int carCount = 0;
    Pattern pattern = Pattern.compile(buttonTextPattern);
    Matcher matcher = pattern.matcher(buttonText);
    if (matcher.find()) {
        carCount = Integer.parseInt(matcher.group(1));
    }
    assertThat(carCount, equalTo(selectedCarCount));
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) NgWebElement(com.github.sergueik.jprotractor.NgWebElement) NgWebElement(com.github.sergueik.jprotractor.NgWebElement) WebElement(org.openqa.selenium.WebElement) Test(org.junit.Test)

Example 37 with NgWebElement

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

the class NgScrollableIntegrationTest method testEvaluateRowData.

@Ignore
@Test
public void testEvaluateRowData() {
    // Wait page to load
    wait.until(ExpectedConditions.visibilityOf(ngDriver.findElement(By.className("table-container"))));
    List<WebElement> nameRows = ngDriver.findElements(new ByChained(NgBy.repeater("row in rowCollection"), NgBy.binding("row.firstName")));
    rowCnt = 0;
    for (WebElement rowElement : nameRows) {
        if (rowCnt++ > maxRows) {
            break;
        }
        NgWebElement ngRowElement = new NgWebElement(ngDriver, rowElement);
        System.err.println(String.format("Row %d Name: %s %s", rowCnt, (String) ngRowElement.evaluate("row.firstName"), (String) ngRowElement.evaluate("row.lastName")));
    }
}
Also used : NgWebElement(com.github.sergueik.jprotractor.NgWebElement) NgWebElement(com.github.sergueik.jprotractor.NgWebElement) WebElement(org.openqa.selenium.WebElement) ByChained(org.openqa.selenium.support.pagefactory.ByChained) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 38 with NgWebElement

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

the class NgScrollableIntegrationTest method testRowsAndColumns.

@Ignore
@Test
public void testRowsAndColumns() {
    // Wait page to load
    wait.until(ExpectedConditions.visibilityOf(ngDriver.findElement(By.className("table-container"))));
    List<WebElement> rows = ngDriver.findElements(NgBy.repeater("row in rowCollection"));
    assertThat(rows, notNullValue());
    assertTrue(rows.size() > 1);
    int size = rows.size();
    System.err.println(String.format("Protractor finds: %d rows", size));
    rowCnt = 0;
    // NOTE: birthdate is empty
    // <a ng-href="mailto:{{row.email}}">email</a></td>
    // appears impossible to locate
    List<String> columnBindings = Arrays.asList("row.firstName", "row.lastName", /*, "row.birthDate" */
    "row.balance");
    System.err.println("Inspecting first " + maxRows + " rows.");
    for (WebElement rowElement : rows) {
        if (rowCnt++ > maxRows) {
            break;
        }
        System.err.println(String.format("row %d: %s", rowCnt, rowElement.getText()));
        highlight(rowElement);
        for (String columnBinding : columnBindings) {
            WebElement columnElement = new NgWebElement(ngDriver, rowElement).findElement(NgBy.binding(columnBinding));
            System.err.println(columnBinding + ": " + columnElement.getText());
            // will miss
            highlight(columnElement);
        }
    }
}
Also used : NgWebElement(com.github.sergueik.jprotractor.NgWebElement) NgWebElement(com.github.sergueik.jprotractor.NgWebElement) WebElement(org.openqa.selenium.WebElement) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 39 with NgWebElement

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

the class NgDatePickerIntegrationTest method testBrowse.

// @Ignore
@Test
public // uses DateTime Picker dropdown with input box
void testBrowse() {
    // Arrange
    final String searchText = "Drop-down Datetime with input box";
    WebElement contaiter = null;
    try {
        contaiter = wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.xpath(String.format("//div[@class='col-sm-6']//*[contains(text(),'%s')]", searchText)))));
        highlight(contaiter);
    } catch (Exception e) {
        System.err.println("Exception: " + e.toString());
    }
    try {
        contaiter = wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.xpath(String.format("//*[text()[contains(.,'%s')]]", searchText)))));
        highlight(contaiter);
    } catch (Exception e) {
        System.err.println("Exception: " + e.toString());
    }
    try {
        (new WebDriverWait(driver, 5)).until(new ExpectedCondition<Boolean>() {

            @Override
            public Boolean apply(WebDriver d) {
                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 = elements.next().getText();
                    // System.err.println("got: " + text);
                    result = text.contains(searchText);
                }
                if (result) {
                    actions.moveToElement(element).build().perform();
                }
                return result;
            }
        });
    } catch (Exception e) {
        System.err.println("Exception: " + e.toString());
    }
    // Act
    NgWebElement ng_datepicker_input = ngDriver.findElement(NgBy.model("data.dateDropDownInput"));
    actions.moveToElement(ng_datepicker_input.getWrappedElement()).build().perform();
    highlight(ng_datepicker_input);
    NgWebElement ng_calendar_button = ngDriver.findElement(By.cssSelector(".input-group-addon"));
    assertThat(ng_calendar_button, notNullValue());
    highlight(ng_calendar_button);
    actions.moveToElement(ng_calendar_button.getWrappedElement()).click().build().perform();
    // NgWebElement ng_datepicker
    NgWebElement ng_dropdown = ngDriver.findElement(By.cssSelector("div.dropdown.open ul.dropdown-menu"));
    assertThat(ng_dropdown, notNullValue());
    highlight(ng_dropdown);
    // Assert
    NgWebElement ng_display = ng_dropdown.findElement(NgBy.binding("data.previousViewDate.display", "[data-ng-app]"));
    assertThat(ng_display, notNullValue());
    Pattern pattern = Pattern.compile("\\d{4}\\-(?<month>\\w{3})");
    Matcher matcher = pattern.matcher(ng_display.getText());
    assertTrue(matcher.find());
    // Act
    String[] months = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "Jan" };
    String display_month = matcher.group("month");
    String next_month = months[java.util.Arrays.asList(months).indexOf(display_month) + 1];
    System.err.println("Current month: " + display_month);
    System.err.println("Expect to find next month: " + next_month);
    WebElement ng_next_month = ng_display.findElement(By.xpath("..")).findElement(By.className("right"));
    assertThat(ng_next_month, notNullValue());
    highlight(ng_next_month);
    try {
        Thread.sleep(100);
    } catch (InterruptedException e) {
    }
    ng_next_month.click();
    assertTrue(ng_display.getText().contains(next_month));
    highlight(ng_display);
    // Assert
    System.err.println("Next month: " + ng_display.getText());
}
Also used : WebDriver(org.openqa.selenium.WebDriver) NgWebDriver(com.github.sergueik.jprotractor.NgWebDriver) Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) 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) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) Iterator(java.util.Iterator) Test(org.junit.Test)

Example 40 with NgWebElement

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

the class NgDatePickerIntegrationTest method testDirectSelect.

// @Ignore
@Test
public // uses DateTime Picker drop down with input box
void testDirectSelect() {
    NgWebElement ng_datepicker;
    // Arrange
    final String searchText = "Drop-down Datetime with input box";
    try {
        (new WebDriverWait(driver, 5)).until(new ExpectedCondition<Boolean>() {

            @Override
            public Boolean apply(WebDriver d) {
                Iterator<WebElement> elements = d.findElements(By.className("col-sm-6")).iterator();
                Boolean result = false;
                WebElement element = null;
                while (elements.hasNext() && !result) {
                    String text = elements.next().getText();
                    // System.err.println("got: " + text);
                    result = text.contains(searchText);
                }
                if (result) {
                    actions.moveToElement(element).build().perform();
                }
                return result;
            }
        });
    } catch (Exception e) {
        System.err.println("Exception: " + e.toString());
    }
    try {
        ng_datepicker = ngDriver.findElement(NgBy.model("data.dateDropDownInput"));
    } catch (WebDriverException e) {
        assertTrue(e.getMessage().contains("no injector found for element argument to getTestability"));
        System.err.println(" Ignoring exception: " + e.getMessage());
    } catch (Exception e) {
        throw (e);
    }
    ng_datepicker = ngDriver.findElement(NgBy.model("data.dateDropDownInput", "[data-ng-app]"));
    assertThat(ng_datepicker, notNullValue());
    assertTrue(ng_datepicker.getAttribute("type").matches("text"));
    // Act, Assert
    actions.moveToElement(ng_datepicker.getWrappedElement()).build().perform();
    highlight(ng_datepicker);
    NgWebElement ng_calendar = ngDriver.findElement(By.cssSelector(".input-group-addon"));
    assertThat(ng_calendar, notNullValue());
    highlight(ng_calendar);
    actions.moveToElement(ng_calendar.getWrappedElement()).click().build().perform();
    NgWebElement ng_dropdown = ngDriver.findElement(By.cssSelector("div.dropdown.open ul.dropdown-menu"));
    assertThat(ng_dropdown, notNullValue());
    highlight(ng_dropdown);
    String monthDate = "12";
    WebElement dateElement = ng_dropdown.findElements(NgBy.cssContainingText("td.ng-binding", monthDate)).get(0);
    assertThat(dateElement, notNullValue());
    highlight(dateElement);
    System.err.println("Mondh Date: " + dateElement.getText());
    dateElement.click();
    ngDriver.waitForAngular();
    ng_datepicker = ng_dropdown.findElement(NgBy.model("data.dateDropDownInput", "[data-ng-app]"));
    assertThat(ng_datepicker, notNullValue());
    highlight(ng_datepicker);
    // System.err.println(ng_datepicker.getAttribute("innerHTML"));
    List<WebElement> ng_dataDates = ng_dropdown.findElements(NgBy.repeater("dateObject in data.dates"));
    assertThat(ng_dataDates.size(), equalTo(24));
    // Thread.sleep(10000);
    Pattern patternTimeOfDay = Pattern.compile("(?:[1-9]|1[0-2]):00 pM", Pattern.CASE_INSENSITIVE);
    WebElement ng_hour = ng_datepicker.findElements(NgBy.cssContainingText("span.hour", patternTimeOfDay)).get(0);
    assertThat(ng_hour, notNullValue());
    highlight(ng_hour);
    System.err.println("Hour of the day (pattern search): " + ng_hour.getText());
    String timeOfDay = "6:00 PM";
    ng_hour = ng_datepicker.findElements(NgBy.cssContainingText("span.hour", timeOfDay)).get(0);
    assertThat(ng_hour, notNullValue());
    highlight(ng_hour);
    System.err.println("Hour of the day (exact text search): " + ng_hour.getText());
    ng_hour.click();
    ngDriver.waitForAngular();
    String specificMinute = "6:35 PM";
    // reload,
    try {
        ng_datepicker = ng_dropdown.findElement(NgBy.model("data.dateDropDownInput", "[data-ng-app]"));
        assertThat(ng_datepicker, notNullValue());
        highlight(ng_datepicker);
    // System.err.println("Dropdown: " + ng_datepicker.getText());
    } catch (StaleElementReferenceException e) {
        // works fine with desktop browsers
        if (isCIBuild) {
            System.err.println("Ignoring StaleElementReferenceException");
        } else {
            System.err.println("Enexpected exception");
            throw (e);
        }
    }
    WebElement ng_minute;
    try {
        ng_minute = ng_datepicker.findElements(NgBy.cssContainingText("span.minute", specificMinute)).get(0);
        assertThat(ng_minute, notNullValue());
        highlight(ng_minute);
        System.err.println("Time of the day: " + ng_minute.getText());
        ng_minute.click();
    } catch (StaleElementReferenceException e) {
        if (isCIBuild) {
            System.err.println("Ignoring StaleElementReferenceException");
        } else {
            throw (e);
        }
    }
    try {
        ng_datepicker = ngDriver.findElement(NgBy.model("data.dateDropDownInput", "[data-ng-app]"));
        highlight(ng_datepicker);
        System.err.println("Selected Date/time : " + ng_datepicker.getAttribute("value"));
        // "Thu May 12 2016 18:35:00 GMT-0400 (Eastern Standard Time)"
        assertTrue(ng_datepicker.getAttribute("value").matches("\\w{3} \\w{3} \\d{1,2} \\d{4} 18:35:00 GMT[+-]\\d{4} \\(.+\\)"));
    } catch (StaleElementReferenceException e) {
        if (isCIBuild) {
            System.err.println("Ignoring StaleElementReferenceException");
        } else {
            throw (e);
        }
    }
}
Also used : WebDriver(org.openqa.selenium.WebDriver) NgWebDriver(com.github.sergueik.jprotractor.NgWebDriver) Pattern(java.util.regex.Pattern) 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) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) Iterator(java.util.Iterator) StaleElementReferenceException(org.openqa.selenium.StaleElementReferenceException) WebDriverException(org.openqa.selenium.WebDriverException) 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