Travis CI Automated Testing
Travis CI is a continuous integration service which you can easily use to test your GitHub projects.
It is very easy to use the TestingBot Selenium grid together with Travis CI.
Below are the steps to run your Selenium tests via Travis CI, once the tests are up and running you can even display a TestingBot Status badge showcasing your Selenium tests status.
1. Get Travis CI up and running
Sign up at Travis CI and connect your GitHub project with Travis CI.
You can find information on how to do this at the Travis CI help section.
2. Create a simple Selenium test
Add a simple Selenium test to your GitHub project, modify the .travis.yml
file in your repository to indicate you want to run a Selenium test.
Example .travis.yml
file:
language: node_js
node_js:
- 0.8
env:
- [
{secure: "akuE0dld1Ke9mahjUUrQhUZRYWasdfewfwefewfZlbvOx\nqaPybirPGsDmImvcktaAkjLxpePd0V1+ak+4dws7dTrFfEsdvsdsdvsdvds2\nud1q5oGOzEqfiRGxY/fJHLWlaQ609Bsdfdsfds2VeY1Z/V7N9iQ="},
{secure: "JGfkAfr/SOlzV+NpgNi3fxP4F2usdfdsveGAppugHj1IxhoyjY\nOp07x4p1hdIfWVF03RqUrPNXkl72+yh53pv2fUzsdfsd3434GRjGy6J6\notuA/N+xs0+TP2ENlCmDauwO32Okfojvj7CgvsdfdsfRyaFzIGWPdw="}
]
script:
- "node tests/examples/*.js"
The two secure lines in the above example are your TestingBot key and secret, used to run a test on our Grid.
To generate these 2 lines, you need to install the Travis CI gem and run these commands with your own key and secret:
travis encrypt username/projectname TESTINGBOT_KEY=my_key
travis encrypt username/projectname TESTINGBOT_SECRET=my_secret
Now you can use the encrypted TESTINGBOT_KEY
and TESTINGBOT_SECRET
environment variables in your tests.
Below is a NodeJS example:
var webdriver = require('selenium-webdriver');
async function runSampleTest () {
let driver;
try {
driver = new webdriver.Builder().
withCapabilities({
'browserName': 'chrome',
'platform': 'WIN10',
'version': 'latest',
'client_key': process.env.TESTINGBOT_KEY,
'client_secret': process.env.TESTINGBOT_SECRET,
'name': (process.env.CI_JOB_ID ? ("GitLab Build " + process.env.CI_JOB_ID) : "Simple Test")
}).
usingServer("https://" + process.env.TESTINGBOT_KEY + ":" + process.env.TESTINGBOT_SECRET +
"@hub.testingbot.com/wd/hub").
build();
await driver.get('https://www.google.com');
var title = await driver.getTitle();
console.log("title is: " + title);
} catch (e) {
console.log(e);
} finally {
if (driver) {
await driver.quit();
}
}
}
runSampleTest();