Building a CI System Using Selenium Builder, GitHub, Travis and Sauce Labs
Sauce AI for Test Authoring: Move from intent to execution in bit.|xBack to ResourcesBlogPosted March 12, 2013
Building a CI System Using Selenium Builder, GitHub, Travis and Sauce Labs
Today I & # x27; m going to show you how you can use Selenium Builder withGitHub, Travis, and Sauce Labsto make a uninterrupted integration answer for your website that & # x27; s all on the Internet, zero stored locally. You can either postdate along with the demo picture below or say on for the written tutorial. The outstanding thing about this setup is that if you put your site codification and your tests into the same GitHub depository, then whenever you update the site code, and whenever you update the tests, Travis will rerun your Selenium tests on Sauce OnDemand - and then send you an email about whether or not they however work!

So you can get a total Selenium CI solution by putting together these components. And because they & # x27; re all components, if you want to use something else in part - for example Jenkins instead of Travis - you can construct your own solution. For now I & # x27; m going to show you this set of four things that work really well together. The great thing about this is that you store everything on GitHub, so all your tests are stored in the cloud, nothing is stored on some local machine somewhere. You can record and redact test from any computer that lead Firefox. You can access your test, cut them, & amp; play them back topically. And all of the existent execution of the testing - the CI - is handled by Travis and Sauce. So you actually don & # x27; t need to build any of your own testing base!
OK! So how do you actually do this?
The inaugural thing you need to do is install the plugins. You go into Selenium Builder, you go into Plugins, and you but tick install on GitHub integration and Sauce. Restart Builder.

Adjacent up, you need to record some tests. Let & # x27; s just say for now we & # x27; re testing this site.
Let & # x27; s record a check.
Now we & # x27; re depart to save this exam. In the File menu, save the exam to GitHub.
Because this is the 1st time we & # x27; re apply it, I & # x27; m going to have to enter my detail.
Now, as you can see, we can admission our secretary. And I & # x27; ve set up this small repo here as an exemplar one.
So let & # x27; s save this exam in hither, as JSON, which is the standard formatting Builder works in. This means we can later open it again and edit it.
Let & # x27; s do another exam.
Now we salvage that one as well. Just record as many test as you want and put them all into this place.
Now we & # x27; ve do that, the next thing we need to do is configure the Selenium interpreter, which is really a slight node.js program that occupy these JSON scripts and uses Webdriver to play them back. Let & # x27; s clone the repo to disk so we can add the config files we need.
Create a new text file. I & # x27; ve just glue in a cluster of things, which are actually reasonably straightforward.
The config is a JSON file that contains two things: the settings that you desire to run the tests (in this event, we want to run them on Firefox) and if you want to run them on Sauce Labs & # x27; infrastructure. You experience to tell Sauce your username and admittance key before this can happen, but it & # x27; s not a good idea to perpetrate your Sauce access key to a GitHub repository. So instead, we & # x27; re go to put the username and access key into environment variables. As long as we run the interpreter with the SAUCE_USERNAME and SAUCE_ACCESS_KEY environment variables set to the right values, it will work fine. And how we set those variable, we & # x27; ll get to in a moment, as that will be in the Travis configuration. Here we have the tests we actually want to run. This config format supports glob syntax, so you don & # x27; t have to list each test individually. Just put in the path to the directory with an asterisk at the end, and it will find the tests. And it will ignore anything that & # x27; s not a JSON file. That & # x27; s the entirety of the config, so let & # x27; s save that in our repo.
And commit and push it.
Now the next thing we need to do is to tell Travis that we live, and that we would like to use its services.
You can log yourself in ...
SUSA automates exploratory testing with persona-driven behavior, catching bugs that scripted automation misses.
... using your GitHub report.
And then you go in hither ...
... and you enable Travis consolidation for this particular repo.
OK. Now the final step is to configure Travis. We need to tell Travis what running an integration test for this particular project actually imply. That & # x27; s done by putting a file into the top level of the depositary, which tells Travis what to do. It & # x27; s called .travis.yml. So again, I & # x27; ve just pasted in something.
Now we state it to install the Selenium representative, and so run it with the configuration we already made. And the one thing we & # x27; re lacking hither is the environment variable for the Sauce access key. Setting variables in Travis is easy if you don & # x27; t mind them be public, which you probably don & # x27; t mind for your Sauce username. Now this is the one tricky bit in this tutorial. You involve to encrypt your access key to let Travis know what it is without revealing it to the world. The way to do that is to first instal a Ruby gem.
Once that & # x27; s installed, get sure you & # x27; re in the depositary you require to inscribe something for and log in to Travis.
Then you can use this command to encrypt an environment variable.
What comes out is a blob of encrypted data ...
... which you can glue into the .travis.yml config file like this. The encrypted data is bind to your git credentials and this particular repo, so it should be safe from snooping or theft. Your access key should also be safe. If it does always become compromised, you can also generate a new one. That & # x27; s what I & # x27; ll be doing in a few minutes.
Now you can save this file ...
... commit it, and push it. And of course this means Travis now goes & quot; Oh, this has be force to! OK, is thither a .travis.yml? Yeah, there is. & quot;
Let & # x27; s really go onto Travis. We can see it & # x27; s in the queue right now.
Ok, full, it & # x27; s go the examination.
You can see the detail of each test being run.
But you don & # x27; t need to know any of the details, because in the end, we get an e-mail aver, & quot; Hey! It & # x27; s succeeded, everything & # x27; s ticket! & quot;
So I & # x27; ll only establish you what happens if you break thing. You can edit these JSON scripts with a text editor, which is pretty leisurely.
Let & # x27; s go in hither and modify this verify to something that & # x27; s not really the case.
Save, commit, and push, and Travis scat again.
And now we get recount that the build is break! One of our exam failed!
So let & # x27; s fix the test up again.
Save, commit, energy.
And short after, Travis tells us that we & # x27; ve bushel the build. Excellent.
That & # x27; s all really - you can use these four components to make a continuous integration system for your site. If you have any questions, drop Adam or me an e-mail.
Thanks for follow along!
Automate This With SUSA
Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed.
Try SUSA FreeTest Your App Autonomously
Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.
Try SUSA Free