• Stars
    star
    199
  • Rank 189,925 (Top 4 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created almost 11 years ago
  • Updated 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Karma plugin. Launch any browser on SauceLabs!

karma-sauce-launcher

js-standard-style npm version npm downloads semantic-release

Build Status

Karma Plus Sauce

Run your unit tests on Sauce Labs' browser cloud!

Installation

Install karma-sauce-launcher as a devDependency in your package.json:

npm install karma-sauce-launcher --save-dev

Usage

This launcher is typically used in CI to run your unit tests across many browsers and platforms on Sauce Labs. However, you can also use it locally to debug tests in browsers not available on your machine. It is expected that you are already familiar with Karma when configuring this launcher, so if you are new to Karma, head over to the Karma website.

The Sauce Labs platform configurator can help to find the correct configuration for your desired test platform.

Adding karma-sauce-launcher to an existing Karma config

To configure this launcher, you need to add two properties to your top-level Karma config, sauceLabs and customLaunchers, set the browsers array to use Sauce Labs browsers, and add the sauceLabs reporter.

The sauceLabs object defines global properties for each browser/platform while the customLaunchers object configures individual browsers. The sauceLabs reporter allows your tests results to be properly displayed on https://saucelabs.com. Here is a sample Karma config to get the launcher running:

module.exports = function(config) {
  // Example set of browsers to run on Sauce Labs
  // Check out https://saucelabs.com/platforms for all browser/platform combos
  var customLaunchers = {
    // Old JSONWP way of setting the capabilities
    sl_chrome: {
      base: 'SauceLabs',
      browserName: 'chrome',
      platform: 'Windows 10',
    },
    sl_firefox: {
      base: 'SauceLabs',
      browserName: 'firefox',
      version: 'latest'
    },
    sl_ie_11: {
      base: 'SauceLabs',
      browserName: 'internet explorer',
      platform: 'Windows 8.1',
    },
    // Mobile settings
    // 1. Go to https://wiki.saucelabs.com/display/DOCS/Platform+Configurator#/
    // 2. Select Appium iOS,Android
    // 3. Configure your device
    //    Don't forget to provide the `appiumVersion`
    sl_ios_safari: {
      base: 'SauceLabs',
      deviceName: 'iPhone 11 Simulator',
      platformVersion: '13.4',
      platformName: 'iOS',
      browserName: 'Safari',
      appiumVersion: '1.17.1',
      deviceOrientation: 'portrait'
    },
    // !!!!IMPORTANT!!!!
    // If you want to use an Android emulator then you can't use localhost.
    // Because an Android emulator is a VM it will go to it's own localhost
    // and the test will fail. Make change the `hostname` to your
    // local ip
    sl_android: {
      base: 'SauceLabs',
      deviceName: 'Android GoogleAPI Emulator',
      platform: 'Android',
      version: '11.0',
      browserName: 'chrome',
      appiumVersion: '1.18.1',
      deviceOrientation: 'portrait'
    },
    // For W3C way of setting the capabilities check
    // https://wiki.saucelabs.com/display/DOCS/Platform+Configurator#/
    // And select WebDriver (W3C) Selenium 3/4, Webdriver.io
    sl_chromeW3C: {
      base: 'SauceLabs',
      browserName: 'chrome',
      browserVersion: 'latest',
      'sauce:options':{
        tags: ['w3c-chrome']
      }
    },
  }

  config.set({

    // The rest of your karma config is here
    // ...
    sauceLabs: {
        testName: 'Web App Unit Tests'
    },
    customLaunchers: customLaunchers,
    browsers: Object.keys(customLaunchers),
    reporters: ['dots', 'saucelabs'],
    singleRun: true
  })
}

Note: this config assumes that process.env.SAUCE_USERNAME and process.env.SAUCE_ACCESS_KEY are set.

Example karma-sauce-launcher configs

For example configs using this launcher (using Travis CI), check out this repo's karma file, or AngularJS' Karma config.

Example results in Sauce Labs

Version 4.2.0 and lower of this module will give you the following result in Sauce Labs, no matter how many tests you execute.

Sauce Logs

As of version 4.3.0 the logs are replaced with the test names and results of the individual tests that have been executed on Sauce Labs, including the execution url in the logs.

Successful run Sauce Successful Logs

Unsuccessful run Sauce Successful Logs

Execution url Sauce Successful Logs

sauceLabs config properties shared across all browsers

username

Type: String Default: process.env.SAUCE_USERNAME

Your Sauce Labs username (if you don't have an account, you can sign up here).

accessKey

Type: String Default: process.env.SAUCE_ACCESS_KEY

Your Sauce Labs access key which you will see on your account page.

region

Type: String

Detect datacenter to run tests in. Can be either eu or us.

headless

Type: Boolean

If set to true tests are being run on Sauce Labs headless platform on us-east-1. This option will be ignored if region is set.

proxy

Type: String

Proxy for connecting to Sauce REST API, which is used to communicate job updates of pass/fail.

startConnect

Type: Boolean Default: true

If true, Sauce Connect will be started automatically. Set this to false if you are launching tests locally but want to start Sauce Connect via a binary manually in the background to improve test speed.

connectOptions

Type: Object Default:

{
  username: 'yourUsername',
  accessKey: 'yourAccessKey',
  tunnelIdentifier: 'autoGeneratedTunnelID'
}

Options to send to Sauce Connect.

Check here for all available options. All parameters have to be applied camel cased instead of with hyphens.

build

Type: String Default: One of the following environment variables: process.env.BUILD_NUMBER process.env.BUILD_TAG process.env.CI_BUILD_NUMBER process.env.CI_BUILD_TAG process.env.TRAVIS_BUILD_NUMBER process.env.CIRCLE_BUILD_NUM process.env.DRONE_BUILD_NUMBER

ID of the build currently running. This should be set by your CI.

testName

Type: String Default: 'Karma test'

Name of the unit test group you are running.

tunnelIdentifier

Type: String

Sauce Connect can proxy multiple sessions, this is an id of a session.

tags

Type: Array of Strings

Tags to use for filtering jobs in your Sauce Labs account.

recordVideo

Type: Boolean Default: false

Set to true if you want to record a video of your Karma session.

recordScreenshots

Type: Boolean Default: true

Set to false if you don't want to record screenshots.

public

Type: String Default: null

Control who can view job details. Available visibility levels are documented on the SauceLabs website.

customData

Type: Object Default: {}

Send arbitrary data alongside your tests. See the SauceLabs documentation for more details.

customLaunchers config properties

The customLaunchers object has browser names as keys and configs as values. Documented below are the different properties which you can configure for each browser/platform combo.

Note: You can learn about the available browser/platform combos on the Sauce Labs platforms page, platforms configurator page and REST API page.

base

Type: String Required: true

This defines the base configuration for the launcher. In this case it should always be SauceLabs so that browsers can use the base Sauce Labs config defined at the root sauceLabs property.

browserName

Type: String Required: true

Name of the browser.

browserVersion

Type: String Default: Latest browser version for all browsers except Chrome

Version of the browser to use.

platformName

Type: String Default: 'Linux' for Firefox/Chrome, 'Windows 7' for IE/Safari

Name of platform to run browser on.

sauce:options

Specific Sauce Labs capability options.

Behind the scenes

This launcher uses Sauce Connect in the background. If you are interested in security or want to see the system requirements, head over to the documentation.

More Repositories

1

karma

Spectacular Test Runner for JavaScript
JavaScript
11,920
star
2

karma-coverage

A Karma plugin. Generate code coverage.
JavaScript
767
star
3

karma-jasmine

A Karma plugin - adapter for Jasmine testing framework.
JavaScript
543
star
4

grunt-karma

Grunt plugin for Karma.
JavaScript
471
star
5

karma-chrome-launcher

A Karma plugin. Launcher for Chrome and Chrome Canary.
JavaScript
466
star
6

karma-mocha

A Karma plugin. Adapter for Mocha testing framework.
JavaScript
380
star
7

gulp-karma

Example of using Karma with Gulp.
JavaScript
310
star
8

karma-phantomjs-launcher

A Karma plugin. Launcher for PhantomJS.
JavaScript
281
star
9

karma-ng-html2js-preprocessor

A Karma plugin. Compile AngularJS 1.x and 2.x templates to JavaScript on the fly.
CoffeeScript
266
star
10

karma-junit-reporter

A Karma plugin. Report results in junit xml format.
JavaScript
175
star
11

karma-browserstack-launcher

A Karma plugin. Launch any browser on BrowserStack!
JavaScript
150
star
12

karma-firefox-launcher

A Karma plugin. Launcher for Firefox.
JavaScript
102
star
13

karma-html2js-preprocessor

A Karma plugin. Convert HTML files into JS strings to serve them in a script tag.
CoffeeScript
74
star
14

karma-commonjs

A Karma plugin. Test CommonJS modules.
JavaScript
73
star
15

karma-webdriver-launcher

A plugin for Karma. Launch any browser with WebDriver.
JavaScript
66
star
16

karma-ie-launcher

A Karma plugin. Launcher for Internet Explorer.
JavaScript
59
star
17

karma-coffee-preprocessor

A Karma plugin. Compile coffee script on the fly.
JavaScript
53
star
18

karma-cli

The Karma command line interface.
JavaScript
52
star
19

karma-qunit

A Karma plugin. Adapter for QUnit testing framework.
JavaScript
51
star
20

maven-karma-plugin

Maven plugin for running tests using Karma.
Java
45
star
21

karma-requirejs

A Karma plugin. Adapter for RequireJS framework.
JavaScript
39
star
22

karma-teamcity-reporter

A Karma plugin. Report results for Teamcity CI.
JavaScript
34
star
23

karma-intellij

Reporter for IntelliJ / WebStorm.
JavaScript
34
star
24

karma-growl-reporter

A Karma plugin. Report results with growl.
JavaScript
27
star
25

karma-ng-scenario

A Karma plugin. Adapter for Angular's Scenario Runner.
JavaScript
25
star
26

karma-runner.github.com

Homepage of Karma - The Spectacular JavaScript Test Runner.
HTML
24
star
27

karma-edge-launcher

A Karma plugin. Launcher for Microsoft Edge.
JavaScript
21
star
28

karma-safari-launcher

A Karma plugin. Launcher for Safari.
JavaScript
19
star
29

karma-closure

A Karma plugin. Resolve Google Closure dependencies on the fly.
JavaScript
18
star
30

karma-dart

DEPRECATED. A plugin for Dart language.
JavaScript
17
star
31

karma-slimerjs-launcher

A Karma launcher for SlimerJS
JavaScript
13
star
32

karma-traceur-preprocessor

A Karma plugin. Compile ES6 script on the fly using traceur-compiler.
JavaScript
13
star
33

karma-nodeunit

A Karma plugin - adapter for Node unit testing framework.
JavaScript
12
star
34

karma-script-launcher

A Karma plugin. Launcher for custom scripts.
JavaScript
9
star
35

integration-tests

JavaScript
8
star
36

karma-dojo

A Karma plugin. Adapter for Dojo Toolkit.
JavaScript
7
star
37

karma-opera-launcher

A Karma plugin. Launcher for Opera.
JavaScript
7
star
38

test-device-manager

Keep-alive test browsers and redirect them to a test server on command.
JavaScript
6
star
39

karma-ember-preprocessor

A Karma plugin. Preprocessor for Ember.js templates (handlebars).
JavaScript
6
star
40

karma-googmodule-preprocessor

A Karma preprocessor to handle Closure's goog.module() system
JavaScript
5
star
41

shared-karma-files

Shared configs for all the Karma repos.
CoffeeScript
2
star