-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
72709d6
commit 08f0ad8
Showing
2 changed files
with
92 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
'use strict'; | ||
|
||
// use any assertion library you like | ||
let request = require('request'); | ||
const container = require('codeceptjs').container; | ||
|
||
/** | ||
* Sauce Labs Helper for Codeceptjs | ||
* | ||
* @author Puneet Kala | ||
*/ | ||
class SauceHelper extends Helper { | ||
|
||
constructor(config) { | ||
super(config); | ||
} | ||
|
||
/** | ||
* | ||
* @param sessionId Session ID for current Test browser session | ||
* @param data Test name, etc | ||
* @private | ||
*/ | ||
_updateSauceJob(sessionId, data) { | ||
var sauce_url = "Test finished. Link to job: https://saucelabs.com/jobs/"; | ||
sauce_url = sauce_url.concat(sessionId); | ||
console.log(sauce_url); | ||
|
||
|
||
var status_url = 'https://saucelabs.com/rest/v1/'; | ||
status_url = status_url.concat(this.config.user); | ||
status_url = status_url.concat('/jobs/'); | ||
status_url = status_url.concat(sessionId); | ||
|
||
console.log(this.config.user); | ||
request({ url: status_url, method: 'PUT', json: data, auth: {'user': this.config.user, 'pass': this.config.key}}, this._callback); | ||
} | ||
|
||
/** | ||
* Request call back function | ||
* @param error | ||
* @param response | ||
* @param body | ||
* @private | ||
*/ | ||
_callback(error, response, body) { | ||
if (!error && response.statusCode == 200) { | ||
console.log(body); | ||
} | ||
} | ||
|
||
/** | ||
* Helper function gets called if the test is passing | ||
* @param test | ||
* @private | ||
*/ | ||
_passed (test) { | ||
console.log ("Test has Passed"); | ||
var sessionId = container.helpers().WebDriverIO.browser.requestHandler.sessionID; | ||
this._updateSauceJob(sessionId, {"passed": true, "name": test.title}); | ||
} | ||
|
||
/** | ||
* Helper function gets called if the test execution fails | ||
* @param test | ||
* @param error | ||
* @private | ||
*/ | ||
_failed (test, error) { | ||
console.log ("Test has failed"); | ||
var sessionId = container.helpers().WebDriverIO.browser.requestHandler.sessionID; | ||
this._updateSauceJob(sessionId, {"passed": false, "name": test.title}); | ||
} | ||
} | ||
|
||
module.exports = SauceHelper; |
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,16 @@ | ||
{ | ||
"name": "codeceptjs-saucehelper", | ||
"version": "1.0.0", | ||
"description": "Sauce Labs Result Publisher for Codecept JS tests", | ||
"repository": { | ||
"type": "git", | ||
"url": "[email protected]:puneet0191/codeceptjs-saucehelper.git" | ||
}, | ||
"keywords": [ | ||
"codeceptJS", | ||
"codeceptjs", | ||
"saucelabs" | ||
], | ||
"author": "Puneet Kala <[email protected]>", | ||
"license": "MIT" | ||
} |