Introducing Cross-Browser JavaScript Unit Testing on Sauce Labs

September 12th, 2013 by Bill McGee

Today we’re excited to announce a new and improved way to test your JavaScript unit tests on the Sauce Labs cloud.  These changes, including a revamped REST API, provide an easy way for JavaScript developers to do massive cross-browser testing of their apps without setting up or maintaining any test infrastructure.

js

Using Sauce for your JS unit testing gives you instant access to difficult to maintain OS/browser combinations, including Mac OS X and Internet Explorer, providing you with better test coverage and scalability. You can also integrate your tests with your CI system to automatically ensure your browser compatibility on a per-commit basis.

Currently, you can easily run your Jasmine, QUnit, YUI Test, or Mocha tests on Sauce Labs using GruntYetiKarma, Mocha Sauce, or Intern. If there are other testing frameworks you’d like us to support, let us know.

Why did we make this improvement?

For a long time now, our primary goal at Sauce has been to make functional Selenium testing a killer experience. While we’ve added additional capabilities to our platform, like manual testing and hybrid and native mobile app testing, JavaScript unit testing, although used here and there by some customers, wasn’t a core focus.

That changed this past May when we attended JSConf. Not only did we meet tons of developers using Sauce, the majority of them were using us for JavaScript unit testing, particularly if they had an open source project that needed cross-browser testing coverage (did you know we offer unlimited-use plans for open source projects?).

After talking with a few developers at various companies for feedback on how we could improve the experience, we learned that some relatively minor changes could have a big impact on how easy and useful it is to test JavaScript functionality using Sauce’s cloud infrastructure. Then we got to work.

Features

What make JS unit testing awesome on Sauce?

REST API

First of all, our new REST API makes it super simple to run your tests on our cloud – and it takes Selenium out of the equation. In the past, if you did JavaScript unit testing on Sauce, you had to use the Selenium libraries to instantiate the browser. Now, this happens seamlessly in the background.

JavaScript unit testing on Sauce

Test Details Page

To help JS developers identify issues lightning fast, we did an overhaul of the test details page, creating a test report specifically designed for JavaScript unit tests. You’ll be able to see and share all your test details easily and identify failures faster using the screenshots, video and logs.

JavaScript unit testing on Sauce details

Getting Started

If you’ve never done any sort of JavaScript unit testing on Sauce, we suggest getting started by signing up for a free account and reading our documentation. If you’ve already picked your tool of choice, check out our simple REST API to get started. And if you’re using Grunt, Yeti, Karma or Mocha, check out the following links:

Grunt-Sauce

Yeti & Sauce Labs

Karma Sauce Launcher

Mocha-Sauce

Read the Case Study

Want to learn more about how other companies do JS unit testing on Sauce? Read our latest case study featuring Mobify.

Mobify uses Sauce to test mobify.js, their JavaScript library for powering responsive sites. Mobify was able to easily automate their unit testing and run their tests easily in the cloud using our Grunt integration.

Happy JavaScript unit testing!

Sauce Labs Adds Expanded JavaScript Unit Testing Capabilities to its Cloud Testing Platform

September 12th, 2013 by Bill McGee

Developers now able to easily cross-browser test JavaScript components using Sauce Labs’ secure, enterprise-grade testing infrastructure

SAN FRANCISCO, CA – (Sept. 12, 2013) – Sauce Labs Inc., the leading provider of cloud-based mobile and web application testing solutions, today announced expanded platform support and new features for JavaScript (JS) Unit Testing on Sauce. Developers are now able to automatically test whether the JavaScript in their web and mobile applications renders correctly using Sauce Labs’ test infrastructure of more than 150 browser / OS platforms.

With JavaScript code playing an increasingly critical role in modern web apps, JS unit testing is essential to ensure quality and keep up with the accelerating pace of web development. However, many developers are limited to testing against the browsers available on their own laptops or internal test infrastructure. By using the Sauce Labs platform for JS unit testing, developers can instantly run tests across all their target browsers, increasing the coverage of their testing and the speed of their release cycles.

“Using Sauce for JS unit tests gives developers instant access to difficult to maintain OS/browser combinations, so they can get better test coverage, and allows them integrate tests with their Continuous Integration, or CI, systems,” said John Dunham, CEO and co-founder of Sauce Labs. “Hundreds of users have already been using Sauce Labs to run their JavaScript unit tests in the cloud, but the new features make it even simpler.”

Sauce’s latest JS unit testing developments include a convenient REST API that makes it easier for developers to run tests on the Sauce Lab cloud. To more quickly help frontend developers identify the browser-specific issues within their web and mobile applications, Sauce Labs overhauled their test details page, creating a new reporting page that specifically details the results of JS unit tests. This feature enables developers to see and share all test details easily and identify failures faster.

Beyond web app developers, some popular JS application frameworks run their own cross-browser JS tests in the Sauce Labs cloud, including YUI, an open source JavaScript and CSS library for building richly interactive web applications that is built by Yahoo.

“We use Yeti with Sauce Labs to run over 25,000 tests for every commit to the YUI open source project,” said Reid Burke, Yahoo engineer and YUI team member. “We develop with confidence because we constantly test our code on the same browsers and devices our customers use. Plus, Yeti’s support for parallel Sauce sessions lets us run all of these tests quickly.”

In addition to JS unit testing, the Sauce platform supports functional testing with Selenium, hybrid and native mobile app testing with Appium, and manual testing. To learn more about JavaScript Unit Testing on Sauce, visit http://saucelabs.com/javascript.

 

Additional Online Resources

 

About Sauce Labs
Sauce Labs, the leading web and mobile application testing company, provides cloud-based testing tools that greatly increase productivity for developers and enterprises alike. Sauce Labs’ automated testing service lets users run Selenium tests and JavaScript unit tests for native mobile apps, mobile web apps and desktop apps across multiple browsers in parallel without setting up or maintaining test infrastructure. Its manual testing service lets users interactively test websites on more than 150 browser/OS platforms while recording screenshots and videos of bugs. To date, more than 60 million tests have run in the Sauce cloud. Sauce Labs is headquartered in San Francisco, California. For more information, visit http://saucelabs.com.

 

Mocha Sauce for JavaScript Unit Tests, Created by Paul Bakaus

July 22nd, 2013 by Bill McGee

Paul Bakaus, CTO of Studio 5 at Zynga, and a prodigious doer of things who created jQuery UI and the Aves Engine, created Mocha Sauce for use by the Zynga development team, and he was kind enough to write a little about it. Read on to learn about why he created Mocha Sauce. You can find Mocha Sauce on Github.

Mocha Sauce is a bleeding edge project that connects Mocha with Sauce Labs. It started as a fork of mocha-cloud (a project that unfortunately doesn’t seem to be maintained any longer), but now lives on its own and comes with lots of additional features and improvements. It’s definitely not stable, but it is being used in production for an unannounced game here within Studio 5 at Zynga, and we like it so far!

Mocha Sauce for JavaScript Unit Testing in the Cloud

A screenshot of what running tests with Mocha Sauce looks like.

So why in the world did I create it? Read on.

Requirements, and trying not to reinvent the wheel

My team and I needed our unit tests to run in the browser (during development), as a pre-commit hook (running in a headless browser), in multiple remote VMs / browsers, and finally, we needed them to be integrated with Jenkinsfor continuous integration.

Based on these requirements, we were planning to reuse as many existing libraries or frameworks as possible, and we arrived at the following set of third party dependencies:

Mocha for actual unit testing, allowing me to run my unit tests in the browser. Mocha is very feature-rich and modular, and doesn’t enforce a particular loading or coding style. Since testing environments are always subject to environmental changes (per project and company), being modular and non-enforcing is essential. Mocha also has been around for a while, and there’s quite a bit of community around it.

mocha-phantomjs to run the same Mocha test site in a terminal using PhantomJS, which made it trivial to implement a pre-commit hook that runs the test suite. mocha-phantomjs is amazing, as it supports a large number of Mocha reporters for output.

Sauce Labs is an amazing service that allows you to automatically instantiate a pristine remote virtual machine that runs a specific browser on a specific platform. With WebDriver on node.js, you can spin up a VM and then instrument the remote browser using the WebDriver API. It’s really simple and definitely worth the money.

The missing link

But now that we can spin up remote VMs through node.js, how do we run our unit test suite in that VM, report back its output and collect it somewhere?

This is where Mocha Sauce comes in. It builds on the excellent, but discontinued work of mocha-cloud and mocha-cloud-grid-view and adds many advanced features – we, for instance, needed to be able to use Sauce Connect to create a local tunnel, which then allows you to test firewalled or local urls in the VMs, and we also needed to integrate it with Jenkins, amongst many other smaller things.

I could copy all of its documentation and paste it here but that would be dumb. I encourage you to simply read into the docs to get an idea about its features and usage. There’s also in-depth information of how to set it up.

Keep in mind that this is alpha code, and probably will break here and there. If you do have requirements similar to mine, give it a shot and submit lots of feedback via Twitter to @pbakaus or email to pbakaus @ zynga. Now test your units!

Guest Post: Testing JavaScript with Yeti and Sauce Labs WebDriver with Ryuichi Okumura

June 4th, 2013 by Bill McGee

When we read YUI contributor Ryuichi Okumura‘s blog post on testing JavaScript with Yeti and Sauce, we thought it was an awesome use of Sauce, and wanted to share it with you. Ryuichi kindly gave us the green light to post-cross this, so read on to hear about how he’s using Sauce for JS testing, and check out his Twitter and Github.

We’ve recently been quite busy developing a number of JavaScript testing environments, such as test frameworks and test runners. Yeti, developed by the YUI team, is one of the test runners. As for the available test frameworks, Yeti supports the major libraries—not only YUI Test, but QUnit, Jasmine, and Mocha. I’ve shown examples previously where Yeti and QUnit were used together.

saucelabs-yui

On top of JavaScript testing, we can’t forget the devices and browsers on which the testing is being done in the first place. With the spread of so many different types of mobile devices and so many OSes and browsers in development, it’s become important to carry out tests on the actual browsers. In these conditions, services have appeared that allow you to open and operate the actual browsers online. Today, I’d like to show you a test using one of those services, Sauce Labs. Sauce Labs is a cloud service that offers many different mobile and desktop browser environments. Also, one of Sauce Labs’ major features is that it supports Selenium testing with the WebDriver protocol. Just like Yeti, since WebDriver protocol is supported, you can boot the browser on the cloud through the command line and run a JavaScript test.

First, You can sign up easy Sauce Labs account if you doesn’t have a Sauce Labs account. Sauce Labs provides some free and paid plans. Also there is “Open Sauce” plan, this is very kind and helping plan for OSS developers like you.

Sign up when you’re done, let’s prepare for the testing environment. Check your access key and download Sauce-Connect.jar file from Sauce Connect guide.

Start Sauce Connect:

java -jar Sauce-Connect.jar <username> <access key>

Install Yeti via npm command if you haven’t install yet.

npm install -g yeti

Start Yeti hub server while specify Sauce Labs WebDriver endpoint:

yeti --server --wd-url http://<username>:<access key>@ondemand.saucelabs.com:80
Yeti Hub started. LAN: http://10.0.1.13:9000
                  Local: http://localhost:9000

And, Launch browser you like while specify a test file:

yeti --browser chrome src/date/tests/unit/*.html
Waiting for Hub to launch browsers...
  Agent connected: Chrome (26.0.1410.64) / Windows 7 from 10.0.1.13
✓ Testing started on Chrome (26.0.1410.64) / Windows 7
✓ Agent completed: Chrome (26.0.1410.64) / Windows 7
✓ 22 tests passed! (35 seconds)
  Agent disconnected: Chrome (26.0.1410.64) / Windows 7 from 10.0.1.13

That’s all. It’s able to test on the browser in the cloud even if you don’t have it!