Posts Tagged ‘selenium’

Announcing Selenium 2.30.0 as the New Default Version for Sauce Automated Tests

February 22nd, 2013 by Santiago Suarez Ordoñez

After a considerable period of investigation and bug fixing in collaboration with the Selenium project and the Legion of the Bouncy Castle, we are happy to announce we’re moving to Selenium 2.30.0 as the default version in our service. You can find more details about this release in the official changelog.

This transition is scheduled for Friday, March 1st. In the meantime, we advise you to try your tests on this new version by adding the following key-value to your tests’ Desired Capabilities:

"selenium-version": "2.30.0"

If you see any issues after moving over to this new version, we definitely want to hear about it. And remember, once we move everyone to 2.30.0, you can still keep your tests on our previous default (Selenium 2.18.0) version by using the “selenium-version” capability outlined above.

Happy testing!

Share

Announcing Appium on Sauce: Native & Hybrid iOS App Testing in the Cloud

February 5th, 2013 by Ashley Wilson

Today we are extremely excited to announce the initial release of Appium on Sauce, a new way to automatically test your native and mobile web hybrid iOS apps in the cloud.

everestonsauce

Appium on Sauce has its roots in Appium, an open source project written in Node.js that draws from Dan Cuellar’s work on iOS Auto. Appium currently supports iOS testing with Android support in the works. Using the WebDriver JSON Wire Protocol to drive Apple’s UIAutomation, Appium takes Selenium commands from your app and translates those into a readable format for UIAutomation. With this seamless transition happening under the hood, Appium requires no recompiling or modifications to your app, and allows you to write tests in your favorite programming language and testing frameworks using the Selenium API and language-specific libraries.

tutorial_diagram

Support for mobile web hybrid and native app testing has been on our radar screen for a while now, particularly since the Mobile Testing Summit, where we were first introduced to the project now known as Appium. Given its out-of-the-box compatibility with Selenium, goal of cross-platform support across iOS and Android, and flexible approach to automation, pairing Appium with our cloud to provide a turnkey service for automatically testing native and hybrid apps made perfect sense.

And the best part? Appium on Sauce requires no setup or maintenance of iOS infrastructure. Tests can run in parallel across dozens of machines, allowing them to complete much faster than if they were running serially. Additionally, you can plug Appium on Sauce into your existing CI setup and let the cloud serve as your build server.

To get a quick of idea of how Appium on Sauce works, check out the demo video below featuring Everest, an iPhone app that helps you achieve personal goals.

For the next few weeks, Appium on Sauce will be available by invitation-only as we grow our ability to support more users. To sign up for an invite, visit http://saucelabs.com/appium and tell us a bit about your app and why you’d like to test it in the cloud. We expect to open up Appium on Sauce to everyone in the coming weeks so stay tuned to our blog and Twitter for an announcement on that.

And in the meantime, if you’re a Node developer working on a mobile app development or testing, please consider contributing to Appium to help make it better!

Happy testing!

Share

Announcing “Open Sauce,” free unlimited testing for Open Source projects

December 13th, 2012 by Ashley Wilson

For about a year, we’ve been quietly giving free testing support to some high profile open source projects, like Mozilla and the Selenium Project. As open source advocates and contributors ourselves, we know it’s important to support projects that we benefit from on a regular basis. And what better way to do it then by providing the infrastructure that helps ensure new releases are fully tested?

Given that history, we are very excited to announce today that we’re taking this effort one huge leap forward and providing free “Open Sauce” accounts to any OSS project that could benefit from our automated and manual cross-browser testing services.

If you have an open source project, simply sign up here and enter in your project’s repository URL and a description of what it is. You’ll automatically be enrolled in the plan, which provides unlimited testing minutes on up to three parallel VMs and access to all our features, including 96+ OS/browser combos, screenshots, debugging tools and more.

In exchange, we just ask that you agree you will only use this account for your OSS project(s) and that all of your test results (videos, screenshots, and the Selenium log) will be publicly accessible (we actually think this is an awesome thing, as it makes it super simple to share the tests with other developers).

For more info, visit our Open Sauce page or sign up for an account. And if you’d like for us to list your project on Open Sauce, let us know.

Happy (open source) testing!

Share

The Eschaton: What The End Game Looks Like For Testing with Selenium

November 13th, 2012 by The Sauce Labs Team

This is the first in a series of posts by QAOnDemand, which offers self-service QA scripting and testing. For more info, visit http://qaondemand.com.

In theological circles, “The Eschaton” is defined as the end of time. In fact, there’s a whole field of study called Eschatology that studies what the end of the world looks like. While I have to believe their office parties are pretty grim, they’re definitely on to something. Visualizing the end result of what you’re building before ever laying down any foundation can lead to better decision-making, which is a key thing to keep in mind when setting up a mature testing environment for the first time.

To help you with this effort, I’ve devised a zombie readiness kit that includes how to set up the five key components for building a mature testing environment with Selenium:

  • A place to store your tests (source code repository)
  • A place to run your tests (Sauce Labs or a Selenium server)
  • A mechanism to trigger your tests (continuous integration server like Jenkins)
  • A place to log and track defects (a bug tracker like Bugzilla)
  • An army of human testers to test what cannot or has not yet been automated

While you can certainly test software without all five in place, it’s radically more productive with everything integrated and running smoothly. I’ll be diving into each component in more detail, so let’s get started with the guide!

A place to store your tests.

The Z: drive of your network is not a place to store tests. Neither is Dropbox. Your tests belong under source control. All of them. And by all, yes, I mean both manual test scripts and your test automation code.

There are many reasons why bringing your test assets under source control is a good idea, but here‘s the top 26:

A) Continuous integration servers are designed to pull from repositories. This means that if you put your test code in a well-organized repository, it’s relatively easy to configure your CI server to pull the latest copies from the repo and execute your tests automatically. Plus when a test fails, it’s also easy to take a quick look at your revisions to see if a recent change to the test code could be responsible for the failed test.

B) Products like the Atlassian suite are designed to broadcast repository activity. This is a good thing. Too often, QA gets a siege-like quality where we only come up from the dungeon when there’s a problem or free food. The truth is that by continuously broadcasting QA test results into the main communication streams of your company, you normalize the process of QA for everyone outside the group. QA test results become less of an interrupt and more routine. That’s a good thing and a worthy goal.

C-Z) Revision control. If your test code isn’t under revision control, then you’ve been living in the woods too long. You’s ignorant so listen up! If it’s worth doing, it’s worth keeping track of. The ability to trace changes over time is one of the most underrated tools out there. If something breaks and you’ve got to pop open the code, the first thing to look at is what has changed. Did the code change? Did the test change? With Git, CVS, SVN, Merc, whatever, you can easily see the evolution of your test code. It solves so many problems and enables so many good things such as skills development, accountability, and humility.

A place to run your tests.

You’re reading this on Sauce Labs‘ blog so this hardly needs mentioning, but there’s a nuance here worth talking about. One of the best qualities of Sauce Labs is the visibility it creates. The value in being able to rerun a test or capture a screenshot cannot be overstated. Whether you’ve provided a manual step-by-step set of instructions or you’ve provided a link to a screen cast, the first step in remediating a bug is to reproduce it and observe it in action. So if that “place to run your test” is “Joey’s Laptop,” then you’re going have a bad time. But if it’s a generally available service that anyone can access, it’s going to be a whole lot more fun.

A mechanism to trigger your tests

We see a lot of test teams “kicking off” tests manually. This is fine; there are lots of cases where you need to do this, but it’s waaaay better when a continuous integration (CI) server does this for you. Getting your CI to manage your test execution is tricky. Now I’d love to tell you there’s a simple script ./make-it-so.py, but alas, there is not. There are different types of builds, different deployment scenarios, and different types of check-ins that should fire off different types of tests.

But the net-net is that in the end, you want your QA process to be seamlessly integrated into the development process. And increasingly, CI drives development. Consider this question: In five years, is continuous integration and automated deployment going to be more or less prevalent? Is it going to be more common or less common? The answer is yes, so why bring up the rear of the parade? Get out in front. The sooner your QA process is wired into your CI, the easier it’ll be in the end.

A place to log and track defects

I’m going to move quickly through this point because most of you probably have this at some level. The one feature I’ve seen in the last few years that’s really been a huge boon to development is tying tickets to checkins, such that you can see the code that is related to the ticket. This makes it infinitely easier to quickly find the business requirements associated with a ticket and cross-reference it to the code itself. If you can tie your test code to tickets in a similar fashion, it’s so much the better because you’ve created visibility for both the created tests and related revisions. I highly recommend you select bug-tracking software that does this. It’s absolutely worth every expense.

An army of human testers to test what can’t (or has yet to be) automated

In its heart of hearts, quality assurance is a request for an opinion that is inescapably a human observation. “Does it work as you expect?” can sometimes be described in a way that can be automated. Sometimes it can be described in a way that a tester with nominal knowledge of the system can test. Sometimes it takes a domain expert to tell if something works as expected.

The point is, human testing always has been and always will be a part of QA. Anyone who says it can be completely automated is either an academic or a fool. So plan for it and work towards an end game that uses human testers in a productive and efficient way. We think it’s helpful to break up the problem of organizing human-based QA work into three buckets using the following guidance.

  • a) Automate the simple stuff that’s easy to maintain or is tedious. Automate the routine stuff that won’t break often, but when it does, it’s catastrophic. There’s no shortage of people who will tell you that with a good framework and their secret sauce, you can automate everything. You can’t. And more importantly, it’s not worth it. Automation is fundamentally an economic problem, not an engineering problem. You should only automate that which the cost of automation is meaningfully less than the cost of just running the check repeatedly by hand when needed. The bottom-line? Don’t get dragged into complex automation strategies. Automate the simple routine stuff in a simple and routine way.
  • b1) Outsource the intermediate stuff, such as layout, copy writing, new features, and regressing fixes on a well-defined but complex bug. Outsourcing works great where cultural nuance, domain expertise and a qualified point of view don’t matter all that much. The overhead is much lower than it used to be and in the sage words of Eric S. Raymond: “Given enough eyeballs, all bugs are shallow” .
  • b2) Outsource the creation of simple automation — you know, like writing your Sauce Labs tests. Just sayin’. When a well-defined bug gets checked, have an outsourced team write an automated test to check it again. Test harnesses with a thousand tests get built one test at a time. ***
  • c) Use your domain experts as big guns. Focus them on the hard stuff – subtle features that require an understanding of how the code works or how a customer sees the world. If your in-house QA engineers are testing to see if your upload feature correctly kicks out an error for oversized files or disallowed formats, then you are wasting valuable expertise. Again, it’s helpful to think about testing as an economic problem and price your top talent. Give your top dogs a fully loaded cost and socialize the notion that it’s not a few hours, it’s a few dollars. Remind people of what they’re asking for in economic terms – that a detailed, cross-browser, multi-platform manual test by your in-house team is easily a $1,000 request. A simple question to posit: “Is that the best way to spend $1,000?”

So, what now?

In conclusion, take time to work through your endgame. Almost all QA work is time-bound, meaning we all work as hard and as fast as we can testing until the clock runs out. If nothing explodes during testing, we ship. It’s not fair, but that’s the way it is. So if you don’t block off some time each cycle to build toward a better way of doing things, then you’re selling yourself and your team short. Hopefully this post gave you a little perspective on what that end-game could look like.

In the next post, we’ll get into specifics of some of the tools we’ve found to be most helpful and more specifics about what works for us.

*** Look, QAOnDemand basically does B1 and B2 for a living. We see a lot of people’s QA efforts. Our services are structured and priced to make it easy for you to say yes to modest outsourcing. We’ll knock out your intermediate testing without crushing you with a big contract or a lot of overhead. Plus we offer a decent free trial with no strings attached, so give it a go. We’ll also bootstrap your Sauce Labs environment for you if you haven’t done so already. It’s much easier to add to a working system once it’s set up correctly. Net-net, a little help in the beginning goes a long way. Ok, ’nuff said.

Share

Musings on Mobile Testing Automation

November 1st, 2012 by Jason Huggins

We at Sauce Labs love automated testing. We believe test automation is a critical piece of the puzzle for pushing code from “GitHub to Heroku” as fast as possible, while building confidence that everything working yesterday is still working today.

This is why I started Sauce Labs and why we invested in building out our “Selenium as a Service” cloud. We started with Selenium because it’s the market leading testing tool for desktop web testing. However, for mobile it’s a brand new game. It’s not enough to just test web apps in mobile browsers. Looking at the success of the app marketplaces, (e.g. Apple App Store and Google Play), it’s obvious that native and hybrid app development is popular with developers, too. And there is no consensus on the right tool for testing /anything/ on mobile — native, hybrid, or web. While the mobile test automation tool market matures, many mobile developers have given up on using automated tests and gone back to manual testing. Developers will come back to test automation when consensus is reached, but consensus building doesn’t just happen automagically. This is why we hosted the Mobile Testing Summit — to get the world’s leading open source test automation tool creators in one room — and see what happens. At the summit, these creators are sharing their experiences of what’s worked, what hasn’t, and charting a course forward.

As we chart that course, I think it’s useful to reflect on the secrets of Selenium’s success and how they can and do apply to mobile.

10) Be Good at One Thing (And Pick the Right Thing)

Born in the age of AJAX and Web 2.0, Selenium was pretty good at testing JavaScript-heavy web applications. But it really excelled at driving Firefox on either OS X or Linux with Java client libraries. This was the “killer combo” that resonated with developers. Firefox was their favorite browser and MacBooks were their favorite development machine. Java probably wasn’t their favorite programming language, but it’s what most large scale web apps were written in.

9) Make Stone Soup (Start Small, Sell the Dream, and Ask for Help)

The Selenium project’s mission is to automate all browsers on all operating systems with any programming language. However, such a Big Hairy Audacious Goal is not something one person can do alone. Like the folk story where a village turned a pot and a simple stone into a delicious soup, Selenium needed lots of help from lots of people to get the job done. At the beginning, many browser/OS/language combinations were buggy or incomplete. For many years, Selenium really stunk at automating Safari on Mac. And if you used XPath element locators in Internet Explorer, Selenium was worse than an angry skunk. I’m sorry  to be blunt – but things did get better over time as more people got involved. At first, you don’t need a detailed road map, but you do need to tell people what mountain you’re climbing. If you start small enough, yet dream big enough, you just might be able to convince strangers to help you on your journey.

8) No Assembly Required

Don’t require developers to modify their apps in any way just to start using your test library. Developers should be able to test their app “as-is”. Originally, Selenium violated this rule. Because of the same origin policy (long story), Selenium’s JavaScript and HTML had to be served alongside the rest of a web application’s public assets. This was a frequent complaint and impediment to adoption. Once Selenium Remote Control (RC) arrived, we were able to remove the app modification requirement. There are several reasons this is important — some technical, others cultural. Developers want to keep the surface area of their apps as small as possible. Having extra code lying around in the app leads to an unnecessary increase in file size and another potential vector for bugs or security holes. And some teams charged with test automation are separated from the developers who compiled the app. They have to write tests, but they might not have any (or at least, an easy) way to modify the source just to make it automatable. Yes, that’s sad and wrong, but a reality for many organizations. The least you can do is make their lives a little more comfortable. Make it easy to test an app as-is.

7) Be Newbie Friendly

Newbie’s want some help. Don’t leave them hanging. Focus on the “First 15 minutes” experience. Although it’s controversial in the testing world, you should consider having a Record & Playback tool for helping new users write their first test. And like a good mentor, encourage them not to abuse the tool.

6) Be Developer Friendly

Pay attention to how developers prefer to work. Let developers use their favorite text editors or IDEs. They also like to write their tests in the same language as the app’s source code, and check those tests into the same code repository. And don’t invent a new programming language. Many of the commercial testing tools that Selenium supplanted broke all these rules, and explains why developers refuse to use them.

5) Scaling Happens

Paul Hammant gets the credit here. It took me a long time to realize he was right all along. A few months into the project, Paul wrote the first versions of what later became Selenium RC. He used a technique, (now called “comet” or “long polling”) to let any programming language talk to the Selenium automation engine running in the browser. Instead of inventing a new protocol to talk in this new way to a browser, he decided to re-use (some might say abuse) HTTP for the message transport. At the time, even though all Selenium tests were run locally and didn’t need to talk over a network, using HTTP ended up having a secondary benefit — you could drive Selenium tests remotely on different machines (with different OS and browser configurations) from anywhere on the network. Using HTTP also let testing scale up gracefully. It enabled projects like the Selenium Farm, Selenium Grid project, and even Sauce Labs to exist. Functional testing can be slow, but throwing more computers at the problem is a great way to speed things back up again. Through the magic of HTTP proxying — you can distribute tests to huge farms of machines without having to push that complexity into the tests themselves. So, even though worrying about scaling is usually considered a premature optimization, it’s not that premature when it comes to testing. Sometimes, you are going to need it.

4) Good Ideas Come from Everywhere

Be welcoming of ideas from other projects. And occasionally, merge and join forces. When Simon Stewart and I spoke at the Google Test Automation Conference in 2007, we were both quite proud of our projects and happy doing our own thing. However, we quickly realized we shared many common goals and attitudes regarding the future of test automation. At the conference we hatched a plan to merge our projects. Simon’s WebDriver project became Selenium 2. Selenium had solved 80% of the test automation problem. But WebDriver was really good for that last 20% the frequently tripped up Selenium users — interacting with the host operating system for things such as keyboard and mouse events, handling pop-up dialog boxes, and security warnings. It’s important to be humble and know your project’s weaknesses. When someone comes along and fixes all your problems, and they inconveniently didn’t solve them in your own codebase, don’t get mad. Instead, get them drunk, and trick them into taking over your project.

3) Be Social

It’s not enough to simply create. You also have to promote your work. Speak at a meetup. Speak at conferences. Write blog posts. Create screencasts. But you don’t have to do it alone. I’ve had the luck and pleasure of working in many environments where everyone was encouraged to publicly share their work as much as possible. I did my part in getting the word out about Selenium in the beginning, but friends and colleagues did a bulk of the work. I couldn’t be in every city and every conference talking about Selenium. But my friends could. So, collect lots of friends. If you solve an important problem for them, they’ll be more than happy to tell the world about it on your behalf.

2) Be Free (Open Source FTW)

Everyone has their own story for why they believe in the power of open source. I became a big believer in open source years ago as a system administrator of a large proprietary HR system. Half way through the implementation, we unfortunately found out that some critical functionality just flat out didn’t work. Without access to the source code, and being too small to get the attention of the vendor, we had no ability to fix the issue. We ended up writing our own replacement system — this was the Time and Expense system that the Selenium project came from. Having access to the source code is especially important in testing — as SDKs and standards evolve, testing tools are on a treadmill racing to keep up. It doesn’t scale to expect just one project or one team to know how to automate every crazy cool new HTML5 or iOS feature at all times. With open source, when your users run into a feature that your testing tool can’t handle, they’re not stuck. They have the power to fix things and move on.

1) Be Foolish

Do the things that others think are crazy. Within reason, of course. If you believe passionately in a particular idea, do it anyway, despite what people say. In 2003, using JavaScript was considered a very unprofessional thing. It was buggy and inconsistent in every browser. But using JavaScript let us create some really cool and fast features that we couldn’t do any other way. Then 6 months later Gmail and Google Maps came along and using JavaScript was no longer crazy. Foolish today, genius tomorrow. Paradoxically, if you want people to keep thinking well of you, you have to keep doing things they think are quite foolish. So, stay foolish.

To be continued….


Share

Using Sauce Breakpoints to Find and Fix Flakey Tests

September 13th, 2012 by Jonathan Lipps
Spoiler Alert: If you read this article, you’ll be one of the first to hear about a previously-unpublicized feature from Sauce. It’s like an easter egg!

Bugs and Flakes, yum!It probably comes as no surprise that at Sauce we write a lot of Selenium tests. Our website needs good test coverage, just like our customers’ apps. We have a build that runs all of these tests (and many more unit tests besides) after every chunk of commits. If tests fail in our build, it stays “red” until someone commits a fix. During that time, we can’t deploy the new code, and it’s our custom to not even push more commits on top while the build is red, so the problem can be diagnosed and fixed without complicating matters.

In other words, it’s a big deal when the build breaks because it is potentially interfering with other developers’ workflows. That’s one of the reasons we pull out our hair and yell obscenities when we encounter flakes in our build. A flake occurs when a test that normally passes, or passes under normal conditions, fails non-deterministically (i.e., under seemingly random conditions). If we run the build again, that same test might pass, leaving us without a lot of information about what went wrong. Is something wrong in the code? Is something wrong in our build infrastructure? It leaves us uncertain whether we might actually have a problem with that functionality in production, too—if it’s failing 1 out of every 1,000 times in the build, is it affecting 0.1% of our customers?

On a recent Flakey Friday (a Friday dedicated to tracking down and eleminating flakiness from tests), we caught a test acting strangely, and failing one out of every ten or so runs. The test looked like this:

def test_can_publish_and_back(self):
    self.login(self.user)
    self.open_job(self.test_job['_id'])
    self.find_element_by_link_text("make public").click()
    self._check_public()
    self.find_element_by_link_text("make private").click()
    self._check_private()

This is one test for our job* detail page. The setUp function for this test class handles creating a new random user and a new random job. The test logs the user in and goes to the page for this job. It then clicks a link designed to make the job “public” (i.e., viewable by anyone on the web), checks both the database and the website to make sure the AJAX-powered toggle did its trick, and finally makes sure we can toggle the job back to “private” in the same way.

This is a straightforward test and is built using Selenium test best practices (creating a fresh random user object, a fresh random job, and using spin asserts to avoid race conditions), but every so often it would fail because Selenium would check that the link text changed after click—something that, in these cases, didn’t happen. Likewise, the job was not marked with the appropriate status in the database.

How do you diagnose and fix a problem that only occurs on average 10% of the time in the build? Well, the first thing we tried was reproducing the behavior manually. Unfortunately, no matter how many times we performed the test actions ourselves in a browser, we could never observe the failure. Since we couldn’t reproduce the bug, all we had were various hypotheses about website load in our test environment, or javascript issues that prevented the AJAX call from taking place. But we were basically looking at a long, hard road of guesswork.

At that point we decided to make use of Sauce Breakpoints to try and catch the bug in the wild. I’ve written previously about how you can use Breakpoints to debug javascript errors in tests you are writing. This particular technique wouldn’t have helped us here, because we couldn’t reliably reproduce the failure. What we needed was a way to run so many instances of this test that we were likely to observe a failure, and then to enter Breakpoint mode on just the tests that failed.

The first step was taken care of in a rather brute-force way: I simply created 14 new versions of the same test, like so:

def test_can_publish_and_back2(self):
    self.test_can_publish_and_back()

...

def test_can_publish_and_back15(self):
    self.test_can_publish_and_back()

This way, I could run our custom version of the Nose test runner and have it pick up all and only the tests I was interested in using a wildcard match:

nose test_can_publish_and_back*

Then, I made use of a feature we have not yet publicized: programmatic Sauce Breakpoints. This is achieved by sending a special Selenium command that the Sauce Cloud understands to mean that you want the job breakpointed. For both Selenium RC and WebDriver, the special command is sauce: break. For Selenium RC, this command is sent as the context parameter for setContext. For Selenium WebDriver, it is passed as the script value of the execute command. Luckily, the Python WebDriver API implements these commands, so all I had to do was hack sauce: break into our main test class’s tearDown function:

def tearDown(self):
    if not self.passed:
        self.collect_web_traceback()
        if self.break_on_fail:
            self.driver.execute_script("sauce: break")
    self.report_pass_fail()
    if self.stop_on_teardown:
        self.driver.quit()

Essentially, our tearDown logic here says, “If the test didn’t pass, get a traceback and breakpoint the test if I’ve set self.break_on_fail. Then, report the status to Sauce, and close the WebDriver session.” With all of these modifications in hand, I was able to run the offending test multiple times in parallel like so:

nose --processes=15 test_can_publish_and_back*

Then, all I had to do was go to my Sauce Labs tests page and watch to see which tests turned up as breakpointed. I could navigate to the detail page for a breakpointed test and use the dev tools in Chrome to examine what was happening. In the case of this flake, I discovered the problem was that the AJAX request was not successful—it was receiving a 401 response from our test server. This meant that the CSRF protection for the AJAX POST was messing up somehow. After a lot of website backend debugging, we were able to determine that, under load, new CSRF tokens sometimes took longer to save to our persistent data store than it did for the website to respond with them to the request, making the browser’s next (valid) request appear invalid to the server, thus causing it to reply with a 401. Luckily, upgrading our backend code and making our session save synchronous took care of the problem.

The details I have shared about our particular flake are not important to the big story here. What is important is that we had a kind of flake that was nigh-impossible to pin down without a tool like Sauce Breakpoints. It allowed me (within the space of one parallel Sauce test run) to observe the bug in its natural habitat and get into the dev tools of this problem session, where we were able to find the first clue on the trail which eventually led to squashing the issue. We hope this strategy can also be useful to others who aren’t tolerant of mysterious flakes in their build. Let us know if you can think of any other testing practices which can be augmented by Breakpoints!

Addendum: Selenium RC

The example code of programmatic Sauce Breakpoints above is for Selenium 2, a.k.a WebDriver. Breakpoints also work for Selenium 1 (a.k.a. Selenium RC) tests, but the code is different. Here is our tearDown function for Selenium 1 tests, which illustrates the use of the set_context function:

def tearDown(self):
    if not self.passed:
        self.collect_web_traceback()
        if self.break_on_fail:
            self.selenium.set_context("sauce: break")
    self.report_pass_fail()
    if self.stop_on_teardown:
        self.selenium.stop()

* at Sauce, we call an individual test run in our infrastructure by a customer a “job”

Share

Introducing the Sauce Plugin for Selenium Grid

September 11th, 2012 by Ross Rowe

We are excited to let you know that we have released a beta version of our open source Sauce plugin for Selenium Grid!

This plugin allows you to easily connect to and leverage Sauce’s virtual machine capacity and extensive cross-browser platform support from any existing Selenium Grid setup, allowing you to transparently run Selenium 2 (WebDriver) tests using either your local Grid nodes or Sauce ones. (Support for Selenium 1 (RC) is planned for a future release). Let’s get started!

Installation

If you haven’t done so yet, download the standalone Selenium Server jar.

To use the plugin, download the jar file from https://repository-saucelabs.forge.cloudbees.com/release/com/saucelabs/sauce-grid-plugin/1.0.4/sauce-grid-plugin-1.0.4.jar and place it in the same location as your selenium-server jar. Then start your Selenium Grid hub using the parameters below for:

Windows:

java -cp selenium-server-standalone-2.25.0.jar;sauce-grid-plugin-1.0.4.jar org.openqa.grid.selenium.GridLauncher -role hub ^
-servlets com.saucelabs.grid.SauceOnDemandAdminServlet,com.saucelabs.grid.SauceOnDemandConsoleServlet

Or Unix:

java -cp selenium-server-standalone-2.25.0.jar:sauce-grid-plugin-1.0.4.jar org.openqa.grid.selenium.GridLauncher -role hub \
-servlets com.saucelabs.grid.SauceOnDemandAdminServlet,com.saucelabs.grid.SauceOnDemandConsoleServlet

The plugin can be configured by opening the following URL in your browser and clicking on the ‘Configure’ link:http://localhost:4444/grid/admin/SauceOnDemandConsoleServlet (notice that localhost:4444 will change if the hub hasn’t been launched on your own machine or using port 4444).

This page will allow you to specify the username/access key to use when running tests against Sauce. If you don’t have an username and access-key, sign up for a free or paid Sauce account right now! The maximum number of parallel sessions will be automatically populated when the page is saved by finding the number of parallel sessions available to your Sauce user account. All platforms in our service will be instantly ready for your use.

Using Sauce as a Selenium Grid Node

Usage

There are two ways that the Sauce Grid plugin can be configured to be run: by handling all capabilities that aren’t available in your local Nodes (like iOS devices or Android) or by explicitly handling a specific subset of browser/operating system combinations.

To configure the plugin to use Sauce for all browser/operating system combinations that aren’t explicitly handled by existing nodes, select the ‘Handle All Unspecified Capabilities’ check box.

To configure the plugin to use Sauce OnDemand for specific browser/operating system combinations, select the desired browsers from the multi-select list. Please note that there are separate lists for SeleniumRC/WebDriver.

Then update your tests to run against the Grid instance, eg.

//run against Firefox v12 on Windows XP DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setPlatform(Platform.XP);
capabilities.setCapability("version", "12");
WebDriver driver = new RemoteWebDriver(new URL("http://YOUR_HUB_HOST:4444/wd/hub"), capabilities);
driver.get("http://www.amazon.com");
...
driver.quit();

And that’s it!

Now your automated tests are able to run using both your local Selenium instances or Sauce, depending on the capabilities that they request. Remember, this plugin is in beta and fully open source. You can find the project up on Github and we encourage you to fork it, report issues and send us pull requests. Happy testing!

Share

Cross Browser Testing Demo Using Selenium & Node.js

July 3rd, 2012 by Ashley Wilson

One of the great things about Sauce OnDemand is that it works with any programming language. For all you Node.js fans looking for ways to ensure excellent cross-browser test coverage, check out the demo below to see how to use Selenium & Sauce with Express.js, Vow.js, and WD.js.

For more info, visit the Sauce Node Demo on Github. Happiest testing, to you!

Share

Upcoming Selenium Events: Page Object Model, Optimizing Test Performance, and More

June 21st, 2012 by Ashley Wilson

June and July are busy months for the Selenium and Sauce community. Check out these meetups happening across the country (and world), and let us know if we’re missing anything. Hope to see you there!

June 21: PDX Selenium Meetup
Beyond Page Object Patterns
By Sam Woods, Software Development Engineer in Test at WebTrends
Learn about the evolution of automated UI tests from “scripts” to fully functional, maintainable, reliable abstracted automated test cases using the page object pattern.

June 27: Colombo Selenium Meetup
Selenium’s Journey
By Jason Huggins, Co-Founder of Sauce Labs
Get an introduction to Selenium’s colorful history in this virtual meetup with Jason Huggins, original creator of Selenium.

July 9th: Boston Selenium Meetup
July 11th: DC Selenium Meetup
Optimizing Selenium for Executed Performance
By Santiago Suarez Ordoñez, Selenium Ninja at Sauce Labs
This talk will cover test writing tips gathered over the years from helping hundreds of Selenium users and engineers make their tests run faster and more reliably, independently of the technology stack used. We’ll be talking about things such data independence, making atomic tests and generating application state.

July 10th: Continuous Delivery NYC Meetup
Continuous Delivery at New Relic
By: Bjorn Freeman-Benson, VP of Engineering at New Relic
Bjorn will talk about New Relic’s experiences in growing from a few developers supporting a few thousand users to 70+ developers delivering continuously to thousands of large and small commercial customers.

July 17th: San Jose Selenium Meetup
HARdy Har Har: How to generate HTTP Archive Files
By Adam Goucher, Selenium Expert and Consultant at Element 34
This talk will show you how to generate HTTP Archive (HAR) files in two different ways; using a custom Firefox WebDriver profile and with the BrowserMob Proxy.

July 18th: San Diego Web Performance Meetup
Capturing Performance Data from your Selenium Tests
By Patrick Lightbody, Director of Product Management at Neustar Enterprise Services
Learn from one of the original Selenium developers how you can use open source projects and new specifics, such as Navigation Timings, to augment your existing test suite and capture performance in your existing continuous integration environment.

July 18th: OC PHP Meetup
Selenium: Less Testing and More Coding
By Jonathan Lipps, Front-End Engineer at Sauce Labs
Jonathan will give a demo of a basic PHP web application and go through the motivations for using Selenium as a way to consistently and reliably test the application. He’ll then describe how Sauce Labs’s cloud service enables testing to transparently scale to multiple browsers and platforms and reduce several frustrations with running tests locally.

Share

Selenium Testing Framework Part 3: Putting It All Together

December 6th, 2011 by Jason Smiley

This is the final post in a 3-part guest blog series by Jason Smiley, a QA Engineer at Gerson Lehrman Group. You can read his first post here and his second post here.

If you’ve been following along with my other posts on building a Selenium testing framework, you know we’ve covered some of the high-level testing concepts and base classes so far. Now that we have defined all our working parts, let’s see how we would pull this above code into our test projects. To summarize specficially what we talked about in the last blog, we have defined the following classes.

  • SeleniumTestBase.cs, which handles creating of the test browser, reading from the DB,  and handles changing of active windows or frames.
  • SeleniumActionBase.cs, which can update the DB and also can handle changing of the active windows or frames.
  • SeleniumPageBase.cs, which checks the starting number of the XPath browser index (IE uses 0 while all other browsers use 1).
  • SeleniumPageElement.cs, which handles waiting for and interacting with elements on the page.

Since I mentioned the above classes should be in an external project from your testing project, I will refer to these set of classes in compiled form as the OurSeleniumFramework.dll. This .dll file should be referenced in your test project so test, action, and page classes can extend the base classes we created.

When creating a test project to test a website, it is a good idea to create a project base test that will create all of our action and page classes, as well as having a project base action class that will create all our page classes. Page classes will create SeleniumPageElements, which will be used by action and test classes.

Example Test Project

To demonstrate this structure, I will show how base classes are created and how this can be used to test a login page which has a username field, password field, submit button, login confirmation message that appears after successful login, and error message that appears after unsuccessful attempts. I will now show what each class required to perform a basic login test will look like. I will also add notes in the tests to show why something is being done. See below for all the example test project files. The files will be:

  1. ProjectTestBase.cs: Handles NUnit setup, teardown, and page and action initialization functionality for tests.
  2. ProjectActionBase.cs: Handles page initialization functionality for actions.
  3. LoginTests.cs: Implements the tests for the login page.
  4. LoginActions.cs: Implements the steps required to do Login testing.
  5. LoginPage.cs: Handles the initialization for PageElement objects which will be used by actions and tests.

Example ProjectTestBase.cs

public ProjectTestBase : SeleniumTestBase
{
#region Action declarations
protected LoginActions _LoginActions;
#endregion

#region Page declarations
protected LoginPage _LoginPage;
#endregion

public ProjectTestBase (IWebDriver webDriver)
: base(webDriver) { }

public void CreateActions(IWebDriver webDriver)
{
_LoginActions = new LoginActions(webDriver);
}

public void CreatePages(IWebDriver webDriver)
{
_LoginPage= new LoginPage(webDriver);
}

[SetupTestFixture]
public virtual void setupTestFixture()
{
//Function is virtual so child test classes can have additional functionality.

//For this example project, nothing needs to be done on this level.
}

[Setup]
public virtual void setup()
{
//Function is virtual so child test classes can have additional functionality.
myDriver = StartBrowser(“firefox”);
CreateActions(myDriver);
CreatePages(myDriver);
LaunchUrl(“http://myhomepage.com”);
}

[Teardown]
public virtual void tearDown()
{
//Function is virtual so child test classes can have additional functionality.
myDriver.Quit();
}

[TeardownTestFixture]
public virtual void setupTestFixture()
{
//Function is virtual so child test classes can have additional functionality.

//For this example project, nothing needs to be done on this level.
}
}

Example ProjectActionBase.cs

public ProjectActionBase : SeleniumActionBase
{

#region Page declarations
protected LoginPage _LoginPage;
#endregion

public ProjectActionBase(IWebDriver webDriver)
: base(webDriver);
{
_LoginPage = new LoginPage(webDriver);
}
}

(I’d like to point out here that in this class, you can put common actions such as successful login so all action classes will be able to perform this step. This is just a nice-to-have, though, and not a must.)

Example LoginTests.cs

public LoginTests : ProjectTestBase
{

[Test]
public void successfulLoginTest()
{
_LoginActions.LoginAttempt(“Jason”, “Smiley”, true);
Assert.That(_LoginPage.ConfirmationMessage.Text, Is.EqualTo(“You are now logged in”).IgnoreCase, “You should have logged in successfuly but didn’t”);
}

[Test]
public void invalidLoginTest()
{
_LoginActions.LoginAttempt(“fake”, “fake”, false);
Assert.That(_LoginPage.ErrorMessage.Text, Is.EqualTo(“Invalid login”).IgnoreCase, “You should have gotten an error message but didn’t”)
}
}

Example LoginActions.cs

public LoginActions : ProjectActionBase
{
public void LoginAttempt(string username, string password, isValid = null)
{
LoginPage.UsernameTextField.Clear();
LoginPage.UsernameTextField.SendKeys(username);
LoginPage.PasswordTextField.Clear();
LoginPage.PasswordTextField.SendKeys(password);
LoginPage.SubmitBtn.Click();

if(isValid != null && isValid == true)
{
LoginPage.ConfirmationMessage.
WaitUntilVisibleAndPresent(“confirmation is not appearing after 5 seconds”);
}

if(isValid != null && isValid == false)
{
LoginPage.ErrorMessage.WaitUntilVisibleAndPresent(“error message is not appearing after 5 seconds”);
}
}
}

Example LoginPage.cs

public LoginPage : SeleniumPageBase
{
#region PageElement declarations
public PageElement UsernameTextField;
public PageElement PasswordTextField;
public PageElement ConfirmationMessage;
public PageElement ErrorMessage;
#endregion

public LoginPage(IWebDriver webDriver)
: base(webDriver)
{
UsernameTextField = new PageElement(By.Id(“username”), webDriver);
PasswordTextField= new PageElement(By.Id(“password”), webDriver);
ConfirmationMessage= new PageElement(By.Id(“success”), webDriver);
ErrorMessage= new PageElement(By.Id(“error”), webDriver);
}
}
Share