@percy/playwright 1.0.5 → 1.0.6-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -58,4 +58,91 @@ $ percy exec -- node script.js
58
58
 
59
59
  - `page` (**required**) - A `playwright` page instance
60
60
  - `name` (**required**) - The snapshot name; must be unique to each snapshot
61
- - `options` - [See per-snapshot configuration options](https://docs.percy.io/docs/cli-configuration#per-snapshot-configuration)
61
+ - `options` - [See per-snapshot configuration options](https://www.browserstack.com/docs/percy/take-percy-snapshots/overview#per-snapshot-configuration)
62
+
63
+
64
+ ## Percy on Automate
65
+
66
+ ## Usage
67
+
68
+ ```javascript
69
+ const { chromium } = require('playwright');
70
+ const percyScreenshot = require('@percy/playwright');
71
+
72
+ const desired_cap = {
73
+ 'browser': 'chrome',
74
+ 'browser_version': 'latest',
75
+ 'os': 'osx',
76
+ 'os_version': 'ventura',
77
+ 'name': 'Percy Playwright PoA Demo',
78
+ 'build': 'percy-playwright-javascript-tutorial',
79
+ 'browserstack.username': 'username',
80
+ 'browserstack.accessKey': 'accesskey'
81
+ };
82
+
83
+ (async () => {
84
+ const cdpUrl = `wss://cdp.browserstack.com/playwright?caps=${encodeURIComponent(JSON.stringify(desired_cap))}`;
85
+ const browser = await chromium.connect(cdpUrl);
86
+ const page = await browser.newPage();
87
+ await page.goto("https://percy.io/");
88
+ await percyScreenshot(page, 'Screenshot 1');
89
+
90
+ // Options for percyScreenshot
91
+ // await percyScreenshot(page, 'Screenshot 1', {
92
+ // fullPage: true,
93
+ // percyCSS: 'body { background: red; }',
94
+ // ignoreRegionSelectors: ['#ignore-this'],
95
+ // customIgnoreRegions: [{ top: 10, right: 10, bottom: 120, left: 10 }],
96
+ // });
97
+
98
+ await browser.close();
99
+ })();
100
+ ```
101
+
102
+ ## Configuration
103
+
104
+ `percyScreenshot(page, name[, options])`
105
+
106
+ - `page` (**required**) - A `playwright` page instance
107
+ - `name` (**required**) - The snapshot name; must be unique to each snapshot
108
+ - `options` (**optional**) - There are various options supported by percyScreenshot to server further functionality.
109
+ - `sync` - Boolean value by default it falls back to `false`, Gives the processed result around screenshot [From CLI v1.28.0-beta.0+]
110
+ - `fullPage` - Boolean value by default it falls back to `false`, Takes full page screenshot [From CLI v1.27.6+]
111
+ - `freezeAnimatedImage` - Boolean value by default it falls back to `false`, you can pass `true` and percy will freeze image based animations.
112
+ - `freezeImageBySelectors` - List of selectors. Images will be freezed which are passed using selectors. For this to work `freezeAnimatedImage` must be set to true.
113
+ - `freezeImageByXpaths` - List of xpaths. Images will be freezed which are passed using xpaths. For this to work `freezeAnimatedImage` must be set to true.
114
+ - `percyCSS` - Custom CSS to be added to DOM before the screenshot being taken. Note: This gets removed once the screenshot is taken.
115
+ - `ignoreRegionXpaths` - List of xpaths. elements in the DOM can be ignored using xpath
116
+ - `ignoreRegionSelectors` - List of selectors. elements in the DOM can be ignored using selectors.
117
+ - `customIgnoreRegions` - List of custom objects. elements can be ignored using custom boundaries. Just passing a simple object for it like below.
118
+ - example: ```{top: 10, right: 10, bottom: 120, left: 10}```
119
+ - In above example it will draw rectangle of ignore region as per given coordinates.
120
+ - `top` (int): Top coordinate of the ignore region.
121
+ - `bottom` (int): Bottom coordinate of the ignore region.
122
+ - `left` (int): Left coordinate of the ignore region.
123
+ - `right` (int): Right coordinate of the ignore region.
124
+ - `considerRegionXpaths` - List of xpaths. elements in the DOM can be considered for diffing and will be ignored by Intelli Ignore using xpaths.
125
+ - `considerRegionSelectors` - List of selectors. elements in the DOM can be considered for diffing and will be ignored by Intelli Ignore using selectors.
126
+ - `customConsiderRegions` - List of custom objects. elements can be considered for diffing and will be ignored by Intelli Ignore using custom boundaries
127
+ - example: ```{top: 10, right: 10, bottom: 120, left: 10}```
128
+ - In above example it will draw rectangle of consider region will be drawn.
129
+ - Parameters:
130
+ - `top` (int): Top coordinate of the consider region.
131
+ - `bottom` (int): Bottom coordinate of the consider region.
132
+ - `left` (int): Left coordinate of the consider region.
133
+ - `right` (int): Right coordinate of the consider region.
134
+
135
+ ### Creating Percy on automate build
136
+ Note: Automate Percy Token starts with `auto` keyword. The command can be triggered using `exec` keyword.
137
+ ```sh-session
138
+ $ export PERCY_TOKEN=[your-project-token]
139
+ $ percy exec -- [playwright test command]
140
+ [percy] Percy has started!
141
+ [percy] [Playwright example] : Starting automate screenshot ...
142
+ [percy] Screenshot taken "Playwright example"
143
+ [percy] Stopping percy...
144
+ [percy] Finalized build #1: https://percy.io/[your-project]
145
+ [percy] Done!
146
+ ```
147
+
148
+ Refer to docs here: [Percy on Automate](https://www.browserstack.com/docs/percy/integrate/functional-and-visual)
package/index.js CHANGED
@@ -1,17 +1,18 @@
1
1
  const utils = require('@percy/sdk-utils');
2
+ const { Utils } = require('./utils');
2
3
 
3
4
  // Collect client and environment information
4
5
  const sdkPkg = require('./package.json');
5
6
  const playwrightPkg = require('playwright/package.json');
6
7
  const CLIENT_INFO = `${sdkPkg.name}/${sdkPkg.version}`;
7
8
  const ENV_INFO = `${playwrightPkg.name}/${playwrightPkg.version}`;
9
+ const log = utils.logger('playwright');
8
10
 
9
11
  // Take a DOM snapshot and post it to the snapshot endpoint
10
12
  async function percySnapshot(page, name, options) {
11
13
  if (!page) throw new Error('A Playwright `page` object is required.');
12
14
  if (!name) throw new Error('The `name` argument is required.');
13
15
  if (!(await utils.isPercyEnabled())) return;
14
- let log = utils.logger('playwright');
15
16
 
16
17
  try {
17
18
  // Inject the DOM serialization script
@@ -40,4 +41,36 @@ async function percySnapshot(page, name, options) {
40
41
  }
41
42
  }
42
43
 
43
- module.exports = percySnapshot;
44
+ // Takes Playwright screenshot with Automate
45
+ async function percyScreenshot(page, name, options) {
46
+ if (!page) throw new Error('A Playwright `page` object is required.');
47
+ if (!name) throw new Error('The `name` argument is required.');
48
+ if (!(await utils.isPercyEnabled())) return;
49
+ if (Utils.projectType() !== 'automate') {
50
+ throw new Error('Invalid function call - percyScreenshot(). Please use percySnapshot() function for taking screenshot. percyScreenshot() should be used only while using Percy with Automate. For more information on usage of PercySnapshot(), refer doc for your language https://docs.percy.io/docs/end-to-end-testing');
51
+ }
52
+
53
+ try {
54
+ const sessionDetails = await Utils.sessionDetails(page);
55
+ const sessionId = sessionDetails.hashed_id;
56
+ const pageGuid = page._guid;
57
+ const frameGuid = page._mainFrame._guid;
58
+ const data = {
59
+ environmentInfo: ENV_INFO,
60
+ clientInfo: CLIENT_INFO,
61
+ sessionId: sessionId,
62
+ pageGuid: pageGuid,
63
+ frameGuid: frameGuid,
64
+ framework: 'playwright',
65
+ snapshotName: name,
66
+ options
67
+ };
68
+ const response = await Utils.captureAutomateScreenshot(data);
69
+ return response?.body?.data;
70
+ } catch (err) {
71
+ log.error(`Could not take percy screenshot "${name}"`);
72
+ log.error(err);
73
+ }
74
+ }
75
+
76
+ module.exports = { percySnapshot, percyScreenshot, CLIENT_INFO, ENV_INFO };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@percy/playwright",
3
3
  "description": "Playwright client library for visual testing with Percy",
4
- "version": "1.0.5",
4
+ "version": "1.0.6-beta.0",
5
5
  "license": "MIT",
6
6
  "author": "Perceptual Inc.",
7
7
  "repository": "https://github.com/percy/percy-playwright",
@@ -26,7 +26,8 @@
26
26
  "test:types": "tsd"
27
27
  },
28
28
  "publishConfig": {
29
- "access": "public"
29
+ "access": "public",
30
+ "tag": "beta"
30
31
  },
31
32
  "peerDependencies": {
32
33
  "playwright-core": ">=1"
@@ -34,6 +35,7 @@
34
35
  "devDependencies": {
35
36
  "@percy/cli": "^1.28.2",
36
37
  "@playwright/test": "^1.24.2",
38
+ "babel-eslint": "^10.1.0",
37
39
  "cross-env": "^7.0.2",
38
40
  "eslint": "^7.18.0",
39
41
  "eslint-config-standard": "^16.0.2",
@@ -43,6 +45,7 @@
43
45
  "eslint-plugin-standard": "^5.0.0",
44
46
  "nyc": "^15.1.0",
45
47
  "playwright": "^1.24.2",
48
+ "sinon": "^18.0.0",
46
49
  "tsd": "^0.25.0"
47
50
  }
48
51
  }
package/types/index.d.ts CHANGED
@@ -6,3 +6,9 @@ export default function percySnapshot(
6
6
  name: string,
7
7
  options?: SnapshotOptions
8
8
  ): Promise<void>;
9
+
10
+ export default function percyScreenshot(
11
+ page: Playwright.Page,
12
+ name: string,
13
+ options?: SnapshotOptions
14
+ ): Promise<void>;