Run Your Selenium Tests Completely in the Cloud Using Travis CI and Sauce Labs
Sauce AI for Test Authoring: Move from intent to execution in minutes.|xBack to ResourcesBlogPosted
Sauce AI for Test Authoring: Move from intent to execution in minutes.
|
x
Blog
Run Your Selenium Tests Completely in the Cloud Using Travis CI and Sauce Labs
This is a quick tutorial to get you started running automated tests altogether in the cloud as part of your development process usingTravis CIand real browsers in. As a dago pig during this blog post, I used a pocket-size, open source Python project of my own calledcssify. You can bump the cssifybuild results on Travisand even watch running jobs or videos of the browsers in activeness in the project & # x27; s. Steps involved:
Set up your tryout to run on Travis CI
Configure Travis CI to commence Sauce Connect
Configure your Selenium tests to run on Sauce Labs
Provide additional details to Sauce
What is Travis CI?
Travis CI is a hosted continuous consolidation service for the open source community. It is integrated with GitHub and offers first class support for: C, C++, Clojure, Erlang, Go, Groovy, Haskell, Java, JavaScript (with Node.js), Perl, PHP, Python, Ruby and Scala. Their CI environment provides multiple runtimes (e.g. Node.js or PHP versions), information stores and so on. Because of this, host your project on Travis means you can effortlessly test web covering against multiple runtimes and data fund without even having all of them instal topically.
Setup Your Tests to Run on Travis CI
There & # x27; s multiple tutorials out there to get started employ Travis CI. One of my favorite thing about Travis is how easy it is to configure and get started. Check out theofficial Travis CI medicoto get started in your own scheduling lyric. For running your Selenium tests, remember to install the right dependencies, including the Selenium client bindings,like I didin my project. Also, make sure you make Travis commence your webapp before the tests start. Your application want to be serving pages to be able to test it utilize our browsers:)
Configure Travis CI to Start Sauce Connect
For autonomous testing across multiple user personas, check out SUSATest — it explores your app like 10 different real users.
Sauce Connect make a magical rainbow burrow that will allow the Sauce browsers driven by your Selenium tests to access the Web Application that your Travis anatomy showtime. Once a Sauce Connect tunnel is scarper, browsers in our cloud can use it to hit localhost, interior IPs or even to merely proxy the public internet through the correct localisation. I & # x27; ve created amodest Bash handwritingthat takes care of downloading, starting and look for Connect to be ready. To use Sauce Connect in your build, all you need to do is curl and run this playscript in your .travis.yml before_script section asI did in my project:
before_script:
Configure Your Selenium Tests to Run on Sauce Labs
Once your figure are happily running and Sauce Connect is started automatically by Travis, the succeeding step is having your Selenium hand run in the Sauce Labs cloud and hit the Application Under Test (AUT) through the tunnel. To start running real browsers in the Sauce Cloud, create your scripts useRemote WebDriverand show the command executor tolocalhost:4445(Sauce Connect will listen in that port and securely and efficiently relay to Sauce). You can find an example of thison the cssify codebase.
self.username = os.environ [& # x27; SAUCE_USERNAME & # x27;]
self.key = os.environ [& # x27; SAUCE_ACCESS_KEY & # x27;]
hub_url = & quot; % s: % s @ localhost:4445 & quot; % (self.username, self.key)
self.driver = webdriver.Remote (desired_capabilities=self.caps,
command_executor= & quot;http: // % s/wd/hub& quot; % hub_url)
Now for these browsers to be able to hit the AUT when opening localhost, you want to specify an additional Desired Capability,. The value this capability should be set to is stored in the environment variableTRAVIS_JOB_NUMBER. You can find anexample in the cssify codebase for this as well.
self.caps [& # x27; tunnel-identifier & # x27;] = os.environ [& # x27; TRAVIS_JOB_NUMBER & # x27;]
Provide Additional Details to Sauce
In addition to running your tests in existent browsers using the cloud, there & # x27; s extra details you can provide to rush up debugging and navigating test results. Inthe cssify testsyou can detect some examples Desired Capabilities that Sauce uses and that you can pull from Travis CI & # x27; s environment variables.
self.caps [& # x27; build & # x27;] = os.environ [& # x27; TRAVIS_BUILD_NUMBER & # x27;]
self.caps [& # x27; tags & # x27;] = [os.environ [& # x27; TRAVIS_PYTHON_VERSION & # x27;], & # x27; CI & # x27;]
That & # x27; s it!
You & # x27; re set! You are now running your tests using Travis CI, they start a Sauce tunnel on their own and drive real browser in the cloud. Time to get cerebrate aboutrunning these in parallelto speed up your builds now! Here are examples of whatyour Travis CI buildshould look and what you & # x27; ll see.
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