Skip to content

Commit

Permalink
Adding logs and limiting to
Browse files Browse the repository at this point in the history
  • Loading branch information
Amit3200 committed Oct 19, 2023
1 parent 49c11b8 commit e301f22
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
4 changes: 4 additions & 0 deletions packages/sdk-utils/src/request.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import percy from './percy-info.js';
import logger from './logger.js';

// Helper to send a request to the local CLI API
export async function request(path, options = {}) {
Expand Down Expand Up @@ -53,6 +54,9 @@ if (process.env.__PERCY_BROWSERIFIED__) {
// rollup throws error for -> await import(protocol === 'https:' ? 'https' : 'http')
let { default: http } = protocol === 'https:' ? await import('https') : await import('http');

const log = logger('request');
log.debug(`Request object for url: ${url},\nRequest object: ${JSON.stringify(options)}`);

return new Promise((resolve, reject) => {
http.request(url, options)
.on('response', response => {
Expand Down
16 changes: 8 additions & 8 deletions packages/webdriver-utils/src/driver.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import utils from '@percy/sdk-utils';
import Cache from './util/cache.js';
import { httpsAgent } from './util/utils.js';
import httpsAgent from './util/utils.js';
const { request } = utils;
const log = utils.logger('webdriver-utils:driver');

Expand All @@ -15,7 +15,7 @@ export default class Driver {
return await Cache.withCache(Cache.caps, this.sessionId, async () => {
try {
const options = {
// agent: httpsAgent()
agent: httpsAgent()
};
const baseUrl = `${this.executorUrl}/session/${this.sessionId}`;
const caps = JSON.parse((await request(baseUrl, options)).body);
Expand All @@ -29,9 +29,9 @@ export default class Driver {

async getWindowSize() {
const options = {
// agent: httpsAgent()
agent: httpsAgent()
};
const baseUrl = `${this.executForUrl}/session/${this.sessionId}/window/current/size`;
const baseUrl = `${this.executorUrl}/session/${this.sessionId}/window/current/size`;
const windowSize = JSON.parse((await request(baseUrl, options)).body);
return windowSize;
}
Expand All @@ -55,7 +55,7 @@ export default class Driver {
headers: {
'Content-Type': 'application/json;charset=utf-8'
},
// agent: httpsAgent(),
agent: httpsAgent(),
body: JSON.stringify(command)
};
const baseUrl = `${this.executorUrl}/session/${this.sessionId}/execute/sync`;
Expand All @@ -65,7 +65,7 @@ export default class Driver {

async takeScreenshot() {
const options = {
// agent: httpsAgent()
agent: httpsAgent()
};
const baseUrl = `${this.executorUrl}/session/${this.sessionId}/screenshot`;
const screenShot = JSON.parse((await request(baseUrl, options)).body);
Expand All @@ -74,7 +74,7 @@ export default class Driver {

async rect(elementId) {
const options = {
// agent: httpsAgent()
agent: httpsAgent()
};
const baseUrl = `${this.executorUrl}/session/${this.sessionId}/element/${elementId}/rect`;
const response = JSON.parse((await request(baseUrl, options)).body);
Expand All @@ -87,7 +87,7 @@ export default class Driver {
headers: {
'Content-Type': 'application/json;charset=utf-8'
},
// agent: httpsAgent(),
agent: httpsAgent(),
body: JSON.stringify({ using, value })
};
const baseUrl = `${this.executorUrl}/session/${this.sessionId}/element`;
Expand Down
2 changes: 1 addition & 1 deletion packages/webdriver-utils/src/providers/genericProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ export default class GenericProvider {
async getHeaderFooter(deviceName, osVersion, browserName) {
// passing 0 as key, since across different pages and tests, this config will remain same
const devicesConfig = await Cache.withCache(Cache.devicesConfig, 0, async () => {
return (await request(DEVICES_CONFIG_URL)).body;
return (await request(DEVICES_CONFIG_URL, httpsAgent())).body;
});
let deviceKey = `${deviceName}-${osVersion}`;
return devicesConfig[deviceKey]
Expand Down
2 changes: 1 addition & 1 deletion packages/webdriver-utils/src/util/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import https from 'https';
export function httpsAgent() {
// return {};
return new https.Agent({
minVersion: 'TLSv1.1',
minVersion: 'TLSv1.2',
maxVersion: 'TLSv1.2'
});
}
Expand Down

0 comments on commit e301f22

Please sign in to comment.