Search in sources :

Example 26 with NgWebElement

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

the class NgScrollableTablePage method getFullName.

public String getFullName(int index) {
    waitPageLoad();
    WebElement row = rows.get(index);
    NgWebElement ngRowElement = new NgWebElement(ngDriver, row);
    return String.format("%s %s", (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)

Example 27 with NgWebElement

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

the class NgMultiSelectPage method selectAllCars.

public void selectAllCars() {
    for (int rowNum = 0; rowNum != countCars(); rowNum++) {
        // For every row, click on the car name
        NgWebElement ngCar = new NgWebElement(ngDriver, directive).findElement(NgBy.repeaterElement("i in items", rowNum, "i.label"));
        try {
            System.err.println(ngCar.getAttribute("innerHTML"));
        } catch (NullPointerException e) {
        // ignore
        }
        try {
            System.err.println("* " + ngCar.evaluate("i.label").toString());
            ngCar.click();
        } catch (WebDriverException e) {
        // ignore
        }
    }
}
Also used : NgWebElement(com.github.sergueik.jprotractor.NgWebElement) WebDriverException(org.openqa.selenium.WebDriverException)

Example 28 with NgWebElement

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

the class NgIgnoreSyncIntegrationTest method testNonAngularIgnoreSync.

// @Ignore
@Test
public void testNonAngularIgnoreSync() {
    if (isCIBuild) {
        return;
    }
    NgWebDriver ngDriver = new NgWebDriver(seleniumDriver, true);
    ngDriver.navigate().to("http://www.google.com");
    long startTime = System.currentTimeMillis();
    ngDriver.waitForAngular();
    long estimatedTime = System.currentTimeMillis() - startTime;
    System.err.println("waitForAngular: " + estimatedTime);
    NgWebElement element = ngDriver.findElement(By.cssSelector("input#gs_htif0"));
    try {
        element.getAttribute("id");
    } catch (TimeoutException exception) {
        fullStackTrace = org.apache.commons.lang.exception.ExceptionUtils.getFullStackTrace(exception);
        System.err.println("TimeoutException thrown: " + fullStackTrace);
        return;
    }
}
Also used : NgWebDriver(com.github.sergueik.jprotractor.NgWebDriver) NgWebElement(com.github.sergueik.jprotractor.NgWebElement) TimeoutException(org.openqa.selenium.TimeoutException) Test(org.junit.Test)

Example 29 with NgWebElement

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

the class NgLocalFileIntegrationTest method testUpload3.

// @Ignore
@Test
public void testUpload3() {
    if (isCIBuild) {
        return;
    }
    // TODO: abort the test on timeout
    // http://stackoverflow.com/questions/2275443/how-to-timeout-a-thread
    getPageContent("ng_upload3.htm");
    WebElement drop = ngDriver.findElement(NgBy.binding("dropText"));
    assertThat(drop, notNullValue());
    highlight(drop);
    WebElement fileToUpload = ngDriver.findElement(By.id("fileToUpload"));
    assertThat(fileToUpload, notNullValue());
    assertTrue(fileToUpload.getAttribute("type").equalsIgnoreCase("file"));
    String localPath = "C:/developer/sergueik/powershell_selenium/powershell/testfile.txt";
    System.err.println("sendKeys :" + localPath);
    fileToUpload.sendKeys(localPath);
    NgWebElement ng_fileToUpload = new NgWebElement(ngDriver, fileToUpload);
    // String script = "angular.element(this).scope().setFiles(this)";
    // Object result = CommonFunctions.executeScript(script,ng_fileToUpload);
    // assertThat(result, notNullValue());
    wait.until(ExpectedConditions.visibilityOf(ngDriver.findElement(By.cssSelector("input[ type='button' ][ value='Upload' ]"))));
    // Element is not currently visible and may not be manipulated
    WebElement button = ngDriver.findElement(By.cssSelector("input[ type='button' ][ value='Upload' ]"));
    System.err.println("Click");
    button.click();
}
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) Test(org.junit.Test)

Example 30 with NgWebElement

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

the class NgLocalFileIntegrationTest method testMultiSelect2.

@Ignore
@Test
public void testMultiSelect2() {
    getPageContent("ng_multi_select2.htm");
    WebElement button = ngDriver.findElement(By.cssSelector("multiselect-dropdown button[data-ng-click='openDropdown()']"));
    assertThat(button, notNullValue());
    button.click();
    // selectedRepeaterOption("option in options") will not work with this
    // directive
    List<WebElement> elements = ngDriver.findElements(NgBy.binding("option.name"));
    assertTrue(elements.size() > 0);
    // find what is selected based on the bootstrap class attribute
    String expression = "\\-remove\\-";
    Pattern pattern = Pattern.compile(expression);
    Matcher matcher = null;
    int count = 0;
    for (WebElement element : elements) {
        NgWebElement ngElement = new NgWebElement(ngDriver, element);
        String optionName = ngElement.evaluate("option.name").toString();
        // switch to core Selenium
        WebElement element2 = element.findElement(By.tagName("span"));
        assertThat(element2, notNullValue());
        String classAttribute = element2.getAttribute("class");
        // System.err.println( "option.name = " + optionName + " " +
        // classAttribute);
        matcher = pattern.matcher(classAttribute);
        if (matcher.find()) {
        } else {
            System.err.println("selected: " + optionName);
            highlight(element);
            count++;
        }
    }
    elements = ngDriver.findElements(NgBy.repeaterColumn("country in SelectedCountries", "country.name"));
    assertTrue(elements.size() == count);
    elements.stream().forEach(element -> System.err.format("%s\n", element.getText()));
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) 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)

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