1 | # karma-sauce-launcher
|
2 |
|
3 | [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/karma-runner/karma-sauce-launcher)
|
4 | [![npm version](https://img.shields.io/npm/v/karma-sauce-launcher.svg?style=flat-square)](https://www.npmjs.com/package/karma-sauce-launcher) [![npm downloads](https://img.shields.io/npm/dm/karma-sauce-launcher.svg?style=flat-square)](https://www.npmjs.com/package/karma-sauce-launcher)
|
5 | [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
|
6 |
|
7 | [![Build Status](https://img.shields.io/travis/karma-runner/karma-sauce-launcher/master.svg?style=flat-square)](https://travis-ci.org/karma-runner/karma-sauce-launcher) [![Dependency Status](https://img.shields.io/david/karma-runner/karma-sauce-launcher.svg?style=flat-square)](https://david-dm.org/karma-runner/karma-sauce-launcher) [![devDependency Status](https://img.shields.io/david/dev/karma-runner/karma-sauce-launcher.svg?style=flat-square)](https://david-dm.org/karma-runner/karma-sauce-launcher#info=devDependencies)
|
8 |
|
9 |
|
10 | ![Karma Plus Sauce](/images/karma-plus-sauce.png)
|
11 |
|
12 | > Run your unit tests on [Sauce Labs](https://saucelabs.com/)' browser cloud!
|
13 |
|
14 |
|
15 | ## Installation
|
16 |
|
17 | Install `karma-sauce-launcher` as a `devDependency` in your package.json:
|
18 |
|
19 | ```bash
|
20 | npm install karma-sauce-launcher --save-dev
|
21 | ```
|
22 |
|
23 | ## Usage
|
24 |
|
25 | 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](http://karma-runner.github.io/).
|
26 |
|
27 | The [Sauce Labs platform configurator](https://wiki.saucelabs.com/display/DOCS/Platform+Configurator/#/) can help to find the correct configuration for your desired test platform.
|
28 |
|
29 | ### Adding karma-sauce-launcher to an existing Karma config
|
30 |
|
31 | 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.
|
32 |
|
33 | 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:
|
34 |
|
35 | ```js
|
36 | module.exports = function(config) {
|
37 | // Example set of browsers to run on Sauce Labs
|
38 | // Check out https://saucelabs.com/platforms for all browser/platform combos
|
39 | var customLaunchers = {
|
40 | // Old JSONWP way of setting the capabilities
|
41 | sl_chrome: {
|
42 | base: 'SauceLabs',
|
43 | browserName: 'chrome',
|
44 | platform: 'Windows 10',
|
45 | },
|
46 | sl_firefox: {
|
47 | base: 'SauceLabs',
|
48 | browserName: 'firefox',
|
49 | version: 'latest'
|
50 | },
|
51 | sl_ie_11: {
|
52 | base: 'SauceLabs',
|
53 | browserName: 'internet explorer',
|
54 | platform: 'Windows 8.1',
|
55 | },
|
56 | // Mobile settings
|
57 | // 1. Go to https://wiki.saucelabs.com/display/DOCS/Platform+Configurator#/
|
58 | // 2. Select Appium iOS,Android
|
59 | // 3. Configure your device
|
60 | // Don't forget to provide the `appiumVersion`
|
61 | sl_ios_safari: {
|
62 | base: 'SauceLabs',
|
63 | deviceName: 'iPhone 11 Simulator',
|
64 | platformVersion: '13.4',
|
65 | platformName: 'iOS',
|
66 | browserName: 'Safari',
|
67 | appiumVersion: '1.17.1',
|
68 | deviceOrientation: 'portrait'
|
69 | },
|
70 | // !!!!IMPORTANT!!!!
|
71 | // If you want to use an Android emulator then you can't use localhost.
|
72 | // Because an Android emulator is a VM it will go to it's own localhost
|
73 | // and the test will fail. Make change the `hostname` to your
|
74 | // local ip
|
75 | sl_android: {
|
76 | base: 'SauceLabs',
|
77 | deviceName: 'Android GoogleAPI Emulator',
|
78 | platform: 'Android',
|
79 | version: '11.0',
|
80 | browserName: 'chrome',
|
81 | appiumVersion: '1.18.1',
|
82 | deviceOrientation: 'portrait'
|
83 | },
|
84 | // For W3C way of setting the capabilities check
|
85 | // https://wiki.saucelabs.com/display/DOCS/Platform+Configurator#/
|
86 | // And select WebDriver (W3C) Selenium 3/4, Webdriver.io
|
87 | sl_chromeW3C: {
|
88 | base: 'SauceLabs',
|
89 | browserName: 'chrome',
|
90 | browserVersion: 'latest',
|
91 | 'sauce:options':{
|
92 | tags: ['w3c-chrome']
|
93 | }
|
94 | },
|
95 | }
|
96 |
|
97 | config.set({
|
98 |
|
99 | // The rest of your karma config is here
|
100 | // ...
|
101 | sauceLabs: {
|
102 | testName: 'Web App Unit Tests'
|
103 | },
|
104 | customLaunchers: customLaunchers,
|
105 | browsers: Object.keys(customLaunchers),
|
106 | reporters: ['dots', 'saucelabs'],
|
107 | singleRun: true
|
108 | })
|
109 | }
|
110 | ```
|
111 |
|
112 | **Note: this config assumes that `process.env.SAUCE_USERNAME` and `process.env.SAUCE_ACCESS_KEY` are set.**
|
113 |
|
114 | ### Example karma-sauce-launcher configs
|
115 |
|
116 | For example configs using this launcher (using Travis CI), check out this repo's [karma file](https://github.com/karma-runner/karma-sauce-launcher/tree/master/examples/karma.conf-ci.js), or [AngularJS' Karma config](https://github.com/angular/angular.js/blob/master/karma-shared.conf.js).
|
117 |
|
118 | ### Example results in Sauce Labs
|
119 | 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.
|
120 |
|
121 | ![Sauce Logs](/images/saucelabs-old.png)
|
122 |
|
123 | As of version [4.3.0](https://github.com/karma-runner/karma-sauce-launcher/releases/tag/v4.3.0) the logs are replaced with the
|
124 | test names and results of the individual tests that have been executed on Sauce Labs, including the execution url in the logs.
|
125 |
|
126 | **Successful run**
|
127 | ![Sauce Successful Logs](/images/new-sauce-logs-success.png)
|
128 |
|
129 | **Unsuccessful run**
|
130 | ![Sauce Successful Logs](/images/new-sauce-logs-failure.png)
|
131 |
|
132 | **Execution url**
|
133 | ![Sauce Successful Logs](/images/sauce-execution-url.png)
|
134 |
|
135 | ## `sauceLabs` config properties shared across all browsers
|
136 |
|
137 | ### username
|
138 | Type: `String`
|
139 | Default: `process.env.SAUCE_USERNAME`
|
140 |
|
141 | Your Sauce Labs username (if you don't have an account, you can sign up [here](https://saucelabs.com/signup/plan/free)).
|
142 |
|
143 | ### accessKey
|
144 | Type: `String`
|
145 | Default: `process.env.SAUCE_ACCESS_KEY`
|
146 |
|
147 | Your Sauce Labs access key which you will see on your [account page](https://saucelabs.com/account).
|
148 |
|
149 | ### region
|
150 | Type: `String`
|
151 |
|
152 | Detect datacenter to run tests in. Can be either `eu` or `us`.
|
153 |
|
154 | ### headless
|
155 | Type: `Boolean`
|
156 |
|
157 | 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.
|
158 |
|
159 | ### proxy
|
160 | Type: `String`
|
161 |
|
162 | Proxy for connecting to Sauce REST API, which is used to communicate job updates of pass/fail.
|
163 |
|
164 | ### startConnect
|
165 | Type: `Boolean`
|
166 | Default: `true`
|
167 |
|
168 | If `true`, Sauce Connect will be started automatically.
|
169 | Set this to `false` if you are launching tests locally but want to start Sauce Connect via [a binary](https://wiki.saucelabs.com/display/DOCS/Downloading+Sauce+Connect+Proxy) manually in the background to improve test speed.
|
170 |
|
171 | ### connectOptions
|
172 | Type: `Object`
|
173 | Default:
|
174 | ```js
|
175 | {
|
176 | username: 'yourUsername',
|
177 | accessKey: 'yourAccessKey',
|
178 | tunnelIdentifier: 'autoGeneratedTunnelID'
|
179 | }
|
180 | ```
|
181 |
|
182 | Options to send to Sauce Connect.
|
183 |
|
184 | Check [here](https://wiki.saucelabs.com/display/DOCS/Sauce+Connect+Proxy+Command-Line+Quick+Reference+Guide) for all available options.
|
185 | All parameters have to be applied camel cased instead of with hyphens.
|
186 |
|
187 | ### build
|
188 | Type: `String`
|
189 | Default: *One of the following environment variables*:
|
190 | `process.env.BUILD_NUMBER`
|
191 | `process.env.BUILD_TAG`
|
192 | `process.env.CI_BUILD_NUMBER`
|
193 | `process.env.CI_BUILD_TAG`
|
194 | `process.env.TRAVIS_BUILD_NUMBER`
|
195 | `process.env.CIRCLE_BUILD_NUM`
|
196 | `process.env.DRONE_BUILD_NUMBER`
|
197 |
|
198 | ID of the build currently running. This should be set by your CI.
|
199 |
|
200 | ### testName
|
201 | Type: `String`
|
202 | Default: `'Karma test'`
|
203 |
|
204 | Name of the unit test group you are running.
|
205 |
|
206 | ### tunnelIdentifier
|
207 | Type: `String`
|
208 |
|
209 | Sauce Connect can proxy multiple sessions, this is an id of a session.
|
210 |
|
211 | ### tags
|
212 | Type: `Array of Strings`
|
213 |
|
214 | Tags to use for filtering jobs in your Sauce Labs account.
|
215 |
|
216 | ### recordVideo
|
217 | Type: `Boolean`
|
218 | Default: `false`
|
219 |
|
220 | Set to `true` if you want to record a video of your Karma session.
|
221 |
|
222 | ### recordScreenshots
|
223 | Type: `Boolean`
|
224 | Default: `true`
|
225 |
|
226 | Set to `false` if you don't want to record screenshots.
|
227 |
|
228 | ### public
|
229 | Type: `String`
|
230 | Default: `null`
|
231 |
|
232 | Control who can view job details. Available visibility levels are documented on
|
233 | the [SauceLabs website](https://wiki.saucelabs.com/display/DOCS/Test+Configuration+Options#TestConfigurationOptions-JobVisibility).
|
234 |
|
235 | ### customData
|
236 | Type: `Object`
|
237 | Default: `{}`
|
238 |
|
239 | Send arbitrary data alongside your tests. See
|
240 | the [SauceLabs documentation](https://wiki.saucelabs.com/display/DOCS/Test+Configuration+Options#TestConfigurationOptions-CustomData)
|
241 | for more details.
|
242 |
|
243 |
|
244 | ## `customLaunchers` config properties
|
245 |
|
246 | 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.
|
247 |
|
248 | *Note: You can learn about the available browser/platform combos on the [Sauce Labs platforms page](https://saucelabs.com/platforms), [platforms configurator page](https://docs.saucelabs.com/reference/platforms-configurator/#/) and [REST API page](https://docs.saucelabs.com/reference/rest-api/#get-supported-platforms).*
|
249 |
|
250 | ### base
|
251 | Type: `String`
|
252 | Required: `true`
|
253 |
|
254 | 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.
|
255 |
|
256 | ### browserName
|
257 | Type: `String`
|
258 | Required: `true`
|
259 |
|
260 | Name of the browser.
|
261 |
|
262 | ### browserVersion
|
263 | Type: `String`
|
264 | Default: Latest browser version for all browsers except Chrome
|
265 |
|
266 | Version of the browser to use.
|
267 |
|
268 | ### platformName
|
269 | Type: `String`
|
270 | Default: `'Linux'` for Firefox/Chrome, `'Windows 7'` for IE/Safari
|
271 |
|
272 | Name of platform to run browser on.
|
273 |
|
274 | ### `sauce:options`
|
275 |
|
276 | Specific Sauce Labs capability [options](https://wiki.saucelabs.com/display/DOCS/Test+Configuration+Options).
|
277 |
|
278 | ## Behind the scenes
|
279 |
|
280 | 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](https://wiki.saucelabs.com/display/DOCS/Getting+Started+with+Sauce+Connect+Proxy).
|