Skip to content

Commit

Permalink
synchronized with docs
Browse files Browse the repository at this point in the history
  • Loading branch information
kobenguyent committed May 2, 2024
1 parent 3e748ca commit d2ba952
Show file tree
Hide file tree
Showing 11 changed files with 396 additions and 102 deletions.
24 changes: 19 additions & 5 deletions docs/build/Playwright.js
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,14 @@ class Playwright extends Helper {
}

if (this.options.video) {
this.options.recordVideo = { size: parseWindowSize(this.options.windowSize) };
// set the video resolution with window size
let size = parseWindowSize(this.options.windowSize);

// if the video resolution is passed, set the record resoultion with that resolution
if (this.options.recordVideo && this.options.recordVideo.size) {
size = parseWindowSize(this.options.recordVideo.size);
}
this.options.recordVideo = { size };
}
if (this.options.recordVideo && !this.options.recordVideo.dir) {
this.options.recordVideo.dir = `${global.output_dir}/videos/`;
Expand Down Expand Up @@ -4035,12 +4042,15 @@ class Playwright extends Helper {
}

/**
* Resets all recorded network requests.
* Starts recording the network traffics.
* This also resets recorded network requests.
*
* ```js
* I.flushNetworkTraffics();
* I.startRecordingTraffic();
* ```
*
* @returns {void} automatically synchronized promise through #recorder
*
*
*/
startRecordingTraffic() {
Expand Down Expand Up @@ -4174,15 +4184,14 @@ class Playwright extends Helper {
/**
* Returns full URL of request matching parameter "urlMatch".
*
* @param {string|RegExp} urlMatch Expected URL of request in network traffic. Can be a string or a regular expression.
*
* Examples:
*
* ```js
* I.grabTrafficUrl('https://api.example.com/session');
* I.grabTrafficUrl(/session.*start/);
* ```
*
* @param {string|RegExp} urlMatch Expected URL of request in network traffic. Can be a string or a regular expression.
* @return {Promise<*>}
*/
grabTrafficUrl(urlMatch) {
Expand Down Expand Up @@ -4796,6 +4805,11 @@ async function targetCreatedHandler(page) {

function parseWindowSize(windowSize) {
if (!windowSize) return { width: 800, height: 600 };

if (windowSize.width && windowSize.height) {
return { width: parseInt(windowSize.width, 10), height: parseInt(windowSize.height, 10) };
}

const dimensions = windowSize.split('x');
if (dimensions.length < 2 || windowSize === 'maximize') {
console.log('Invalid window size, setting window to default values');
Expand Down
29 changes: 28 additions & 1 deletion docs/build/REST.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const axios = require('axios').default;
const Helper = require('@codeceptjs/helper');
const { Agent } = require('https');
const Secret = require('../secret');

const { beautify } = require('../utils');
Expand All @@ -13,6 +14,7 @@ const { beautify } = require('../utils');
* @prop {boolean} [prettyPrintJson=false] - pretty print json for response/request on console logs
* @prop {number} [timeout=1000] - timeout for requests in milliseconds. 10000ms by default
* @prop {object} [defaultHeaders] - a list of default headers
* @prop {object} [httpAgent] - create an agent with SSL certificate
* @prop {function} [onRequest] - a async function which can update request object.
* @prop {function} [onResponse] - a async function which can update response object.
* @prop {number} [maxUploadFileSize] - set the max content file size in MB when performing api calls.
Expand Down Expand Up @@ -40,6 +42,24 @@ const config = {};
* }
*}
* ```
* With httpAgent
*
* ```js
* {
* helpers: {
* REST: {
* endpoint: 'http://site.com/api',
* prettyPrintJson: true,
* httpAgent: {
* key: fs.readFileSync(__dirname + '/path/to/keyfile.key'),
* cert: fs.readFileSync(__dirname + '/path/to/certfile.cert'),
* rejectUnauthorized: false,
* keepAlive: true
* }
* }
* }
* }
* ```
*
* ## Access From Helpers
*
Expand Down Expand Up @@ -76,7 +96,14 @@ class REST extends Helper {
this._setConfig(config);

this.headers = { ...this.options.defaultHeaders };
this.axios = axios.create();

// Create an agent with SSL certificate
if (this.options.httpAgent) {
if (!this.options.httpAgent.key || !this.options.httpAgent.cert) throw Error('Please recheck your httpAgent config!');
this.httpsAgent = new Agent(this.options.httpAgent);
}

this.axios = this.httpsAgent ? axios.create({ httpsAgent: this.httpsAgent }) : axios.create();
// @ts-ignore
this.axios.defaults.headers = this.options.defaultHeaders;
}
Expand Down
15 changes: 11 additions & 4 deletions docs/build/WebDriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -2466,14 +2466,21 @@ class WebDriver extends Helper {
*
*/
async saveScreenshot(fileName, fullPage = false) {
const outputFile = screenshotOutputFolder(fileName);
let outputFile = screenshotOutputFolder(fileName);

if (this.activeSessionName) {
const browser = this.sessionWindows[this.activeSessionName];

if (browser) {
this.debug(`Screenshot of ${this.activeSessionName} session has been saved to ${outputFile}`);
return browser.saveScreenshot(outputFile);
for (const sessionName in this.sessionWindows) {
const activeSessionPage = this.sessionWindows[sessionName];
outputFile = screenshotOutputFolder(`${sessionName}_${fileName}`);

this.debug(`${sessionName} - Screenshot is saving to ${outputFile}`);

if (browser) {
this.debug(`Screenshot of ${sessionName} session has been saved to ${outputFile}`);
return browser.saveScreenshot(outputFile);
}
}
}

Expand Down
96 changes: 96 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,102 @@ layout: Section

# Releases

## 3.6.2

❤️ Thanks all to those who contributed to make this release! ❤️

🛩️ *Features*
* feat(REST): support httpAgent conf ([#4328](https://github.com/codeceptjs/CodeceptJS/issues/4328)) - by **[KobeNguyent](https://github.com/KobeNguyent)**

Support the httpAgent conf to create the TSL connection via REST helper

```
{
helpers: {
REST: {
endpoint: 'http://site.com/api',
prettyPrintJson: true,
httpAgent: {
key: fs.readFileSync(__dirname + '/path/to/keyfile.key'),
cert: fs.readFileSync(__dirname + '/path/to/certfile.cert'),
rejectUnauthorized: false,
keepAlive: true
}
}
}
}
```

* feat(wd): screenshots for sessions ([#4322](https://github.com/codeceptjs/CodeceptJS/issues/4322)) - by **[KobeNguyent](https://github.com/KobeNguyent)**

Currently only screenshot of the active session is saved, this PR aims to save the screenshot of every session for easy debugging

```
Scenario('should save screenshot for sessions **[WebDriverIO](https://github.com/WebDriverIO)** **[Puppeteer](https://github.com/Puppeteer)** **[Playwright](https://github.com/Playwright)**', async ({ I }) => {
await I.amOnPage('/form/bug1467');
await I.saveScreenshot('original.png');
await I.amOnPage('/');
await I.saveScreenshot('main_session.png');
session('john', async () => {
await I.amOnPage('/form/bug1467');
event.dispatcher.emit(event.test.failed, this);
});
const fileName = clearString('should save screenshot for active session **[WebDriverIO](https://github.com/WebDriverIO)** **[Puppeteer](https://github.com/Puppeteer)** **[Playwright](https://github.com/Playwright)**');
const [original, failed] = await I.getSHA256Digests([
`${output_dir}/original.png`,
`${output_dir}/john_${fileName}.failed.png`,
]);
// Assert that screenshots of same page in same session are equal
await I.expectEqual(original, failed);
// Assert that screenshots of sessions are created
const [main_original, session_failed] = await I.getSHA256Digests([
`${output_dir}/main_session.png`,
`${output_dir}/john_${fileName}.failed.png`,
]);
await I.expectNotEqual(main_original, session_failed);
});
```
![Screenshot 2024-04-29 at 11 07 47](https://github.com/codeceptjs/CodeceptJS/assets/7845001/5dddf85a-ed77-474b-adfd-2f208d3c16a8)


* feat: locate element with withClassAttr ([#4321](https://github.com/codeceptjs/CodeceptJS/issues/4321)) - by **[KobeNguyent](https://github.com/KobeNguyent)**

Find an element with class attribute

```js
// find div with class contains 'form'
locate('div').withClassAttr('text');
```

* fix(playwright): set the record video resolution ([#4311](https://github.com/codeceptjs/CodeceptJS/issues/4311)) - by **[KobeNguyent](https://github.com/KobeNguyent)**
You could now set the recording video resolution
```
url: siteUrl,
windowSize: '300x500',
show: false,
restart: true,
browser: 'chromium',
trace: true,
video: true,
recordVideo: {
size: {
width: 400,
height: 600,
},
},
```

🐛 *Bug Fixes*
* fix: several issues of stepByStep report ([#4331](https://github.com/codeceptjs/CodeceptJS/issues/4331)) - by **[KobeNguyent](https://github.com/KobeNguyent)**

📖 *Documentation*
* fix: wrong format docs ([#4330](https://github.com/codeceptjs/CodeceptJS/issues/4330)) - by **[KobeNguyent](https://github.com/KobeNguyent)**
* fix(docs): wrong method is mentioned ([#4320](https://github.com/codeceptjs/CodeceptJS/issues/4320)) - by **[KobeNguyent](https://github.com/KobeNguyent)**
* fix: ChatGPT docs - by **[davert](https://github.com/davert)**

## 3.6.1

* Fixed regression in interactive pause.
Expand Down
1 change: 1 addition & 0 deletions docs/community-helpers.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Please **add your own** by editing this page.
* [codeceptjs-slack-reporter](https://www.npmjs.com/package/codeceptjs-slack-reporter) Get a Slack notification when one or more scenarios fail.
* [codeceptjs-browserlogs-plugin](https://github.com/pavkam/codeceptjs-browserlogs-plugin) Record the browser logs for failed tests.
* [codeceptjs-testrail](https://github.com/PeterNgTr/codeceptjs-testrail) - a plugin to integrate with [Testrail](https://www.gurock.com/testrail)
* [codeceptjs-monocart-coverage](https://github.com/cenfun/codeceptjs-monocart-coverage) - a plugin to generate coverage reports, it integrate with [monocart coverage reports](https://github.com/cenfun/monocart-coverage-reports)

## Browser request control
* [codeceptjs-resources-check](https://github.com/luarmr/codeceptjs-resources-check) Load a URL with Puppeteer and listen to the requests while the page is loading. Enabling count the number or check the sizes of the requests.
Expand Down
Loading

0 comments on commit d2ba952

Please sign in to comment.