Sauce Labs is proud to announce a new major upgrade to our Node.JS API wrapper. After many years of amazing maintenance work by people like Dan Jenkins, Daniel Perez Alvarez and others we assumed ownership of the project and will continue to maintain it going forward. The new version (v2) of the API wrapper comes with a lot of new features and support for a variety of API endpoints that haven’t been supported before. The package was completely rewritten and updated to leverage the latest and greatest Node.JS features. As such, it is a major version change, one that requires you to modify the places where you are using it in your current project.
One of the biggest new features is the support for a whole lot of more Sauce Labs API endpoints, including the API to manage your real device tests as well as our new performance API. In addition, you can now easily switch between our data center regions by providing a configuration property when initiating an instance of the package. To make using and consuming data from our API easier, we decided to also provide a CLI command with that package. With this, you can access the test data by typing the command “sl” command, and the endpoint you want to query, into your command line interface.
The easiest way to install the package is by using NPM:
$
npm install
saucelabs
If you use the package programmatically you can configure it to so that it talks to the correct API endpoint. See the list of available options here. Once you have created an instance you can access all the API endpoints by calling the name of the specific endpoint as a command, e.g., you can fetch all jobs of your user by executing:
import SauceLabs from '
saucelabs';
(async () => {
const myAccount = new SauceLabs();
// get job details of last run job
const job = await user.listJobs(
process.env.SAUCE_USERNAME,
{ limit: 1, full: true }
);
console.log(job);
/**
* outputs:
* { jobs:
[ { browser_short_version: '72',
id: 'dc08ca0c7fa14eee909a093d11567328',
...
browser: 'googlechrome' } ] }
*/
})
Every command call returns a promise that will be resolved once the response is received or gets rejected if a problem occurs. Note that the package can access your Sauce username and access key from the environment if they are set as SAUCE_USERNAME and SAUCE_ACCESS_KEY, however you can also pass them in as parameters.
If you want to access the API from the command line to, for example, download job assets or look into job information the best way to use the package is as a globally installed package. You can install it this way by passing in -g as a parameter to the NPM install command:
$
npm install -g
saucelabs
Now, in order to get the same result as in the script above, you just need to call:
$ sl listJobs Slavocado --limit 1 --full
This will print out the latest job of the user named Slavocado. Another useful command that folks at Sauce use regularly is the command to download job assets of a particular test. This can be done by providing the job id and log name as a parameter like so:
$ sl downloadJobAsset 220c179b3f6f4c109e1cde17dcfeba6a selenium-server.log
# or access a job that was running in our EU data center
$ sl downloadJobAsset 543e4be0db2d423db7dedc412d5cba40 log.json -r eu
You can find a list of all available commands that you can access programmatically or via a command line interface here. If you have questions or issues using the new version, feel free to reach out to us by creating an issue in the project. Please also let us know if you have any ideas on how we can improve this tool even more.
Happy Testing!
We <3 Open Source at Sauce Labs and encourage Saucers to contribute to projects like Appium, Selenium and their own initiatives.