Ape is a library to make selenium tests easy, providing some utilities and using conventions to make your tests easy to write and read.
git clone git://github.com/andrerigon/ape.git
cd ape
mvn install
create your test and extend SeleniumBaseTest. This allows you to use several assertions like:
assertPresent(String elementLocator)
also you can use the raw api to manipulate elements of the page:
on(String elementLocator).click()
or you can even access selenium driver directly
selenium()
After extend SeleniumBaseTest, you have to provide information about the selenium driver. To do that, just annotate your test (or your base test) with:
@SeleniumDriverConfig(baseURL="http://base", host="http://mySeleniumRCURL", browser="*firefox", port = "1234")
If you don’t want or don’t have setup a selenium RC server, just use:
@SeleniumDriverConfig(useEmbbebedSeleniumRC = true)
and a instance of SeleniumRC will be created for you.
If you want your tests windows to be maximized, use:
@MaximizedBrowserWindow
To slow down selenium action commands, just define a diferent delay:
@SeleniumActionDelay(delay = 500, timeUnit = TimeUnit.MILLISECONDS)
When a test fail, the firefox browser closes and its difficult to know in what state the page was.
To help, ape generates an screenshot of the page at the error moment in the /tmp directory.
The name of the file is:
screenshot_<test class name>_<mehtod name>.png
If yout want to change the default dir, just annotate your test with:
@ErrorScreenshotPath("my new path")
When running your tests, frequently (all the time?) your test need to login in the system.
To simplify that, take the following steps:
- make you test or base test to implements AuthenticatedTest
- define a junit rule:
@Rule public final AuthenticationRule visaoLoginRule = AuthenticationRule.defaultUserAndPasswd("test_user", "123");
- annotate your test methods with @Authenticate
If you want to use another credentials, define them in the @Authenticate:
@Authenticate(username="test_user2", password="456")