Skip to content

Commit

Permalink
parse seleniumAddress in capability
Browse files Browse the repository at this point in the history
  • Loading branch information
christian-bromann committed Apr 10, 2021
1 parent 98b9c14 commit ee50670
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 26 deletions.
48 changes: 26 additions & 22 deletions protractor/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,31 +115,35 @@ function replaceCommands (prtrctrCommand) {
}
}

function parseSeleniumAddress (value) {
const u = url.parse(value)
remoteHostname = u.hostname
return [
this.objectProperty(
this.identifier('protocol'),
this.stringLiteral(u.protocol.slice(0, -1))
),
this.objectProperty(
this.identifier('hostname'),
this.stringLiteral(u.hostname)
),
this.objectProperty(
this.identifier('port'),
this.literal(parseInt(u.port || '443'))
),
this.objectProperty(
this.identifier('path'),
this.stringLiteral(u.path)
)
]
}

let remoteHostname = null
function parseConfigProperties (property) {
const name = property.key.name || property.key.value
const value = property.value.value
if (name === 'seleniumAddress') {
const u = url.parse(value)
remoteHostname = u.hostname
return [
this.objectProperty(
this.identifier('protocol'),
this.stringLiteral(u.protocol.slice(0, -1))
),
this.objectProperty(
this.identifier('hostname'),
this.stringLiteral(u.hostname)
),
this.objectProperty(
this.identifier('port'),
this.literal(parseInt(u.port))
),
this.objectProperty(
this.identifier('path'),
this.stringLiteral(u.path)
)
]
return parseSeleniumAddress.call(this, value)
} else if (name === 'capabilities') {
const { rootLevelConfigs, parsedCaps } = parseCapabilities.call(this, property.value.properties)
return [
Expand All @@ -161,9 +165,7 @@ function parseCapabilities (caps) {
for (const cap of caps) {
const name = cap.key.name || cap.key.value
if (name === 'name') {
console.log('DOO WE', remoteHostname);
if (!remoteHostname || (!remoteHostname.includes('browserstack') && !remoteHostname.includes('saucelabs'))) {
console.log('AHH');
continue
}
parsedCaps.push(
Expand All @@ -177,6 +179,8 @@ function parseCapabilities (caps) {
])
)
)
} else if (name === 'seleniumAddress') {
parsedCaps.push(...parseSeleniumAddress.call(this, cap.value.value))
} else {
parsedCaps.push(cap)
}
Expand Down
5 changes: 3 additions & 2 deletions test/__fixtures__/protractor/source/conf.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// Tests for the calculator.
exports.config = {
seleniumAddress: 'https://ondemand.saucelabs.com:4444/wd/hub',
seleniumAddress: 'https://ondemand.saucelabs.com/wd/hub',
capabilities: {
'browserName': 'chrome',
name: 'foobar'
name: 'foobar',
seleniumAddress: 'http://localhost:4444/wd/hub'
},
specs: [
'spec.js'
Expand Down
9 changes: 7 additions & 2 deletions test/__fixtures__/protractor/transformed/conf.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
exports.config = {
protocol: "https",
hostname: "ondemand.saucelabs.com",
port: 4444,
port: 443,
path: "/wd/hub",

capabilities: [{
'browserName': 'chrome',

"sauce:options": {
name: "foobar"
}
},

protocol: "http",
hostname: "localhost",
port: 4444,
path: "/wd/hub"
}],

specs: [
Expand Down

0 comments on commit ee50670

Please sign in to comment.