Search in sources :

Example 6 with NgWebElement

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

the class NgLocalFileIntegrationTest method testAngularUISelectHandleSelectedAndAvailable.

// TODO: separate into class AngularUISelect.java
@Ignore
@Test
public void testAngularUISelectHandleSelectedAndAvailable() {
    getPageContent("ng_ui_select_example1.htm");
    List<WebElement> selectedColors = ngDriver.findElements(NgBy.repeater("$item in $select.selected"));
    for (WebElement selectedColor : selectedColors) {
        NgWebElement ngSelectedColor = new NgWebElement(ngDriver, selectedColor);
        highlight(selectedColor);
        Object itemColor = ngSelectedColor.evaluate("$item");
        System.err.println("selected color: " + itemColor.toString());
    }
    WebElement search = ngDriver.findElement(NgBy.model("$select.search"));
    search.click();
    ngDriver.waitForAngular();
    List<WebElement> availableColors = ngDriver.findElements(By.cssSelector("div[role='option']"));
    for (WebElement availableColor : availableColors) {
        NgWebElement ngAvailableColor = new NgWebElement(ngDriver, availableColor);
        highlight(availableColor);
        int availableColorIndex = -1;
        try {
            availableColorIndex = Integer.parseInt(ngAvailableColor.evaluate("$index").toString());
        } catch (Exception e) {
        }
        System.err.println("available color:" + availableColor.getText() + ",index = " + availableColorIndex);
    }
}
Also used : NgWebElement(com.github.sergueik.jprotractor.NgWebElement) NgWebElement(com.github.sergueik.jprotractor.NgWebElement) WebElement(org.openqa.selenium.WebElement) NoAlertPresentException(org.openqa.selenium.NoAlertPresentException) IOException(java.io.IOException) StaleElementReferenceException(org.openqa.selenium.StaleElementReferenceException) NoSuchElementException(org.openqa.selenium.NoSuchElementException) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 7 with NgWebElement

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

the class NgLocalFileIntegrationTest method testAngularUISelectHandleSearch.

@Ignore
@Test
public void testAngularUISelectHandleSearch() {
    getPageContent("ng_ui_select_example1.htm");
    String searchText = "Ma";
    WebElement search = ngDriver.findElement(By.cssSelector("input[type='search']"));
    search.sendKeys(searchText);
    ngDriver.waitForAngular();
    List<WebElement> availableColors = ngDriver.findElements(By.cssSelector("div[role='option']"));
    for (WebElement availableColor : availableColors) {
        NgWebElement ngAvailableColor = new NgWebElement(ngDriver, availableColor);
        highlight(availableColor);
        assertThat(availableColor.getText(), containsString(searchText));
        System.err.println("search = " + searchText + ", found :" + availableColor.getText());
    }
}
Also used : NgWebElement(com.github.sergueik.jprotractor.NgWebElement) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) NgWebElement(com.github.sergueik.jprotractor.NgWebElement) WebElement(org.openqa.selenium.WebElement) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 8 with NgWebElement

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

the class NgLocalFileIntegrationTest method testDatePickerNavigation.

// @Ignore
@Test
public void testDatePickerNavigation() {
    getPageContent("ng_datepicker.htm");
    WebElement ng_result = ngDriver.findElement(NgBy.model("data.inputOnTimeSet"));
    assertThat(ng_result, notNullValue());
    assertTrue(ng_result.getAttribute("type").matches("text"));
    ng_result.clear();
    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);
    NgWebElement ng_display = ngDriver.findElement(NgBy.binding("data.previousViewDate.display"));
    assertThat(ng_display, notNullValue());
    String dateDattern = "\\d{4}\\-(\\w{3})";
    assertTrue(ng_display.getText().matches(dateDattern));
    highlight(ng_display);
    System.err.println("Current month: " + ng_display.getText());
    Pattern pattern = Pattern.compile(dateDattern);
    Matcher matcher = pattern.matcher(ng_display.getText());
    List<String> months = new ArrayList<>(Arrays.asList(new String[] { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Dec", "Jan" }));
    String followingMonth = null;
    if (matcher.find()) {
        followingMonth = months.get(months.indexOf(matcher.group(1).toString()) + 1);
    }
    WebElement ng_right = ng_display.findElement(By.xpath("..")).findElement(By.className("right"));
    assertThat(ng_right, notNullValue());
    highlight(ng_right);
    ng_right.click();
    ng_display = ngDriver.findElement(NgBy.binding("data.previousViewDate.display"));
    highlight(ng_display);
    assertThat(ng_display.getText(), containsString(followingMonth));
    System.err.println("Following month: " + ng_display.getText());
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) 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 9 with NgWebElement

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

the class NgLocalFileIntegrationTest method testChangeSelectedRepeaterOption.

// @Ignore
@Test
public void testChangeSelectedRepeaterOption() {
    if (!isCIBuild) {
        return;
    }
    getPageContent("ng_repeat_selected.htm");
    for (WebElement option : ngDriver.findElements(NgBy.repeater("fruit in Fruits"))) {
        System.err.println("available option: " + option.getText());
        if (option.getText().isEmpty()) {
            break;
        }
        if (option.getText().equalsIgnoreCase("Orange")) {
            System.err.println("selecting option: " + option.getText());
            option.click();
        }
    }
    ngDriver.waitForAngular();
    // System.err.println("findElements(NgBy.selectedRepeaterOption(...))");
    List<WebElement> elements = ngDriver.findElements(NgBy.selectedRepeaterOption("fruit in Fruits"));
    try {
        assertThat(elements.size(), equalTo(1));
    } catch (AssertionError e) {
        if (isCIBuild) {
            System.err.println("Skipped processing exception " + e.toString());
            return;
        } else {
            throw e;
        }
    }
    WebElement element = elements.get(0);
    assertThat(element, notNullValue());
    System.err.println("selected option: " + element.getText());
    assertThat(element.getText(), containsString("Orange"));
    /*
		 * Object fruitSelected = new
		 * NgWebElement(ngDriver,element).evaluate("fruit.Selected");
		 * System.err.println("fruit.Selected = " + fruitSelected.toString()) ;
		 * assertTrue(parseBoolean(fruitSelected.toString()));
		 */
    // System.err.println("findElement(NgBy.selectedRepeaterOption(...))");
    NgWebElement ngRootWevelement = new NgWebElement(ngDriver, ngDriver.findElement(By.cssSelector("div[ng-app='myApp']")));
    List<NgWebElement> ngElements = ngRootWevelement.findNgElements(NgBy.selectedRepeaterOption("fruit in Fruits"));
    try {
        assertThat(elements.size(), equalTo(1));
    } catch (AssertionError e) {
        if (isCIBuild) {
            System.err.println("Skipped processing exception " + e.toString());
            return;
        } else {
            throw e;
        }
    }
    NgWebElement ngElement = ngElements.get(0);
    assertThat(ngElement, notNullValue());
    assertThat(ngElement.getWrappedElement(), notNullValue());
    System.err.println("selected option: " + ngElement.getText());
    // System.err.println("findNgElements(NgBy.selectedRepeaterOption(...))");
    ngElement = ngDriver.findElement(NgBy.selectedRepeaterOption("fruit in Fruits"));
    assertThat(ngElement, notNullValue());
    assertThat(ngElement.getWrappedElement(), notNullValue());
    System.err.println("selected option: " + ngElement.getText());
}
Also used : NgWebElement(com.github.sergueik.jprotractor.NgWebElement) NgWebElement(com.github.sergueik.jprotractor.NgWebElement) WebElement(org.openqa.selenium.WebElement) Test(org.junit.Test)

Example 10 with NgWebElement

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

the class NgLocalFileIntegrationTest method testDragAndDrop.

// @Ignore
@Test
public void testDragAndDrop() {
    // TODO: investigate the failure under TRAVIS
    assumeFalse(isCIBuild);
    getPageContent("ng_drag_and_drop1.htm");
    List<WebElement> ng_cars = ngDriver.findElements(NgBy.repeater("car in models.cars"));
    NgWebElement ng_basket = new NgWebElement(ngDriver, seleniumDriver.findElement(By.xpath("//*[@id='my-basket']")));
    highlight(ng_basket.getWrappedElement());
    for (WebElement ng_car : ng_cars) {
        if (ng_car.getText().isEmpty()) {
            break;
        }
        highlight(ng_car);
        actions.moveToElement(ng_car).build().perform();
        actions.clickAndHold(ng_car).moveToElement(ng_basket.getWrappedElement()).release().build().perform();
        ngDriver.waitForAngular();
        // System.err.println(basket.getAttribute("innerHTML"));
        List<WebElement> ng_cars_basket = ng_basket.findElements(NgBy.repeater("car in models.basket"));
        NgWebElement ng_car_basket = new NgWebElement(ngDriver, ng_cars_basket.get(ng_cars_basket.size() - 1));
        if (ng_car_basket.getText().isEmpty()) {
            break;
        }
        // {{ car.name }} - {{ car.modelYear }} ( {{ car.price | currency }} )
        System.err.format("%s - %s ( %s )\n", ng_car_basket.evaluate("car.name"), ng_car_basket.evaluate("car.modelYear"), ng_car_basket.evaluate("car.price | currency"));
    }
}
Also used : NgWebElement(com.github.sergueik.jprotractor.NgWebElement) NgWebElement(com.github.sergueik.jprotractor.NgWebElement) WebElement(org.openqa.selenium.WebElement) 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