Skip to content

Commit 0ba4842

Browse files
Merge pull request #225 from karma-runner/fix/issue-210-w3c
fix: fixes issues with older browsers / caps
2 parents 62c71ef + 15cb9b7 commit 0ba4842

File tree

4 files changed

+49
-15
lines changed

4 files changed

+49
-15
lines changed

README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ module.exports = function(config) {
3737
// Example set of browsers to run on Sauce Labs
3838
// Check out https://saucelabs.com/platforms for all browser/platform combos
3939
var customLaunchers = {
40+
// Old JSONWP way of setting the capabilities
4041
sl_chrome: {
4142
base: 'SauceLabs',
4243
browserName: 'chrome',
@@ -67,7 +68,18 @@ module.exports = function(config) {
6768
version: '4.4',
6869
deviceName: 'Samsung Galaxy S3 Emulator',
6970
deviceOrientation: 'portrait'
70-
}
71+
},
72+
// For W3C way of setting the capabilies check
73+
// https://wiki.saucelabs.com/display/DOCS/Platform+Configurator#/
74+
// And select WebDriver (W3C) Selenium 3/4, Webdriver.io
75+
sl_chromeW3C: {
76+
base: 'SauceLabs',
77+
browserName: 'chrome',
78+
browserVersion: 'latest',
79+
'sauce:options':{
80+
tags: ['w3c-chrome']
81+
}
82+
},
7183
}
7284

7385
config.set({

examples/karma.conf-ci.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,28 @@ module.exports = function (config) {
1010
sl_chrome: {
1111
base: 'SauceLabs',
1212
browserName: 'chrome',
13-
version: 'latest'
13+
version: 'latest',
14+
tags: ['jsonwp-chrome']
15+
},
16+
sl_chromeW3C: {
17+
base: 'SauceLabs',
18+
browserName: 'chrome',
19+
browserVersion: 'latest',
20+
'sauce:options':{
21+
tags: ['w3c-chrome']
22+
}
1423
},
1524
sl_firefox: {
1625
base: 'SauceLabs',
1726
browserName: 'firefox',
18-
version: 'latest'
27+
version: 'latest',
28+
tags: ['jsonwp-firefox']
1929
},
2030
sl_ie_11: {
2131
base: 'SauceLabs',
2232
browserName: 'internet explorer',
23-
version: 'latest'
33+
version: 'latest',
34+
tags: ['jsonwp-ie11']
2435
}
2536
};
2637

src/process-config.ts

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import {bootstrap} from 'global-agent'
2+
import {isW3C} from "./utils";
23

3-
export function processConfig (config: any = {}, args: any = {}) {
4+
export function processConfig(config: any = {}, args: any = {}) {
45
const username = config.username || process.env.SAUCE_USERNAME;
56
const accessKey = config.accessKey || process.env.SAUCE_ACCESS_KEY;
67
const startConnect = config.startConnect !== false;
78

89
let tunnelIdentifier = args.tunnelIdentifier || config.tunnelIdentifier;
910

10-
// TODO: This option is very ambiguous because it technically only affects the reporter. Consider
11+
// TODO: This option is very ambiguous because it technically only affects the reporter. Consider
1112
// renaming in the future.
1213
const sauceApiProxy = args.proxy || config.proxy;
1314
if (sauceApiProxy) {
@@ -20,9 +21,7 @@ export function processConfig (config: any = {}, args: any = {}) {
2021
}
2122

2223
// Browser name that will be printed out by Karma.
23-
const browserName = args.browserName +
24-
(args.version ? ' ' + args.version : '') +
25-
(args.platform ? ' (' + args.platform + ')' : '');
24+
const browserName = `${args.browserName} ${args.browserVersion || args.version || ''} ${args.platformName || args.platform || ''}`;
2625

2726
// In case "startConnect" is enabled, and no tunnel identifier has been specified, we just
2827
// generate one randomly. This makes it possible for developers to use "startConnect" with
@@ -53,20 +52,27 @@ export function processConfig (config: any = {}, args: any = {}) {
5352
};
5453

5554
// transform JWP capabilities into W3C capabilities for backward compatibility
56-
args.browserVersion = args.browserVersion || args.version || 'latest'
57-
args.platformName = args.platformName || args.platform || 'Windows 10'
58-
// delete JWP capabilities
55+
if (isW3C(args)) {
56+
args.browserVersion = args.browserVersion || args.version || 'latest'
57+
args.platformName = args.platformName || args.platform || 'Windows 10'
58+
args['sauce:options'] = { ...(args['sauce:options'] || {}), ...capabilitiesFromConfig }
59+
60+
// delete JWP capabilities
61+
delete args.version
62+
delete args.platform
63+
} else {
64+
args = {...args, ...capabilitiesFromConfig}
65+
}
66+
// Not needed
5967
delete args.base
60-
delete args.version
61-
delete args.platform
68+
6269
const seleniumCapabilities = {
6370
user: username,
6471
key: accessKey,
6572
region: config.region,
6673
headless: config.headless,
6774
logLevel: 'error',
6875
capabilities: {
69-
'sauce:options': capabilitiesFromConfig,
7076
...args
7177
},
7278
...config.options

src/utils.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,8 @@ export async function waitUntil({condition, retries = 0, maxRetries = 50, interv
1111

1212
return waitUntil({condition, retries: retries++, maxRetries, interval})
1313
}
14+
15+
export function isW3C(capabilities){
16+
// Only browserVersion is mandatory, platformName is optional
17+
return Boolean(capabilities.browserVersion)
18+
}

0 commit comments

Comments
 (0)