From c83741bc187b139172fc3f67b54a9b8fd3784a3e Mon Sep 17 00:00:00 2001 From: Michael Bodnarchuk Date: Wed, 2 Jan 2019 13:33:13 +0200 Subject: [PATCH] Added support for CodeceptJS 2.0 * refactored to support CodeceptJS 2.0 * added session handling for WebDriver and Appium * change the way helpers are accessed --- index.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 885d31f..0e1fa2a 100644 --- a/index.js +++ b/index.js @@ -2,7 +2,6 @@ // use any assertion library you like let request = require('request'); -const container = require('codeceptjs').container; /** * Sauce Labs Helper for Codeceptjs @@ -56,7 +55,7 @@ class SauceHelper extends Helper { */ _passed (test) { console.log ("Test has Passed"); - var sessionId = container.helpers().WebDriverIO.browser.requestHandler.sessionID; + const sessionId = this._getSessionId(); this._updateSauceJob(sessionId, {"passed": true, "name": test.title}); } @@ -68,9 +67,22 @@ class SauceHelper extends Helper { */ _failed (test, error) { console.log ("Test has failed"); - var sessionId = container.helpers().WebDriverIO.browser.requestHandler.sessionID; + const sessionId = this._getSessionId(); this._updateSauceJob(sessionId, {"passed": false, "name": test.title}); } + + _getSessionId() { + if (this.helpers['WebDriver']) { + return this.helpers['WebDriver'].browser.sessionId; + } + if (this.helpers['Appium']) { + return this.helpers['Appium'].browser.sessionId; + } + if (this.helpers['WebDriverIO']) { + return this.helpers['WebDriverIO'].browser.requestHandler.sessionID; + } + throw new Error('No matching helper found. Supported helpers: WebDriver/Appium/WebDriverIO'); + } } module.exports = SauceHelper;