- Platform Configurator
- Getting Started with Selenium for Automated Website Testing
- Getting Started with Appium for Mobile Native Application Testing
- Selenium Bootcamp by Dave Haeffner
- Appium Bootcamp by Dave Haeffner and Matthew Edwards
The GitHub repository for grunt-saucelabs contains example files including sample
package.json files, and HTML test pages for frameworks including YUI, Mocha, Jasmine, QUnit, and custom frameworks.
Grunt-saucelabs is available as a node package. To install, run this command.
To use the task in
grunt.js, load the
It can also be included as a
package.json in your node project, as described in the next section.
There are two main files you need to configure to use your testing framework with grunt-saucelabs,
The package.json file contains meta-data information about your project. You can find full documentation about how to write this file on the npmjs.com website, but for using grunt-saucelabs with your testing framework, the most important section is the
devDependencies, which is used to load the dependencies for your project. You should set up this section of your file like this:
GruntFile.js file will load the
package.json, so it's important to make sure you have this section set up correctly in order to run grunt-saucelabs.
GruntFile.js file is where all the action happens. It starts up a web server and lets Sauce Connect access your tests on a
localhost port, sets the browser and operating system configurations for your test, and lets you set the options for your test such as the URL of your test page, the name of the test, tags, and other Sauce Labs job settings. There are four sections in this file:
var browserswhere you set the browsers and operating systems you want to test against.
grunt.initConfigsection that sets up the Sauce Connect connection to
Setting localhost Ports
This example file sets Sauce Connect to use port 9999, but it can also connect to any other port on localhost.
optionssection where you set the options for your test.
optionsobject was introduced in
grunt-saucelabs-*version 4.0.0 to be compatible with email@example.com. The topic Parameters for Grunt-Saucelabs Tasks includes a full list of options that you can set up. Check out Best Practice: Use Environment Variables for Authentication Credentials for information on setting up your
keyas environment variables.
grunt.registerTask, where you define the task alias that you will call from the command line. In the Sample GruntFile.js files this alias is
default, and it runs the tasks
connectand the task for the specified testing framework. For example, in the
GruntFile.jsfor Mocha, the second task is named
saucelabs-mocha. The Grunt documentation has more information on defining tasks and arguments for the task alias.
You can find example
GruntFile.js files for each of the testing frameworks in Sample GruntFile.js Files, but they are all essentially the same. This example is for Mocha. Check out the official Grunt documentation on the GruntFile.js for a complete explanation of how to set up your own files.
You can also clone this script directly from our GitHub repo
In the example
options section, you can see that the
build option is set to
process.env.TRAVIS_JOB_ID, which enables these test results to be incorporated into a TravisCI continuous build process. Check out the topics under Using Sauce Labs with Continuous Integration Platforms to see how to use Sauce with CI platforms like Jenkins and Bamboo.
Finding Your Username and Access Key
You can find your Sauce Labs username and access key in the User Profile > User Settings section of your Sauce Labs dashboard.
Running the Task
With everything set up, you can run your task from the command line with a single command that references your task alias (
default in the example file).
This will start up the Web server, and you can then access your tests at the page referenced as the
URL in the
options section of your
GruntFile.js to see how they have executed against the browsers you defined.