mkdir automation
cd automation
stig init
stig
BrowserStig requires a browserstig.conf.js to be in the same directory that you run the "stig" CLI. The following options are supported:
browserstig.js is automatically included in the BrowserStig automation environment. This gives you access to the BrowserStig global in any of your js or coffee files that you include. However, you could also include browserstig.js standalone in any project.
var stig = new BrowserStig();
var stig = new BrowserStig({
initialUrl: '/someurl', // defaults to '/'
waitForElementTimeout: 30000 // The length of time (ms) to search for an element before timeout
});
stig.open('/search');
stig.open('/search');
stig.el('#searchbox').type('Dockers Jeans');
stig.el('#go-button').click();
stig.el('.search-result:first').text( function(text) {
assert(text.indexOf('Skinny Jeans') !== -1);
});
stig.run();
...
stig.run( function() {
console.log('I'm done!');
});
stig.setCookie('authtoken=j43JasHlsa');
stig.el('#button').click();
stig.el('#search').type('Books by J.K. Rowling');
stig.el('#search').type(BrowserStig.keyCodes.ENTER);
stig.el('.dropdown').hover();
stig.el('#input').value( function(value) {
assert(value === 'The text I entered');
});
stig.el('li').count( function(count) {
assert(count > 10);
});
stig.el('title').text( function(text) {
assert(text.indexOf('Amazon') !== -1);
});
stig.el('.content').get( function(el) {
assert(el.html().indexOf('title') !== -1);
});
Although BrowserStig may be used for other automation purposes, it's main purpose is to be used for functional testing. As mentioned before, you can use browserstig.js standalone without the cli. This would allow you to import browserstig.js into any javascript testing framework. However, the stig cli is designed to help you start testing immediately with minimal setup.
If you have used the karma test runner, you will be familiar with the stig cli. Really, the stig cli just wraps the karma test runner. The supported test styles are 'mocha', 'jasmine' and 'qunit'. However, this documentation only covers testing with mocha.
After running "stig init", your project will be initialized with a browserstig.conf.js and a main.js file. main.js is the first file that will be loaded into the browser. In this file we setup mocha to give a much longer timeout for tests. This is because functional tests usually take much longer to run than your typical unit test:
mocha.setup({timeout: 30000});
We also setup a "stig" global to be initialized before each test:
beforeEach(function ()
stig = new BrowserStig();
});
We can now use the "stig" global in any of our tests. The following test is included in main.js by default:
describe('Amazon Test', function () {
it('should get a result from the search', function (done) {
stig.open('/');
stig.el('#twotabsearchtextbox').type('node.js');
stig.el('.nav-submit-input').click();
stig.el('.newaps:first .lrg.bold').text(function (text) {
console.log('First Result: ' + text);
assert(text.length > 0);
});
stig.run(done);
});
});
The most important thing to notice is that the test uses the asynchronous features of mocha. This is why the test function accepts a "done" callback that gets passed to the stig.run function. This tells mocha to wait for the test to finish all the way before moving on to run the next one.
This test is included directly in the main.js file, but it is best to distribute your tests in multiple files. This can be easily accomplished by setting the files property in your browserstig.conf.js. For example, if you wanted to run all of the tests in all of the js files beneath the "tests" directory of your project:
...
files: [ 'tests/**/*.js' ],
...
Here is a pre-configured sample project that you may want to use to help you get started.
Please log any other issues on github