ATF is a browser automation solution researched and developed at Errigal.
What is it?
ATF is a ZERO dependency framework for quick browser automation, Web Testing, Screen Scraping and more.
It brings together the power of chrome's extensibility, the elegance of jQuery content selection and the expressiveness of the JS language.
It can be used for scripting, scraping and general automation-testing.
What does it look like?
Here's what a simple ATF script for logging into an admin section of a website,verifying and logging out might look likeā¦
test.start("example.com - Login as Admin")
window.location = "http://example.com/login/";
test.wait = 2000;
$('#username').val('admin')
$('#password').val('xxxx')
$('#loginForm').submit();
test.wait=2000;
test.assert("Test Valid title",document.title == 'Admin Section');
test.wait=8000;
$('#logout').click();
test.end()
Save the file as test.js. This is what is known as the scripting style of ATF and it's great for quick automation. That's it! No more messing around with XML files and having an entire project with classes all around the place with a gazillion dependencies. Everything you need to run ATF is here in this repository.
Run ATF
$ ./atf /path/to/test.js > Started ATF > Sending Commands...
Note: Make sure you don't use the browser while the ATF script is running, You don't want to trigger any unwanted on[click/move/drag etc] event. You should be able to see all your output in the terminal.
ATF Methods
You have to remember only five self-explainatory methods:
test.start("Your Test Name")
test.wait=3000;
test.assert("Test equality",1==1);
test.tprint("you will see this in the terminal")
test.waitTillExpression("Test title",()=>{return document.title=='Dashboard'},5000); //wait N millisecs. for a given function to return true
test.waitForElement("Check if Element exists",'#logo',5000); // //wait N millisecs. for an element to load
test.end()
Execution style: batch or individual
ATF can execute your script either in batch mode(for speed) or individually one after the other.
Well, how do we configure this?
Let us look at the same code again:
test.start("example.com - Login as Admin")
window.location = "http://example.com/login/";
test.wait = 2000;
$('#username').val('admin')
$('#password').val('xxxx')
$('#loginForm').submit();
test.wait=2000;
test.assert("Test Valid title",document.title == 'Admin Section');
test.wait=8000;
$('#logout').click();
test.end()
Batching is simple, Command batches are separated by a semi-colon.
- Lines 1,2 run as one batch. - Line 3 is an individual command. - Lines 4,5 and 6 are one batch. - Lines 7,8,9 and 10 are individual commands.
How is this useful?
This is very useful when you don't want to run the commands immediately following the emulation of a form submit or link click and would want them to be executed following the next page load. For safety, always use the commands individually, separating each with a semi-colon.
Global Scope, variables and functions
Anything that goes before the first test-case is available to all test cases and in all sub-sequent page loads. Note that these variables and functions are meant to be immutable and read-only by default and should be treated as such.
Note: normal JS doesn't behave this way. The variables don't last another page load and are completely mutable. ATF provides this functionality for convinience.
Test Scope Every variable and function that you define must be within the `test` scope. This is to prevent any unwanted overriding of variables or functions in the webpage.
Example:
test.a = 10;
test.customGetTitle = function(){
return document.title;
}
Note: Do not override any pre-defined keywords. The list of keywords are given below: