Search in sources :

Example 31 with NgWebElement

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

the class NgLocalFileIntegrationTest method testEvaluate.

// @Ignore
@Test
public void testEvaluate() {
    if (!isCIBuild) {
        return;
    }
    getPageContent("ng_service.htm");
    for (WebElement currentElement : ngDriver.findElements(NgBy.repeater("person in people"))) {
        if (currentElement.getText().isEmpty()) {
            break;
        }
        WebElement personName = new NgWebElement(ngDriver, currentElement).findElement(NgBy.binding("person.Name"));
        assertThat(personName, notNullValue());
        Object personCountry = new NgWebElement(ngDriver, currentElement).evaluate("person.Country");
        assertThat(personCountry, notNullValue());
        System.err.println(personName.getText() + " " + personCountry.toString());
        if (personName.getText().indexOf("Around the Horn") >= 0) {
            assertThat(personCountry.toString(), containsString("UK"));
            highlight(personName);
        }
    }
}
Also used : NgWebElement(com.github.sergueik.jprotractor.NgWebElement) NgWebElement(com.github.sergueik.jprotractor.NgWebElement) WebElement(org.openqa.selenium.WebElement) Test(org.junit.Test)

Example 32 with NgWebElement

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

the class NgLocalFileIntegrationTest method testDatePickerDirectSelect.

// @Ignore
@Test
public void testDatePickerDirectSelect() {
    getPageContent("ng_datepicker.htm");
    // can not test official page - it is not an Angular app.
    // http://dalelotts.github.io/angular-bootstrap-datetimepicker/
    // test aborted with exception
    // Caused by: org.openqa.selenium.WebDriverException: [ng:test] no injector
    // found for element argument to getTestability
    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();
    // need a little more room
    int datepicker_width = 900;
    int datepicker_heght = 800;
    seleniumDriver.manage().window().setSize(new Dimension(datepicker_width, datepicker_heght));
    NgWebElement ng_dropdown = ngDriver.findElement(By.cssSelector("div.dropdown.open ul.dropdown-menu"));
    assertThat(ng_dropdown, notNullValue());
    highlight(ng_dropdown);
    List<WebElement> ng_weekDates = ng_dropdown.findElements(NgBy.repeater("dateObject in week.dates"));
    assertTrue(ng_weekDates.size() > 27);
    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();
    NgWebElement ng_element = ng_dropdown.findElement(NgBy.model("data.inputOnTimeSet"));
    assertThat(ng_element, notNullValue());
    List<WebElement> ng_dataDates = ng_element.findElements(NgBy.repeater("dateObject in data.dates"));
    assertThat(ng_dataDates.size(), equalTo(24));
    String timeOfDay = "6:00 PM";
    WebElement ng_hour = ng_element.findElements(NgBy.cssContainingText("span.hour", timeOfDay)).get(0);
    assertThat(ng_hour, notNullValue());
    highlight(ng_hour);
    System.err.println("Hour of the day: " + ng_hour.getText());
    ng_hour.click();
    ngDriver.waitForAngular();
    String specificMinute = "6:35 PM";
    // reload,
    try {
        ng_element = ng_dropdown.findElement(NgBy.model("data.inputOnTimeSet"));
        assertThat(ng_element, notNullValue());
        highlight(ng_element);
    } catch (StaleElementReferenceException e) {
        // works fine with desktop browsers
        if (isCIBuild) {
            System.err.println("Ignoring StaleElementReferenceException");
        } else {
            throw (e);
        }
    }
    WebElement ng_minute;
    try {
        ng_minute = ng_element.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_result = ngDriver.findElement(NgBy.model("data.inputOnTimeSet"));
        highlight(ng_result);
        System.err.println("Selected Date/time : " + ng_result.getAttribute("value"));
        // "Thu May 12 2016 18:35:00 GMT-0400 (Eastern Standard Time)"
        assertTrue(ng_result.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 : StaleElementReferenceException(org.openqa.selenium.StaleElementReferenceException) NgWebElement(com.github.sergueik.jprotractor.NgWebElement) Dimension(org.openqa.selenium.Dimension) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) NgWebElement(com.github.sergueik.jprotractor.NgWebElement) WebElement(org.openqa.selenium.WebElement) Test(org.junit.Test)

Example 33 with NgWebElement

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

the class NgLocalFileIntegrationTest method testAngularUISelectHandleDeselect.

// @Ignore
@Test
public void testAngularUISelectHandleDeselect() {
    getPageContent("ng_ui_select_example1.htm");
    List<WebElement> selectedColors = ngDriver.findElements(NgBy.repeater("$item in $select.selected"));
    while (selectedColors.size() != 0) {
        selectedColors = ngDriver.findElements(NgBy.repeater("$item in $select.selected"));
        for (WebElement selectedColor : selectedColors) {
            NgWebElement ngSelectedColor = new NgWebElement(ngDriver, selectedColor);
            Object itemColor = ngSelectedColor.evaluate("$item");
            System.err.println("deselecting color: " + itemColor.toString());
            WebElement ng_close = ngSelectedColor.findElement(By.cssSelector("span[class *='close']"));
            assertThat(ng_close, notNullValue());
            assertThat(ng_close.getAttribute("ng-click"), notNullValue());
            assertThat(ng_close.getAttribute("ng-click"), containsString("removeChoice"));
            highlight(ng_close);
            ng_close.click();
            ngDriver.waitForAngular();
        }
    }
    System.err.println("Nothing is selected");
}
Also used : NgWebElement(com.github.sergueik.jprotractor.NgWebElement) NgWebElement(com.github.sergueik.jprotractor.NgWebElement) WebElement(org.openqa.selenium.WebElement) Test(org.junit.Test)

Example 34 with NgWebElement

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

the class NgLocalFileIntegrationTest method testEvaluateEvenOdd.

// @Ignore
@Test
public void testEvaluateEvenOdd() {
    if (!isCIBuild) {
        return;
    }
    getPageContent("ng_table_even_odd.htm");
    for (WebElement currentRow : ngDriver.findElements(NgBy.repeater("x in names"))) {
        for (WebElement currentCell : currentRow.findElements(By.tagName("td"))) {
            System.err.println(currentCell.getTagName() + " '" + currentCell.getText() + "' " + currentCell.getAttribute("style"));
            boolean odd = ((Boolean) new NgWebElement(ngDriver, currentCell).evaluate("$odd")).booleanValue();
            if (odd) {
            } else {
            }
        }
    }
}
Also used : NgWebElement(com.github.sergueik.jprotractor.NgWebElement) NgWebElement(com.github.sergueik.jprotractor.NgWebElement) WebElement(org.openqa.selenium.WebElement) Boolean.parseBoolean(java.lang.Boolean.parseBoolean) Test(org.junit.Test)

Example 35 with NgWebElement

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

the class NgLocalFileIntegrationTest method testUpload1.

@Ignore
@Test
public void testUpload1() {
    if (!isCIBuild) {
        return;
    }
    // This example interacts with custom 'fileModel' directive
    getPageContent("ng_upload1.htm");
    WebElement file = ngDriver.findElement(By.cssSelector("div[ng-controller = 'myCtrl'] > input[type='file']"));
    assertThat(file, notNullValue());
    String localPath = "C:/developer/sergueik/powershell_selenium/powershell/testfile.txt";
    file.sendKeys(localPath);
    WebElement button = ngDriver.findElement(NgBy.buttonText("Upload"));
    button.click();
    NgWebElement ng_file = new NgWebElement(ngDriver, file);
    assertThat(ng_file, notNullValue());
    try {
        Object myFile = ng_file.evaluate("myFile");
        if (myFile instanceof Map) {
            @SuppressWarnings("rawtypes") Map<?, ?> map = (Map) (myFile);
            for (Map.Entry<?, ?> entry : map.entrySet()) {
                String key = entry.getKey().toString();
                Object value = entry.getValue();
                System.err.println(key + " = " + value.toString());
            }
        } else {
            System.err.println(myFile.toString());
        }
    } catch (Exception ex) {
        fullStackTrace = org.apache.commons.lang.exception.ExceptionUtils.getFullStackTrace(ex);
        System.err.println("Exception:\n" + fullStackTrace);
    }
    try {
        String script = "var e = angular.element(arguments[0]); var f = e.scope().myFile; return f.name";
        Object result = CommonFunctions.executeScript(script, ng_file);
        assertThat(result, notNullValue());
        System.err.println("myFile.name = " + result);
    } catch (Exception ex) {
        fullStackTrace = org.apache.commons.lang.exception.ExceptionUtils.getFullStackTrace(ex);
        System.err.println("Exception:\n" + fullStackTrace);
    }
}
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) Map(java.util.Map) 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)

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