Posts Tagged ‘sauce ondemand’

Security Through Purity — Bypassing the Red Queen

September 27th, 2011 by jeremy avnet .:. brainsik

As a cloud service, Sauce Labs uses quite a few virtual machines to run our browsers. With Windows images taking about 15 minutes to boot in EC2 and other cloud providers, the most efficient way to use these resources is to cleanup between customers and reuse. Unfortunately, reusing VMs paves a path for malicious users to install software that will continue to run while other customers use them. This means sensitive data could be captured and sent to a 3rd party or, even worse, a 3rd party could gain access to a customer’s internal network if they are testing with a tunneling service.1 How can a VM be protected from malicious software installation?

There are a variety of tools one can use to lock down Windows. The tools provided by Windows itself are the Software Restriction Policy and AppLocker technologies. And a cursory Google search will reveal current dll load hijacking methods for getting around them. The reality is it’s a Red Queen race between securing a system and finding a new exploit — “It takes all the running you can do, to keep in the same place.” For all intents and purposes, it’s like submitting your laptop to a hacking contest. Is there anything you could do to feel comfortable using it again?

the only winning move is not to play

Like Joshua learned, “the only winning move is not to play,” and that’s how we roll at Sauce Labs. Every single session, whether you’re using Scout or OnDemand, gets a fresh VM that’s never been used by anyone else.2 At the end of your session — whether it’s 10 minutes or 10 seconds — the VM (with all its data) is completely destroyed. By avoiding the unsolvable problem of guaranteeing a system secure across anonymous use, we instead guarantee a system that has never and will never be used by any customer besides you.3

A desirable side-effect of the Security Through Purity model is increased reliability. By always using pristine VMs for every session, every session is run with the same settings. This avoids intermittent failures that arise from the OS being in a state dependent on what the previous users did.

At Sauce Labs core is the ability to offer secure, remote browsers to our customers. Our attention to security provides confidence you can test any part of your external or internal services without having to build and manage your own browser testing infrastructure.

  1. Did you know you can use Sauce Labs to test your internal network? Check out Sauce Connect for secure way to use our cloud service to test your internal infrastructure. It’s been vetted by a well-known financial institution, a well-known domestic airline, and a variety of other high-profile customers.
  2. In this way, Sauce Labs has lunched nearly 1.3 million VMs in the last 30 days.
  3. Since we give you a fresh VM in under 20 seconds, a 15 minute boot time would require us to keep a lot of expensive, idle resources around to handle demand spikes. That’s why we developed a cloud technology which allows us to cold boot VMs in under 40 seconds. Aside from meaning demand spikes are handled with minimal delay, this also means there is no additional expense for providing the best security.
Share

Sauce Mac OS X Private Beta Signup!

August 23rd, 2011 by Jason Huggins

From the creation of Sauce OnDemand to the recent release of Sauce Scout, the most popular feature request from users has been OS X support. Well, we’re stoked to say that the wait is almost over. We are readying a very early version of Mac OS X support in our browser testing cloud.

(In case you’re wondering, we will resist the incredible temptation to call this new offering “apple sauce”).

If you’re willing to give us tons of feedback, and will be patient with growing pains, please sign up!

Like the rest of our cloud testing services, each Mac OS X session will include the browser testing features you’re familiar with. You’ll get a video of each session, and can take screenshots at any time. With every new test session, you get a clean-slate, freshly booted machine to control. And when the session is over, we delete the virtual machine, so there’s no lingering data left behind on the machine to worry about.

The Mac OS X private beta will initially be limited due to available systems and we’ll contact you as resourcing permits. First priority will be given to corporate users.

In you’re interested in joining the beta, complete the sign-up form, and we’ll email you soon with details.

Share

Appeasing the Butler or The Commit Heard Round the Company

June 28th, 2011 by joe

Sauce Labs does not employ any artists

 

This is what our build looked like. He was not happy. Notice how his eyes are red. That’s because of failing tests, which as we know turn builds red. These failing tests weren’t normal failing tests, which are actually pretty happy, because they are telling you how to fix your broken stuff. No, these tests were intermittent. That’s largely the fault of the fact that they were selenium tests – go figure, the selenium shop that sells selenium as a service is having selenium issues, lol (but sadface).

Well, to get out of sadfaceland, we dug into one of the sadtests and saw something surprising. It was a case of selenium looking for an element before it appeared. Wait, what? We already know how to fix that. In fact, we already told the whole world how to fix it: with spinning! Basically, the way a spinassert works is by trying the assertion over and over until it passes. This is a big deal with selenium because trying to interact with an element on a page before the page has loaded is a frequent source of flakey tests. We even went so far as to write Test::Right (source on github), a ruby test framework which goes out of its way to make it impossible for you to do write selenium tests without spin asserts. So what happened?

Well, we don’t use Test::Right for all our own tests. Test::Right is ruby and our tests are written in the same language as our back-end; python. And while we were using spin-style asserts for many of our tests, some of them were written before we discovered the magic of spinning, and some were written when we just didn’t remember to use spinning. Also, there were some things that were not assertions but still required spinning; like, if you want to click on an element in a page, it makes sense to spin-wait for that element to be present before clicking on it. Test::Right does the right thing in all these cases; we just had to be more like Test::Right in-house, to prevent sadness from creeping back into the codebase again.

So the fix was clear: modify our own test framework to always spin-wait all the time for every DOM element to show up, every time anyone tried to interact with a DOM element, automatically. We did that, and it made the butler happy. All of a sudden we could trust the build again, and it didn’t take hours to wait for a nonflakey build so that we could deploy new changes. This in turn meant that we never had to hotpatch production when there was an issue, which meant we didn’t have to spend time cleaning up hotpatches when a deploy happened. It also unblocked people who wanted to push new changes to trunk. Basically the whole dev process got better.

So here’s the thing – our customers are having the same issue. Not everyone uses Test::Right. We know this because we have a support team and customers contact us all the time asking for help with flakey tests. In our over 3,000 support requests, race-condition flakey tests are the #1 cause of pain. The shocker is that except for Test::Right (and now our own internal python nose framework), nobody has this universal fix.

So we’re hoping to make test frameworks for all the common languages – PHP, Java, Python, at least – that do what Test::Right did. We already have our own PHPUnit extension (thanks Jan Sorgalla!) which will probably be the first to get the Test::Right makeover.

Sadly, we are a focused team, and we have many tasks to accomplish, so this fix to selenium client libraries will likely not be imminently released by us. Thus we decided to at least tell you all how to Fix Everything on your own side. Now that I’ve done that, back to programming! Good night and good luck.

Share

JavaScript Unit Testing with Jellyfish and OnDemand

June 20th, 2011 by admc

Jellyfish logo

Web application testing turns out to be very similar to an onion. You keep peeling back layers and finding more testing that can, and probably should, be done. But you shouldn’t only be concerned with testing the smooth outer layer that your users will see.  There’s still plenty of automated testing to be done on those inner layers, and it doesn’t require much extra work.

The testing I’m referring to is the JavaScript unit tests. For most development teams, this is an incredibly important step and should be done well before using Selenium for testing web UI and user flows.

Most people think about Selenium as the “click” here, “type” there project. And for many intents and purposes, that’s correct. However, Selenium 2 is offering some new functionality that lends itself to a slightly bigger set of use cases. What I’m talking about is the ‘execute’ method. This allows you to execute arbitrary JavaScript in the AUT (application under test) scope, without having to deal with the frustrating complexities of ‘getEval’ in Selenium 1.

Specifically because of this functionality, I wrote a driver for Jellyfish (jelly.io), a framework that allows you to write node .js scripts that run JavaScript in the browser. In order to do this, I implemented a tiny subset of the WebDriver JSON wire protocol in node.js and called it ‘wd‘. These projects are interesting all in their own right, but to get straight to the point: If you have tests in FooUnit, QUnit or any other JavaScript testing framework that run in the browser, we now have a way for you to do all of that in the Sauce OnDemand cloud.

jelly_integration

For this example, lets use QUnit. In the hopes of covering all the bases, lets assume your QUnit tests are hosted on an internal web site to your company. Lets also assume that the way you currently run them is by opening a browser window and going to ‘file open’, or navigating to a local URL and sitting there watching the tests run. When they are done, you’ll manually look through the tests and results to decide if you broke things or not.

With Jellyfish and OnDemand, the way this now works is that you have a node.js script that runs after every check-in (perhaps by Jenkins) using different browser and platform combinations. When the tests are complete, an email will be sent to all your developers each time you have a failure.

architecture

So how do we do this?

Start by installing Jellyfish, the directions for which are front and center at jelly.io.

Next we will build a straightforward Jellyfish script that will start a Sauce Labs session, navigate to your QUnit tests URL, and assert the results when they finish.

For my examples, I am going to be using the full ‘JQuery Test Suite’ that I got from ‘jquery.com’.

Lets talk about the contents of the script one piece at a time:

var jellyfish = require('jellyfish')  
  , assert = require('assert');

 

This imports the jellyfish package and the assert module, which is a nice lightweight way to make assertions in node.js.

var sauce = jellyfish.createSauce();
sauce.opts.platform = "VISTA";
sauce.opts.browserName = "iexplorer";
sauce.opts.version = "9";

 

This instantiates a new Jellyfish object and lets it know that this one will be talking to Sauce Labs. The username and password for your Sauce Labs account can be passed through here directly, but in this case, I’m storing it in my ~/.jfrc file –, which is nice for simplicity. Next we’ll specify the platform, browser, and version we want to use to run our test (more information about .jfrc can be found here).

sauce.on('result', function(res) {  
  console.log(sauce.name + ' : '+sauce.tid + ' - \x1b[33m%s\x1b[0m', JSON.stringify(res));
});

 

This one is optional, but isn’t it nice to get well-formatted output in your logs?

sauce.on('complete', function(res) {  
  console.log(sauce.name + ' : '+sauce.tid + ' - \x1b[33m%s\x1b[0m', JSON.stringify(res));
  sauce.js("window.testOutput", function(o) {    
    try {      
      assert.equal(o.result.failed, 0);      
      sauce.stop(function() {      
        process.exit(0);    
      })  
    }    
    catch(e) {      
      console.log(e);      
      sauce.stop(function() {      
        process.exit(1);      
      })    
    }  
  })
});

 

This listener is very important since generally our communication with Selenium on Sauce OnDemand is one directional. However, that has been abstracted away. During the script, Jellyfish will poll Selenium every few seconds and ask ‘has window.jfComplete been set to true’? If so, an event will be triggered called ‘complete’. In the next section, you will see how the results are set, but at this point, I just have Jellyfish ask the page for the contents of ‘window.testOutput’. Next we assert the value of the number of failures. In this case, I am catching that exception so that I can print it to the terminal and exit the script with the correct return code for CI.

sauce.go("http://myurl.com/jquery/test/index.html")  
  .js("QUnit.done = function(res) {
    window.testOutput=res;
    window.jfComplete=true;
   }");

 

This is where the magic happens. This code navigates to the URL of the QUnit tests that start automatically, and as soon as we have navigated there, I redefine the QUnit done event to set the window.jfComplete flag. Then I set the results output of the test run in a place I can access it in the above code.

Usually the first question asked here is how to access QUnit tests that are on an internal network. Fortunately, we have a product at Sauce Labs called Sauce Connect that allows our cloud’s VMs to securely access whatever your test machines access on the internal network. It is incredibly simple to setup and you can do so by following the comprehensive documentation.

After that tunnel is running (you can just leave it running), you can now update the start URL in ‘sauce.go’ to reflect the URL you use internally to access your tests in the browser.

Jenkins has hooks for essentially any deployment platform or source control repository, and it also has post-deploy hooks that can be configured to send you an email. You can also use either a ‘matrix project’ or environment variables to make one job run your test on all of our available platform and browser combinations.

The example script can be downloaded here from github and I also made one of my Jellyfish QUnit test runs public for your viewing pleasure. Happy testing!

Share

Sauce Builder Webinar: From zero to creating, storing and running automated tests in under 30 mins

May 3rd, 2011 by The Sauce Labs Team



As you may have heard, we recently released a new, free tool that makes building and running Selenium tests easier than before. Sauce Builder is now available for download, and with it comes the ability to create Selenium tests in your Firefox browser by simply clicking around your application. You can then run those tests in Sauce OnDemand with just a few clicks, no Selenium expertise necessary.

To explain more about Sauce Builder and how automated testing can accelerate your development velocity, we held a webinar with Adam Christian, a Sauce Labs developer and project lead for Sauce Builder.

With Sauce Builder, we’re hoping to simplify and improve the cross-browser testing process for development and QA teams. Specifically, Sauce Builder will allow you to:

  • Build Selenium tests with zero programming - Simply click through your application and Sauce Builder writes a Selenium scripts that reflect your actions.
  • Export results in the language of your choice - HTML, JAVA, Groovy, C#, Perl, PHP, Python and Ruby so your tests speak the same language as your application and dev team.
  • Eliminate bugs faster - Use immediate video playback of your tests in action, and share them with your teammates.
  • Remove test infrastructure headaches - Sauce Builder makes it a snap to either run tests locally in Firefox or in the cloud with access to all the browser / OS combinations supported in the super scalable Sauce OnDemand service.

Share

Sauce Labs Eliminates Barrier to Automated Cross-Browser Testing with Sauce Builder

March 31st, 2011 by The Sauce Labs Team

New tool enables QA pros to build and run Selenium tests without Selenium expertise or infrastructure

SAN FRANCISCO, CA — (Mar. 31, 2011) – Sauce Labs, the web application testing company, today introduced Sauce Builder, a free testing tool that makes it easy for users to build Selenium tests without Selenium expertise and run them with the Sauce OnDemand service. Sauce Builder allows users to build automated Selenium tests simply by clicking through an application. By eliminating the complexity of hand-coding Selenium scripts, Sauce Builder accelerates the adoption of automated testing for QA and development teams that have been craving the development productivity Selenium offers. Sauce Builder is free and available for immediate download.

“Automated testing has historically been one of the most complicated, yet most valuable, technologies for companies that build software. Automated testing is doubly challenging because teams need to build and maintain a testing environment and on top of that, building tests can require significant technical skill,” said John Dunham, CEO of Sauce Labs. “We launched our Sauce OnDemand cloud service last year to eliminate the headache of maintaining a test infrastructure. Now with Builder, we’ve removed the next barrier to the adoption of automated testing and we’re very excited to see how this combination can help QA and development teams achieve their goals.”

With Sauce Builder, Sauce Labs continues to simplify and improve the cross-browser testing process for development and QA teams. Sauce Builder’s benefits include:

  • Build Selenium tests with zero programming – Simply click through your application and Sauce Builder writes a Selenium scripts that reflect your actions
  • Export results in the language of your choice – HTML, Java, Groovy, C#, Perl, PHP, Python and Ruby so your tests speak the same language as your application and dev team
  • Eliminate bugs faster – Use immediate video playback of your tests in action, and share them with your teammates
  • Remove test infrastructure headaches - Sauce Builder makes it a snap to either run tests locally in Firefox or in the cloud with access to all the browser / operating system combinations supported in the super scalable Sauce OnDemand service

With over four million downloads in just four years, the Selenium project is the world’s most popular functional testing framework for web applications. Designed to further expand Selenium adoption, Sauce Builder is the first web-based Selenium tool of its kind, including technology Sauce Labs acquired from Go Test It in 2010. After becoming more familiar with the technology post-acquisition, Sauce Labs elected to open source the code under the name “Se Builder” earlier this year because the technology held so much promise for the Selenium community.

Sauce Builder expands the capabilities of Se Builder by enabling users to directly access Sauce OnDemand, the cloud-based Selenium service, to run their tests. Sauce OnDemand is free to try for up to 200 testing minutes every month. Sauce Labs is also leading a collaborative effort with the Selenium community to deliver a new generalized plug-in architecture for Se Builder that among other things will support integrated plug-ins for testing services like Sauce OnDemand.

To learn more about how automated testing can accelerate your development velocity, please join Adam Christian,a Sauce Labs developer and project lead for Sauce Builder, on Tuesday, April 19th at 10AM Pacific for the webinar, “From zero to creating, storing and running automated tests in under 30 minutes”.

“Debugging takes up valuable time that developers could be using to focus on their applications,” said Sauce Labs’ Christian. “Now with Sauce Builder, developers can leverage this great development environment through our cloud testing infrastructure and not worry about dealing with building or maintaining their own costly testing infrastructure.”
About Sauce Labs
Sauce Labs, web application testing company, provides Sauce OnDemand, a cloud based service that allows users to run automated cross-browser functional tests faster and eliminating the need to maintain their own test infrastructure. To date, over four million Sauce OnDemand tests have been run in the Sauce cloud. The lead investor of Sauce Labs is the Contrarian Group, Peter Ueberroth’s investment management firm. Sauce Labs is headquartered in San Francisco, California. For more information, visit http://saucelabs.com.

Media Contact
Chantal Yang
LEWIS Pulse for Sauce Labs
sauce@lewispulse.com
415-875-7494

 

Share

Announcing Support for Internet Explorer 9 and Firefox 4 in Sauce OnDemand

March 15th, 2011 by Santiago Suarez Ordoñez

Here at Sauce Labs, we’re committed to keeping Sauce OnDemand, our browsers-in-the-cloud service, up to date with every new browser release. That’s why we’re especially thrilled to bring you fully supported IE9 and Firefox 4.0 browsers in the cloud, ready now for everyone – even free accounts – to use.  Also, at the end, for the do-it-yourself Selenium users, we share some of our “secret sauce” for installing these browsers.

Watch them running

Firefox 4 in the coud (see the full job in OnDemand):

Internet Explorer 9 (full job in OnDemand):

Use them yourself!

All you have to do is to create an account if you don’t have one yet, then start your Selenium RC tests using the right browser version and OS in the special Sauce browser string.
Of course you can find the browser string to use in our supported browsers page, but to save you some time, these are the ones you’re looking for:

"os": "Windows 2008", "browser": "firefox", "browser-version": "4"
"os": "Windows 2008", "browser": "iexplore", "browser-version": "9"
Notice: IE9 only runs in Windows Vista or later, so we’ve created new Windows 2008* VMs just for this! This means, though, that it’s important to provide “Windows 2008″ as the OS version requested.

This is how we did it

We founded Sauce Labs in part because we believe most people working on software testing have higher value uses for their time than maintaining test infrastructure.  And also because we believe in the power of open source to make a positive contribution.  So for those Selenium users for whom using Sauce OnDemand is not yet an option, we want to give back to the community and share the following How To section so those users can more easily install both FF4 and IE9 in their own test lab.

The following outlines how to configure and install both browsers.

Setting up Firefox 4

firefox 4 logo
To make Firefox 4 ready for Selenium testing we must ensure it is visible to Selenium.  Here’s how. Choose the Custom option during installation and make sure firefox is installed in C:\Program Files\Mozilla Firefox.

Selenium will find Firefox once it is installed in that location. No further configuration needs to be done, since Selenium takes care of the rest using its own custom profile.

Setting up Internet Explorer 9

ie9 logo

Internet Explorer 9 requires more work to set up. We’ve seen users having issues bringing up the browser as well as performing basic driving actions.

With the accumulated lessons learned from 4 million Selenium tests and counting, our VMs contain a series of registry edits that make Internet Explorer work like a charm with Selenium, as well as run tests faster.

We have made Sauce registry edits available in the their own public gist.  Please only follow these instructions if you are complete comfortable with the process and terms.  To run them just download the files and run the following from the command line:

From the administrator account in your test machine, enter:

regedit /s admin_regedits.reg

As the user running Selenium (may be the administrator user too):

regedit /s user_regedits.reg

Warning: The configurations resulting from these registry edits make should only be used to run in dedicated testing servers. Using them on a machine intended for everyday usage, such as checking email and working, will be a security risk.

If you run into problems with this setup, feel free to ask questions in our Sauce OnDemand forums or our Selenium forums (depending on whether you’re using our cloud service or setting this up locally). We do our best to answer any questions that come through. If you’re looking for faster and personalized responses, we do offer paid Selenium support packages, which give you access to our Selenium experts via phone, email, and chat.

* Windows Server 2008 RC1 is Microsoft’s server OS most closely related to Windows Vista (they have the same NT kernel version number).

Share

Why jQuery in Selenium CSS Locators Is The Way To Go

January 31st, 2011 by Santiago Suarez Ordoñez

You may not have heard about this, but a while ago, Jason Huggins moved Selenium 1′s CSS locator engine from CSSQuery to Sizzle, jQuery’s CSS selector library.

While this may not sound like a big deal to most users, it actually is, and in this blog post, I’ll explain why and how to start using all the cool features that come with this change.

Update: For those of you using or willing to use Selenium 2/Webdriver, you may want to re-consider the special Sizzle pseudoclases like :contains or :nth that I’m talking about in this blog post. For technical reasons, injecting Sizzle in browsers driven by Selenium 2 is not as cheap as with Selenium 1, so the Devs have decided to rely on the browsers’ implementation of CSS (standard CSS only) and fallback to Sizzle when needed (in case of old browsers which don’t provide native css selecting for JavaScript). In Selenium 2 land, my advice, sadly, is to stick to the standard and avoid most of these shortcuts :,(

Why is Sizzle awesome?

Well, Sizzle is jQuery‘s selector engine, and that means A LOT. For those of you who don’t know, jQuery is the javascript library used by almost 30 percent of all the websites. (As in, “30 percent of the whole effing Internet!”).

Because of that, Sizzle gets an insane amount of usage, and therefore, testing. Sizzle’s code is used by an average of 1 site for every 3 you visit. Its codebase has over a thousand followers on github and more than 80 forks as of today. That’s a lot of eyes to catch bugs and improve performance.

But it’s not just a more robust and faster implementation of CSS that works on every browser. It has removed useless CSS selectors and added extra goodies that turn out to be pretty useful for people writing tests.

Sizzle’s extra features you can use right now

As it says in its docs, Sizzle not only implements virtually all CSS 3 Selectors, but also extends them a little bit and adds its own, including some that are actually pretty useful for writing Selenium tests:

:not

The :not selector will help you filter out elements that are similar, but not exactly what you’re looking for. Let’s imagine the following situation:

<a href="#meh" class="confirmation_link hidden">Confirm</a>
... lots of html ...
<a href="#bleh" class="confirmation_link">Confirm</a>

As you can see here, there are two links in the page you’re trying to test. Since they both have the same text, link=Confirm won’t work because they’re the same class and there is no id you could use to be more specific. In this kind of situation, the :not selector is our perfect weapon. It’s just as simple as writing the following locator:

selenium.click("css=a.confirmation_link:not(.hidden)")

Thanks to Sizzle, complex filters can go inside :not. Here are some other examples:

selenium.click("css=.confirmation_link:not(div)")
selenium.click("css=.submit_button:not(#clear_button)")
selenium.click("css=input[type=button]:not(p#not_this_input > input)")

:contains

Even though :contains was already present in cssQuery and the old Selenium, I thought it was worth mentioning. It can be used to filter elements depending on their inner text, so you can do something like:

selenium.click("css=div#myID > a:contains(Confirm Transaction)")

:eq/:nth

This selector finds all the occurrences and then just filters the nth in the list. If are using the confusing :nth-of-type or :nth-child filters, this may be a great replacement.

selenium.click("css=table a:contains(Change password):nth(5)")

:header

This selector will find you any header element. That is, h1, h2, h3, h4, h5 or h6. Pretty cool, huh? This way you can forget about which type of header your devs choose to use in the page. All you care to know is that it’s going to be a header.

Asserting a header that contains a specific text is the perfect situation for this:

assert selenium.is_element_present(":header:contains(Users Admin)")

Form helpers

Additionally, Sizzle includes some form element shortcuts to save you from having to find out whether the element is a textarea element or an input. Even better, it saves you from writing ugly locators like input[type=checkbox].

  • :input: Finds all input elements (includes textareas, selects, and buttons).
  • :text:checkbox:file:password:submit:image:reset:button: Finds the input element with the specified input type (:button also finds button elements).

I think those are all important and you can check out the Sizzle’s wiki for more info. We also released a CSS selectors quick reference if you’d like to have a cheat-sheet printed and close to your desk while you’re writing your tests ;)

Hope everyone is now writing jQuery Selenium selectors and found this post useful for saving some time and headaches. Of course, all of this is already available in our browsers in the cloud service, Sauce OnDemand, so go try it out for free!

Share

Make Sauce TV Even More Fun To Watch (And Share!)

November 30th, 2010 by Santiago Suarez Ordoñez

After listening to @hugs talk about automating screencasts, and his belief that iphone-like commercials are the future of testing and marketing, I decided to take action and find a way to integrate the missing piece that would allow users to create audience-oriented videos using Selenium.

Surprisingly, it took only a few minutes of hacking to come up with a usable javascript extension that transforms the standard setContext Selenium command into a more descriptive and visual message, making videos recorded by Sauce OnDemand way more useful for external watchers.

What this code does is rewrite the original setContext browser side javascript to create and inject a semi-transparent div on top of the application window. All you have to do is tell your story using setContext while your test is running. After a few seconds, a fadeout function is called to take care of removing that div in a visually attractive way.

Here’s an example video of this feature. You can also check the job results page in Sauce and the source code of the test used to record it.

If you’d like to use this cool feature in your own OnDemand tests, just add the following JSON key to your browser string and start using setContext in them:

"user-extensions-url": "http://saucelabs.com/ext/setContext.js",

You can also change the styling of the message pretty easily. Just fork the gist, start playing around, and please share your updates with the rest in the comments section!

Share

Integrating Robot Framework with Sauce OnDemand

November 23rd, 2010 by Adam Goucher

A mini revolution is happening in the automation space with a whole segment of tools designed to aid in the definition and execution of acceptance criteria. This is the ATDD (Acceptance Test Driven Development) realm and is populated by tools such as Cucumber, Robot Framework, JBehave, etc. This post, though, is not about how to use ATDD effectively in your organization, but rather how to integrate the Sauce OnDemand with Robot Framework.

Robot Framework has built-in support for Selenium through its SeleniumLibrary, which means that support is as simple as telling the script to execute in the cloud rather than locally. Thankfully, you can specify both host and port to the SeleniumLibrary when it is loaded.

Library  SeleniumLibrary  server_host=${SELENIUM HOST}  server_port=${SELENIUM PORT}

Of course, we need to set those variables somewhere. The easiest place would be in the Resource file as just hard-coded values, but that isn’t something you often want to do. Typically you want to embed some type of method to decide whether to run the script locally or in the cloud. For that, it is better to use a Variable file since it is pure Python and lets you make decisions.

import sys

# default is to run locally
use_ondemand = "false"

# add the left/right decision
for arg in sys.argv:
    if arg.startswith("--ondemand"):
        parts = arg.split("=")
        use_ondemand = parts[1].lower()

if use_ondemand == "true":
    SELENIUM_HOST = "ondemand.saucelabs.com"
    SELENIUM_PORT = "4444"
    SAUCE_USERNAME = "your-sauce-user"
    SAUCE_KEY = "your-sauce-key-here"
    SAUCE_OS = "Windows 2003"
    SAUCE_BROWSER = "firefox"
    SAUCE_VERSION = "3."
    SAUCE_NAME = "Robots everywhere!"
    BROWSER = '{"username": "%s", "access-key": "%s", "os": "%s", "browser": "%s", "browser-version": "%s", "name": "%s"}' % (SAUCE_USERNAME, SAUCE_KEY, SAUCE_OS, SAUCE_BROWSER, SAUCE_VERSION, SAUCE_NAME)
else:
    SELENIUM_HOST = "localhost"
    SELENIUM_PORT = 4444
    BROWSER = "*firefox"

Nothing too surprising in here. The bulk of it is around creating the JSON string to send to Sauce Labs. In a real production example, the SAUCE_USERNAME and SAUCE_KEY values would be in an external file so they can be changed without affecting any of the variable files (and there could be many). Somehow iterating over permutations of SAUCE_OS, SAUCE_BROWSER and SAUCE_VERSION also holds promise, but I suspect that would involve writing a custom runner that forks separate Robot Framework processes. And while that might be fun, it’s beyond the scope of this experiment.

The other part of interest, and why its a Variables file and not a Resource, is the left/right decision. In order to run the script in Sauce OnDemand, you provide the extra –ondemand=true argument. If absent, anything else for that flag will run locally.

With this in place, you can easily switch between running your Robot Framework acceptance tests locally or in Sauce OnDemand. Not only does this remove the need to manage your own grid of machines, but you get a video to share with the stakeholders who helped create the script in the first place. In fact, here is the video I created while writing this:



I have also made the source code available for this example on github.

Happy Robot-ing!

Share