Angular.js for the testing goat: Utilities for testing Angular.js applications with Selenium for Python.
Unfortunately, due to lack of time and a switch to robotframework-extendedselenium2library this project has been abandoned. Please contact me if you want to take over.
pytractor is an extension to the Selenium bindings for Python. Its goal is to make testing of angular.js applications easier with Python.
It is built on some parts of protractor, the "official" Javascript E2E/Scenario testing framework for Angular.js.
It is assumed that you are familiar with with the Selenium bindings for Python.
Drivers containing the helper methods for testing Angular.js can be found in the pytractor.webdriver
module.
The constructor expects the base URL of your application.
from pytractor.webdriver import Firefox driver = Firefox('http://localhost:8080/base_url')
The base URL will be prepended to each URL you pass to the get()
method (using urlparse.urljoin(base_url, get_url)
).
The constructor also accepts the parameters:
root_element
- A selector for the DOM element that is the root of your Angular.js app (default:
'body'
). script_timeout
- The amount of seconds (default: 10) to wait for a script executing asynchroneously (see selenium's
set_script_timeout()
. test_timeout
- The amount of seconds (default: 10) to wait for the script which verifies whether Angular.js is indeed used on the page.
If no Angular.js app can be found, get()
will raise an exception.
The usual selenium webdriver methods can be used, but pytractor will wait for Angular.js to finish processing for some of them.
The find_element(s)_by_binding()
methods retrieve the element(s) which use the specified binding.
Suppose your Angular app contains a binding of the form
<div>{{my_binding}}</div>
Then you can locate the <div />
with
driver.find_element_by_binding('my_binding')
find_element(s)_by_binding()
will also find elements if only part of the binding
name is specified.
In other words, the binding
<div>{{my_binding}}</div>
can be found with
driver.find_element_by_binding('my_bind')
If you want to locate the binding by its exact name, use
find_element(s)_by_exact_binding()
.
find_element(s)_by_model('model_name')
can be used to locate elements that
use the expression ng-model="model_name"
.
Suppose you have the element
<input type="text" ng-model="person.name">
then the <input>
element can be found with
driver.find_element_by_model('person.name')
find_element(s)_by_repeater('item in list')
can be used to locate elements that
use the expression ng-repeat="item in list"
.
refresh()
will perform a full reload of the current page. It assumes that
the page uses Angular.js.
set_location(url)
will use the in-page navigation (just as $location.url()
).
The location_abs_url
property will retrieve the absolute URL from angular.
- Button text, and options locators.
- Script/mock module injection.
pytractor is licensed under the the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0
protractor is Copyright (c) 2010-2014 Google, Inc. and licensed under the MIT license. See the respective directory for a copy of the license.
Credits for the client-side scripts go to the protractor project for their fine framework.