-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🔥 remove obsolete request pkg, replace obsolete wd pkg with webdriver…
…, remove package-lock
- Loading branch information
Showing
6 changed files
with
111 additions
and
1,241 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package-lock=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,46 @@ | ||
/** | ||
* JavaScript tests integration with Sauce | ||
* https://saucelabs.com/docs/javascript-unit-tests-integration | ||
*/ | ||
var webdriver = require('wd'); | ||
var { remote } = require('webdriver'); | ||
var Bluebird = require('bluebird'); | ||
|
||
module.exports = function(desired, auth, url) { | ||
var browser = webdriver.remote("ondemand.saucelabs.com", 80, auth.username, auth.accessKey); | ||
var initAsync = Bluebird.promisify(browser.init, { context: browser }); | ||
module.exports = function(config, url) { | ||
var desiredCapabilities = config.desired(); | ||
var auth = config.auth(); | ||
var username = auth.username; | ||
var accessKey = auth.accessKey; | ||
|
||
var browser = remote({ | ||
hostname: 'ondemand.saucelabs.com', | ||
port: 80, | ||
path: '/wd/hub', | ||
capabilities: desiredCapabilities, | ||
user: username, | ||
key: accessKey | ||
}); | ||
|
||
var initAsync = Bluebird.promisify(browser.init.bind(browser)); | ||
|
||
var pendingHeartBeat; | ||
var heartbeat = function() { | ||
pendingHeartBeat = setTimeout(function() { | ||
browser.title(); | ||
pendingHeartBeat = setTimeout(async function() { | ||
await browser.getTitle(); | ||
heartbeat(); | ||
}, 60000); | ||
}; | ||
|
||
return initAsync(desired).then(function () { | ||
console.log("# Created remote browser."); | ||
|
||
return initAsync().then(function () { | ||
heartbeat(); | ||
|
||
var getAsync = Bluebird.promisify(browser.get, { context: browser }); | ||
var getAsync = Bluebird.promisify(browser.url.bind(browser)); | ||
|
||
return getAsync(url).then(function () { | ||
return browser; | ||
}); | ||
}).disposer(function() { | ||
clearTimeout(pendingHeartBeat); | ||
|
||
var quitAsync = Bluebird.promisify(browser.quit, { context: browser }); | ||
var quitAsync = Bluebird.promisify(browser.deleteSession.bind(browser)); | ||
|
||
return quitAsync().then(function () { | ||
console.log("# Closed remote browser."); | ||
console.log("Closed browser."); | ||
}); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,39 @@ | ||
var Bluebird = require('bluebird'); | ||
var request = require("request"); | ||
|
||
var requestAsync = Bluebird.promisify(request); | ||
var https = require('https'); | ||
|
||
module.exports = function (sessionID, auth, data) { | ||
var url = ["/v1/", auth.username, "/jobs/", sessionID].join(""); | ||
return new Promise((resolve, reject) => { | ||
var options = { | ||
hostname: 'saucelabs.com', | ||
port: 443, | ||
path: `/rest/v1/${auth.username}/jobs/${sessionID}`, | ||
method: 'PUT', | ||
auth: `${auth.username}:${auth.accessKey}`, | ||
headers: { | ||
'Content-Type': 'application/json' | ||
} | ||
}; | ||
|
||
var req = https.request(options, res => { | ||
var body = ''; | ||
|
||
res.on('data', (chunk) => { | ||
body += chunk; | ||
}); | ||
|
||
res.on('end', () => { | ||
if (res.statusCode >= 200 && res.statusCode < 300) { | ||
resolve(JSON.parse(body)); | ||
} else { | ||
reject(new Error(`Request failed with status code ${res.statusCode}: ${body}`)); | ||
} | ||
}); | ||
}); | ||
|
||
req.on('error', err => { | ||
reject(err); | ||
}); | ||
|
||
return requestAsync({ | ||
method: "PUT", | ||
uri: ["https://", auth.username, ":", auth.accessKey, "@saucelabs.com/rest", url].join(""), | ||
json: true, | ||
body: data | ||
}).then(function (response) { | ||
return response.body; | ||
req.write(JSON.stringify(data)); | ||
req.end(); | ||
}); | ||
}; |
Oops, something went wrong.