samoretc / ngWebDriver

AngularJS and WebDriver bits and pieces for Java

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ngWebDriver

A small library of WebDriver locators and more for AngularJS.

Status

We have taken JavaScript from Angular's Protractor project. While ngWebDriver perfectly compliments the Java version of WebDriver, it has to pass JavaScript up to the browser to inteoprate with Angular, and the Protractor project has done the hard work (including testing) to make that solid, and ngWebDriver benefits from that work.

You can use ngWebDriver today with the regular Java Selenium2/WebDriver libraries. You can also use it with FluentSelenium for extra terseness.

Waiting for Angular to finish async activity

new NgWebDriver(driver).waitForAngularRequestsToFinish();

Do this if WebDriver can possibly run ahead of Angular's ability finish it's MVC stuff in your application.

Locators

repeater()

As Protractor's repeater locator

ByAngular.repeater("foo in f")
ByAngular.repeater("foo in f").row(17)
ByAngular.repeater("foo in f").row(17).column("foo.name")
ByAngular.repeater("foo in f").column("foo.name")

exactRepeater()

As Protractor's exactRepeater

ByAngular.exactRepeater("foo in foos")
ByAngular.exactRepeater("foo in foos").row(17)
ByAngular.exactRepeater("foo in foos").row(17).column("foo.name")
ByAngular.exactRepeater("foo in foos").column("foo.name")

binding()

As Protractor's binding locator

ByAngular.binding("person.name")
ByAngular.binding("{{person.name}}")
// You can also use a substring for a partial match
ByAngular.binding("person");

exactBinding()

As Protractor's exactBinding locator

ByAngular.exactBinding("person.name")
ByAngular.exactBinding("{{person.name}}")

model()

As Protractor's model locator

ByAngular.model('person.name')

options()

As Protractor's options locator

ByAngular.options("c for c in colors")

buttonText()

As Protractor's buttonText locator

ByAngular.buttonText("cLiCk mE")

partialButtonText()

As Protractor's partialButtonText locator

// If you have a button name "Click me to open", using just "click" would do if you partialButtonText
ByAngular.partialButtonText("cLiCk ")

cssContainingText()

As Protractor's cssContainingText locator

ByAngular.cssContainingText("#animals ul .pet", "dog")

Angular model interop

As with Protractor, you can change items in an Angular model, or retrieve them reagrdless of whether they appear in the UI or not.

NgWebDriver ngWebDriver = new NgWebDriver(driver);
// change something via the model defined in $scope 
ngWebDriver.mutate(wholeForm, "person.name", "'Wilma'");
// Note Wilma wrapped in single-quotes as it has to be a valid JavaScript 
// string literal when it arrives browser-side for execution 

See also retrieveJson, retrieve, retrieveAsString and retrieveAsLong for getting Angular data back from the browser.

Other Functions

getLocationAbsUrl()

Returns the URL of the page.

String absoluteUrl = new NgWebDriver(driver).getLocationAbsUrl();

Code Examples

All our usage examples are in a single test class:

Including it in your project

Maven

<dependency>
  <groupId>com.paulhammant</groupId>
  <artifactId>ngwebdriver</artifactId>
  <version>0.9.4</version>
  <scope>test</scope>
</dependency>

<!-- you still need to have a dependency for preferred version of 
  Selenium/WebDriver. That should be 2.48.2 or above -->

Non-Maven

Download from Mavens Central Repo

About

AngularJS and WebDriver bits and pieces for Java

License:MIT License


Languages

Language:Java 51.3%Language:JavaScript 35.3%Language:HTML 12.1%Language:CSS 1.1%Language:Shell 0.2%