From 350a03877d0abca7cf9088ec9658709d6ff100af Mon Sep 17 00:00:00 2001 From: kobenguyent Date: Fri, 9 Feb 2024 16:04:13 +0100 Subject: [PATCH 1/3] fix: use this.options instead of this.config --- lib/helper/Playwright.js | 4 ++-- lib/helper/Puppeteer.js | 6 +++--- lib/helper/WebDriver.js | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/helper/Playwright.js b/lib/helper/Playwright.js index 77dcfeb0d..59773e774 100644 --- a/lib/helper/Playwright.js +++ b/lib/helper/Playwright.js @@ -2329,14 +2329,14 @@ class Playwright extends Helper { this.debugSection('Response', await response.text()); // hook to allow JSON response handle this - if (this.config.onResponse) { + if (this.options.onResponse) { const axiosResponse = { data: await response.json(), status: response.status(), statusText: response.statusText(), headers: response.headers(), }; - this.config.onResponse(axiosResponse); + this.options.onResponse(axiosResponse); } return response; diff --git a/lib/helper/Puppeteer.js b/lib/helper/Puppeteer.js index 16f5b4aa9..ca82e163d 100644 --- a/lib/helper/Puppeteer.js +++ b/lib/helper/Puppeteer.js @@ -486,7 +486,7 @@ class Puppeteer extends Helper { if (!page) return; page.setDefaultNavigationTimeout(this.options.getPageTimeout); this.context = await this.page.$('body'); - if (this.config.browser === 'chrome') { + if (this.options.browser === 'chrome') { await page.bringToFront(); } } @@ -658,9 +658,9 @@ class Puppeteer extends Helper { url = this.options.url + url; } - if (this.config.basicAuth && (this.isAuthenticated !== true)) { + if (this.options.basicAuth && (this.isAuthenticated !== true)) { if (url.includes(this.options.url)) { - await this.page.authenticate(this.config.basicAuth); + await this.page.authenticate(this.options.basicAuth); this.isAuthenticated = true; } } diff --git a/lib/helper/WebDriver.js b/lib/helper/WebDriver.js index 48b058b12..62c122bee 100644 --- a/lib/helper/WebDriver.js +++ b/lib/helper/WebDriver.js @@ -977,12 +977,12 @@ class WebDriver extends Helper { */ amOnPage(url) { let split_url; - if (this.config.basicAuth) { + if (this.options.basicAuth) { if (url.startsWith('/')) { - url = this.config.url + url; + url = this.options.url + url; } split_url = url.split('//'); - url = `${split_url[0]}//${this.config.basicAuth.username}:${this.config.basicAuth.password}@${split_url[1]}`; + url = `${split_url[0]}//${this.options.basicAuth.username}:${this.options.basicAuth.password}@${split_url[1]}`; } return this.browser.url(url); } From f476c20ec4bc3329d5508bbb1f28010af754f9ed Mon Sep 17 00:00:00 2001 From: kobenguyent Date: Fri, 9 Feb 2024 16:30:59 +0100 Subject: [PATCH 2/3] fix: other places --- lib/helper/Playwright.js | 4 ++-- lib/helper/REST.js | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/helper/Playwright.js b/lib/helper/Playwright.js index 59773e774..77dcfeb0d 100644 --- a/lib/helper/Playwright.js +++ b/lib/helper/Playwright.js @@ -2329,14 +2329,14 @@ class Playwright extends Helper { this.debugSection('Response', await response.text()); // hook to allow JSON response handle this - if (this.options.onResponse) { + if (this.config.onResponse) { const axiosResponse = { data: await response.json(), status: response.status(), statusText: response.statusText(), headers: response.headers(), }; - this.options.onResponse(axiosResponse); + this.config.onResponse(axiosResponse); } return response; diff --git a/lib/helper/REST.js b/lib/helper/REST.js index 150466155..723cd3115 100644 --- a/lib/helper/REST.js +++ b/lib/helper/REST.js @@ -157,8 +157,8 @@ class REST extends Helper { } } - if (this.config.onRequest) { - await this.config.onRequest(request); + if (this.options.onRequest) { + await this.options.onRequest(request); } this.options.prettyPrintJson ? this.debugSection('Request', beautify(JSON.stringify(_debugRequest))) : this.debugSection('Request', JSON.stringify(_debugRequest)); @@ -171,8 +171,8 @@ class REST extends Helper { this.debugSection('Response', `Response error. Status code: ${err.response.status}`); response = err.response; } - if (this.config.onResponse) { - await this.config.onResponse(response); + if (this.options.onResponse) { + await this.options.onResponse(response); } this.options.prettyPrintJson ? this.debugSection('Response', beautify(JSON.stringify(response.data))) : this.debugSection('Response', JSON.stringify(response.data)); return response; From 31206aaeb9948c1a5a1fe9c40ab2304dd638ca95 Mon Sep 17 00:00:00 2001 From: kobenguyent Date: Fri, 9 Feb 2024 16:49:26 +0100 Subject: [PATCH 3/3] fix: other places --- lib/helper/REST.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/helper/REST.js b/lib/helper/REST.js index 723cd3115..88c214fb6 100644 --- a/lib/helper/REST.js +++ b/lib/helper/REST.js @@ -72,9 +72,12 @@ class REST extends Helper { this.options.maxBodyLength = maxContentLength; } - this.options = { ...this.options, ...config }; + // override defaults with config + this._setConfig(config); + this.headers = { ...this.options.defaultHeaders }; this.axios = axios.create(); + // @ts-ignore this.axios.defaults.headers = this.options.defaultHeaders; } @@ -157,8 +160,8 @@ class REST extends Helper { } } - if (this.options.onRequest) { - await this.options.onRequest(request); + if (this.config.onRequest) { + await this.config.onRequest(request); } this.options.prettyPrintJson ? this.debugSection('Request', beautify(JSON.stringify(_debugRequest))) : this.debugSection('Request', JSON.stringify(_debugRequest)); @@ -171,8 +174,8 @@ class REST extends Helper { this.debugSection('Response', `Response error. Status code: ${err.response.status}`); response = err.response; } - if (this.options.onResponse) { - await this.options.onResponse(response); + if (this.config.onResponse) { + await this.config.onResponse(response); } this.options.prettyPrintJson ? this.debugSection('Response', beautify(JSON.stringify(response.data))) : this.debugSection('Response', JSON.stringify(response.data)); return response;