Ultron is a JavaScript/NodeJS library for creating automated tests running on the browser of your choice.
var Ultron = require('ultronjs');
var ultron = new Ultron('chrome'); // open Chrome
ultron
.it("should open GitHub via Google")
.describe(function() {
this.open('http://google.com');
this.wait('input[type="text"]').toAppear();
this.fill('input[type="text"]').with('GitHub');
this.$('input[type="text"]').submit();
this.wait('#ires').toAppear(); // results container
this.click('#ires a[href="https://github.com/"]'); // first result
this.wait.until.titleContains('GitHub');
this.wait.for(1000); // wait for just a sec
})
.run()
.then(function() {
ultron.end(); // close browser
});
$ npm install ultronjs
# or
$ npm i -D ultronjs
You also need to download and include in your PATH the driver of the browser of your choice in order to use Ultron.
- Chrome: http://chromedriver.storage.googleapis.com/index.html
- Firefox: https://github.com/mozilla/geckodriver/releases/
- Internet Explorer: http://selenium-release.storage.googleapis.com/index.html
- Safari: http://selenium-release.storage.googleapis.com/index.html
- Opera: https://github.com/operasoftware/operachromiumdriver/releases
Table of Contents
Test.open(url)
url
{string} - The url to open in the browser.
new require('ultronjs')
.it("Should open GitHub")
.describe(function() {
this.open('http://github.com');
})
Test.wait(selector)
selector
{string} - CSS selector of the target element.
toAppear()
- Waits until the element appears.
new require('ultronjs')
.it("Should wait for the search input")
.describe(function() {
this.wait('#search-input').toAppear();
})
until.titleIs(text)
- Waits until the title matches the given text.
new require('ultronjs')
.it("Should wait until the page title contains the word GitHub")
.describe(function() {
this.wait.until.titleIs('GitHub');
})
until.titleContains(text)
- Waits until the title of the page contains the given text.
new require('ultronjs')
.it("Should wait until the page title is GitHub")
.describe(function() {
this.wait.until.titleContains('GitHub');
})
for(milliseconds)
- Waits for the given time in milliseconds.
new require('ultronjs')
.it("Should wait for 2 seconds")
.describe(function() {
this.wait.for(2000);
})
Test.fill(selector)
selector
{string} - CSS selector of the target element.
with(text)
new require('ultronjs')
.it("Should fill GitHub search input with `UltronJS`")
.describe(function() {
this.fill('input[name="q"]').with('UltronJS');
})
Test.Click(selector)
selector
{string} - CSS selector of the target element.
new require('ultronjs')
.it("Should click link to GitHub")
.describe(function() {
this.click('#ires a[href="https://github.com/"]');
})
Test.page.title
should.contain(text)
- text {string}
new require('ultronjs')
.it("Should find the word GitHub in page's title")
.describe(function() {
this.page.title.should.contain('GitHub');
})
findElement.by.linkText(text)
- text {string}
click()
new require('ultronjs')
.it("Should find and click the link of UltronJS repository")
.describe(function() {
this.page.findElement.by.linkText('masterakos/ultronjs').click();
})
Test.$(selector)
- selector {string} - Css selector of the target element.
submit()
new require('ultronjs')
.it("Should submit the search form")
.describe(function() {
// submit by selecting the form
this.$('form').submit();
// or by selecting an input inside the form
this.$('input[name="q"]').submit();
// or by selecting the submit button
this.$('button[type="submit"]').submit();
})
should
count(number)
new require('ultronjs')
.it("Should find 4 links to the page")
.describe(function() {
this.$('a').should.count(4);
})
haveContent(text)
new require('ultronjs')
.it("Should find the right content in body element")
.describe(function() {
this.$('body').should.haveContent(`Browser Automated Testing library`);
})