Skip to content

Commit 19a2efb

Browse files
authored
PMM-3440 Adding Helper
1 parent 4c3a489 commit 19a2efb

File tree

1 file changed

+88
-0
lines changed

1 file changed

+88
-0
lines changed

index.js

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
'use strict';
2+
3+
// use any assertion library you like
4+
let request = require('request');
5+
6+
/**
7+
* Sauce Labs Helper for Codeceptjs
8+
*
9+
* @author Puneet Kala
10+
*/
11+
class SauceHelper extends Helper {
12+
13+
constructor(config) {
14+
super(config);
15+
}
16+
17+
/**
18+
*
19+
* @param sessionId Session ID for current Test browser session
20+
* @param data Test name, etc
21+
* @private
22+
*/
23+
_updateSauceJob(sessionId, data) {
24+
var sauce_url = "Test finished. Link to job: https://saucelabs.com/jobs/";
25+
sauce_url = sauce_url.concat(sessionId);
26+
console.log(sauce_url);
27+
28+
29+
var status_url = 'https://saucelabs.com/rest/v1/';
30+
status_url = status_url.concat(this.config.user);
31+
status_url = status_url.concat('/jobs/');
32+
status_url = status_url.concat(sessionId);
33+
34+
console.log(this.config.user);
35+
request({ url: status_url, method: 'PUT', json: data, auth: {'user': this.config.user, 'pass': this.config.key}}, this._callback);
36+
}
37+
38+
/**
39+
* Request call back function
40+
* @param error
41+
* @param response
42+
* @param body
43+
* @private
44+
*/
45+
_callback(error, response, body) {
46+
if (!error && response.statusCode == 200) {
47+
console.log(body);
48+
}
49+
}
50+
51+
/**
52+
* Helper function gets called if the test is passing
53+
* @param test
54+
* @private
55+
*/
56+
_passed (test) {
57+
console.log ("Test has Passed");
58+
const sessionId = this._getSessionId();
59+
this._updateSauceJob(sessionId, {"passed": true, "name": test.title});
60+
}
61+
62+
/**
63+
* Helper function gets called if the test execution fails
64+
* @param test
65+
* @param error
66+
* @private
67+
*/
68+
_failed (test, error) {
69+
console.log ("Test has failed");
70+
const sessionId = this._getSessionId();
71+
this._updateSauceJob(sessionId, {"passed": false, "name": test.title});
72+
}
73+
74+
_getSessionId() {
75+
if (this.helpers['WebDriver']) {
76+
return this.helpers['WebDriver'].browser.sessionId;
77+
}
78+
if (this.helpers['Appium']) {
79+
return this.helpers['Appium'].browser.sessionId;
80+
}
81+
if (this.helpers['WebDriverIO']) {
82+
return this.helpers['WebDriverIO'].browser.requestHandler.sessionID;
83+
}
84+
throw new Error('No matching helper found. Supported helpers: WebDriver/Appium/WebDriverIO');
85+
}
86+
}
87+
88+
module.exports = SauceHelper;

0 commit comments

Comments
 (0)