@wdio/visual-service 3.0.1 → 3.1.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/CHANGELOG.md CHANGED
@@ -1,5 +1,27 @@
1
1
  # @wdio/visual-service
2
2
 
3
+ ## 3.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 43ed502: Add font loading features:
8
+ - add `waitForFontsLoaded` so the module automatically waits for all fonts to be loaded, enabled by default
9
+ - add `enableLayoutTesting` so all text will become transparent so
10
+ - font rendering issues won't cause flakiness
11
+ - image comparison can be done on layout
12
+
13
+ ### Patch Changes
14
+
15
+ - Updated dependencies [43ed502]
16
+ - webdriver-image-comparison@4.1.0
17
+
18
+ ## 3.0.2
19
+
20
+ ### Patch Changes
21
+
22
+ - 14b6ae6: Support BS real device names
23
+ Fix hide/remove elements
24
+
3
25
  ## 3.0.1
4
26
 
5
27
  ### Patch Changes
package/dist/service.d.ts CHANGED
@@ -6,6 +6,10 @@ export default class WdioImageComparisonService extends BaseClass {
6
6
  private _browser?;
7
7
  private _isNativeContext;
8
8
  constructor(options: ClassOptions, _: WebdriverIO.Capabilities, config: WebdriverIO.Config);
9
+ /**
10
+ * Set up the service if users want to use it in standalone mode
11
+ */
12
+ remoteSetup(browser: WebdriverIO.Browser | WebdriverIO.MultiRemoteBrowser): Promise<void>;
9
13
  before(capabilities: WebdriverIO.Capabilities, _specs: string[], browser: WebdriverIO.Browser | WebdriverIO.MultiRemoteBrowser): Promise<void>;
10
14
  beforeTest(test: Frameworks.Test): void;
11
15
  afterCommand(commandName: string, _args: string[], result: number | string, error: any): void;
@@ -1 +1 @@
1
- {"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAgB,UAAU,EAAE,MAAM,aAAa,CAAA;AAC3D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAA;AAC9D,OAAO,EACH,SAAS,EAUZ,M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AO,GAAG,WAAW,CAAC,kBAAkB;IA4BjE,UAAU,CAAC,IAAI,EAAE,UAAU,CAAC,IAAI;IAKhC,YAAY,CAAE,WAAW,EAAC,MAAM,EAAE,KAAK,EAAC,MAAM,EAAE,EAAE,MAAM,EAAC,MAAM,GAAC,MAAM,EAAE,KAAK,EAAC,GAAG;CA+HpF"}
package/dist/service.js CHANGED
@@ -25,6 +25,12 @@ export default class WdioImageComparisonService extends BaseClass {
25
25
  this.#config = config;
26
26
  this._isNativeContext = undefined;
27
27
  }
28
+ /**
29
+ * Set up the service if users want to use it in standalone mode
30
+ */
31
+ async remoteSetup(browser) {
32
+ await this.before(browser.capabilities, [], browser);
33
+ }
28
34
  async before(capabilities, _specs, browser) {
29
35
  this._browser = browser;
30
36
  this._isNativeContext = determineNativeContext(this._browser);
@@ -36,14 +42,20 @@ export default class WdioImageComparisonService extends BaseClass {
36
42
  await this.#extendMultiremoteBrowser(capabilities);
37
43
  }
38
44
  /**
39
- * add custom matcher for visual comparison
45
+ * add custom matcher for visual comparison when expect has been added.
46
+ * this is not the case in standalone mode
40
47
  */
41
- expect.extend({
42
- toMatchScreenSnapshot,
43
- toMatchFullPageSnapshot,
44
- toMatchElementSnapshot,
45
- toMatchTabbablePageSnapshot,
46
- });
48
+ try {
49
+ expect.extend({
50
+ toMatchScreenSnapshot,
51
+ toMatchFullPageSnapshot,
52
+ toMatchElementSnapshot,
53
+ toMatchTabbablePageSnapshot,
54
+ });
55
+ }
56
+ catch (err) {
57
+ log.warn('Expect package not found. This means that the custom matchers `toMatchScreenSnapshot|toMatchFullPageSnapshot|toMatchElementSnapshot|toMatchTabbablePageSnapshot` are not added and can not be used. Please make sure to add it to your `package.json` if you want to use the Visual custom matchers.');
58
+ }
47
59
  }
48
60
  beforeTest(test) {
49
61
  this.#currentFile = test.file;
@@ -57,15 +69,17 @@ export default class WdioImageComparisonService extends BaseClass {
57
69
  }
58
70
  #getBaselineFolder() {
59
71
  const isDefaultBaselineFolder = normalize(FOLDERS.DEFAULT.BASE) === this.folders.baselineFolder;
60
- const baselineFolder = (isDefaultBaselineFolder ? this.#currentFilePath : this.folders.baselineFolder);
72
+ const baselineFolder = (isDefaultBaselineFolder && this.#currentFilePath ? this.#currentFilePath : this.folders.baselineFolder);
61
73
  /**
62
74
  * support `resolveSnapshotPath` WebdriverIO option
63
75
  * @ref https://webdriver.io/docs/configuration#resolvesnapshotpath
64
76
  *
65
77
  * We only use this option if the baselineFolder is the default one, otherwise the
66
78
  * service option for setting the baselineFolder should be used
79
+ *
80
+ * We also check `this.#config` because for standalone usage of the service, the config is not available
67
81
  */
68
- if (typeof this.#config.resolveSnapshotPath === 'function' && this.#currentFile && isDefaultBaselineFolder) {
82
+ if (this.#config && typeof this.#config.resolveSnapshotPath === 'function' && this.#currentFile && isDefaultBaselineFolder) {
69
83
  return this.#config.resolveSnapshotPath(this.#currentFile, '.png');
70
84
  }
71
85
  return baselineFolder;
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACR,OAAO,EACP,YAAY,EACZ,wBAAwB,EACxB,uBAAuB,EACvB,0BAA0B,EAC1B,yBAAyB,EACzB,yBAAyB,EACzB,wBAAwB,EAC3B,MAAM,4BAA4B,CAAA;AAOnC;;;;;GAKG;AACH,KAAK,sBAAsB,GACrB,yBAAyB,GACzB,0BAA0B,GAC1B,wBAAwB,GACxB,wBAAwB,GACxB,yBAAyB,GACzB,uBAAuB,CAAC;AAE9B,wBAAgB,UAAU,CACtB,aAAa,EAAE,sBAAsB,EACrC,OAAO,EAAE,OAAO,EAChB,eAAe,EAAE,MAAM,GACxB,OAAO,CAMT;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,MAAM,EAAE,iBAAiB,SAAI,GAAG;IAC1E,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;CACjB,CAKA;AAED;;GAEG;AACH,w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AC,KAAK,EAAE,MAAM,CAAA;CAAC,GAAG,MAAM,CAOhH;AA4GD;;GAEG;AACH,wBAAsB,eAAe,CAAC,cAAc,EAAE,WAAW,CAAC,OAAO,GAAG,OAAO,CAAC,YAAY,CAAC,CA4DhG;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAE,IAAI,EAAE,WAAW,CAAC,OAAO,GAAG,WAAW,CAAC,OAAO,GAAG,WAAW,CAAC,OAAO,CAGtG;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAClC,MAAM,EAAE,WAAW,CAAC,OAAO,GAAG,WAAW,CAAC,kBAAkB,GAC7D,OAAO,CAQT"}
package/dist/utils.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { IOS_OFFSETS } from 'webdriver-image-comparison';
2
+ import { NOT_KNOWN } from 'webdriver-image-comparison/dist/helpers/constants.js';
2
3
  export function getFolders(methodOptions, folders, currentTestPath) {
3
4
  return {
4
5
  actualFolder: methodOptions.actualFolder ?? folders.actualFolder,
@@ -86,6 +87,28 @@ async function getMobileInstanceData({ currentBrowser, isAndroid, isMobile }) {
86
87
  deviceScreenSize,
87
88
  };
88
89
  }
90
+ /**
91
+ * Get the device name
92
+ */
93
+ function getDeviceName(currentBrowser) {
94
+ const { capabilities: {
95
+ // We use a few `@ts-ignore` here because this is returned by the driver
96
+ // and not recognized by the types because they are not requested
97
+ // @ts-ignore
98
+ deviceName: returnedDeviceName = NOT_KNOWN, }, requestedCapabilities } = currentBrowser;
99
+ let deviceName = NOT_KNOWN;
100
+ // First check if it's a BrowserStack session, they don't:
101
+ // - return the "requested" deviceName in the session capabilities
102
+ // - don't use the `appium:deviceName` capability
103
+ const isBrowserStack = 'bstack:options' in requestedCapabilities;
104
+ const bsOptions = requestedCapabilities['bstack:options'];
105
+ const capName = 'deviceName';
106
+ if (isBrowserStack && bsOptions && capName in bsOptions) {
107
+ deviceName = bsOptions[capName];
108
+ }
109
+ const { 'appium:deviceName': requestedDeviceName } = requestedCapabilities;
110
+ return (deviceName !== NOT_KNOWN ? deviceName : requestedDeviceName || returnedDeviceName || NOT_KNOWN).toLowerCase();
111
+ }
89
112
  /**
90
113
  * Get the instance data
91
114
  */
@@ -112,14 +135,11 @@ export async function getInstanceData(currentBrowser) {
112
135
  // @ts-ignore
113
136
  app: rawApp = NOT_KNOWN,
114
137
  // @ts-ignore
115
- deviceName: rawDeviceName = NOT_KNOWN,
116
- // @ts-ignore
117
138
  platformVersion: rawPlatformVersion = NOT_KNOWN, } = currentCapabilities;
118
- const { 'appium:deviceName': requestedDeviceName } = requestedCapabilities;
119
139
  const appName = rawApp !== NOT_KNOWN
120
140
  ? rawApp.replace(/\\/g, '/').split('/').pop().replace(/[^a-zA-Z0-9]/g, '_')
121
141
  : NOT_KNOWN;
122
- const deviceName = (requestedDeviceName || rawDeviceName || '').toLowerCase();
142
+ const deviceName = getDeviceName(currentBrowser);
123
143
  const nativeWebScreenshot = !!(requestedCapabilities['appium:nativeWebScreenshot']);
124
144
  const platformVersion = (rawPlatformVersion === undefined || rawPlatformVersion === '') ? NOT_KNOWN : rawPlatformVersion.toLowerCase();
125
145
  const { devicePixelRatio: mobileDevicePixelRatio, devicePlatformRect, deviceScreenSize, } = await getMobileInstanceData({ currentBrowser, isAndroid, isMobile });
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@wdio/visual-service",
3
3
  "author": "Wim Selles - wswebcreation",
4
4
  "description": "Image comparison / visual regression testing for WebdriverIO",
5
- "version": "3.0.1",
5
+ "version": "3.1.0",
6
6
  "license": "MIT",
7
7
  "homepage": "https://webdriver.io/docs/visual-testing",
8
8
  "repository": {
@@ -22,7 +22,7 @@
22
22
  "dependencies": {
23
23
  "@wdio/logger": "^8.24.12",
24
24
  "@wdio/types": "^8.26.2",
25
- "webdriver-image-comparison": "^4.0.2"
25
+ "webdriver-image-comparison": "^4.1.0"
26
26
  },
27
27
  "scripts": {
28
28
  "build": "run-s clean build:*",