@applitools/eyes-cypress 3.24.0-beta.2 → 3.24.0-beta.5

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
@@ -2,9 +2,9 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
-
6
- ## 3.24.0-beta.2 - 2022/3/2
7
-
5
+
6
+ ## 3.24.0-beta.2 - 2022/3/2
7
+
8
8
  - add bin folder
9
9
 
10
10
  ## 3.24.0-beta.1 - 2022/3/2
package/README.md CHANGED
@@ -522,11 +522,15 @@ cy.eyesClose();
522
522
  #### GetAllTestResults
523
523
 
524
524
  Returns an object with the applitools test results from a given test / test file.
525
- This should be called after `close`
525
+ This should be called after `close`. For example:
526
526
 
527
527
  ```js
528
- cy.eyesGetAllTestResults()
529
- ```
528
+ after(() => {
529
+ cy.eyesGetAllTestResults().then(results => {
530
+ console.log(results)
531
+ })
532
+ })
533
+ ```
530
534
 
531
535
  ## Concurrency
532
536
 
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getCookies = exports.getUrl = exports.getTitle = exports.findElements = exports.findElement = exports.transformSelector = exports.setViewportSize = exports.getViewportSize = exports.childContext = exports.parentContext = exports.mainContext = exports.executeScript = void 0;
4
4
  function executeScript(context, script, arg) {
5
- // context = getCurrenctContext(context)
5
+ context = refreshContext(context);
6
6
  let scriptToExecute;
7
7
  if (script.includes('dom-snapshot') ||
8
8
  script.includes('dom-capture') ||
@@ -55,10 +55,11 @@ function transformSelector(selector) {
55
55
  }
56
56
  exports.transformSelector = transformSelector;
57
57
  function findElement(context, selector, parent) {
58
- // context = getCurrenctContext(context)
58
+ context = refreshContext(context);
59
+ const eyesSelector = selector;
59
60
  const root = parent !== null && parent !== void 0 ? parent : context;
60
- const sel = typeof selector === 'string' ? selector : selector.selector;
61
- if (typeof selector !== 'string' && selector.type === 'xpath') {
61
+ const sel = typeof selector === 'string' ? selector : eyesSelector.selector;
62
+ if (typeof selector !== 'string' && eyesSelector.type === 'xpath') {
62
63
  return context.evaluate(sel, context, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
63
64
  }
64
65
  else {
@@ -67,10 +68,11 @@ function findElement(context, selector, parent) {
67
68
  }
68
69
  exports.findElement = findElement;
69
70
  function findElements(context, selector, parent) {
70
- // context = getCurrenctContext(context)
71
+ context = refreshContext(context);
72
+ const eyesSelector = selector;
71
73
  const root = parent !== null && parent !== void 0 ? parent : context;
72
- const sel = typeof selector === 'string' ? selector : selector.selector;
73
- if (typeof selector !== 'string' && selector.type === 'xpath') {
74
+ const sel = typeof selector === 'string' ? selector : eyesSelector.selector;
75
+ if (typeof selector !== 'string' && eyesSelector.type === 'xpath') {
74
76
  // TODO return multiple
75
77
  return context.evaluate(sel, context, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
76
78
  }
@@ -80,12 +82,12 @@ function findElements(context, selector, parent) {
80
82
  }
81
83
  exports.findElements = findElements;
82
84
  function getTitle(context) {
83
- // context = getCurrenctContext(context)
85
+ context = refreshContext(context);
84
86
  return context.title;
85
87
  }
86
88
  exports.getTitle = getTitle;
87
89
  function getUrl(context) {
88
- // context = getCurrenctContext(context)
90
+ context = refreshContext(context);
89
91
  return context.location.href;
90
92
  }
91
93
  exports.getUrl = getUrl;
@@ -95,7 +97,7 @@ function getCookies() {
95
97
  }
96
98
  exports.getCookies = getCookies;
97
99
  // we need to method to reset the context in case the user called open before visit
98
- function getCurrenctContext(context) {
100
+ function refreshContext(context) {
99
101
  //@ts-ignore
100
102
  return (context && context.defaultView) ? context : cy.state('window').document;
101
103
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applitools/eyes-cypress",
3
- "version": "3.24.0-beta.2",
3
+ "version": "3.24.0-beta.5",
4
4
  "main": "index.js",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "bin": {
@@ -47,7 +47,7 @@
47
47
  },
48
48
  "dependencies": {
49
49
  "@applitools/dom-snapshot": "4.5.12",
50
- "@applitools/eyes-universal": "1.1.0",
50
+ "@applitools/eyes-universal": "1.1.1-beta.1",
51
51
  "@applitools/functional-commons": "1.6.0",
52
52
  "@applitools/logger": "1.0.11",
53
53
  "@applitools/visual-grid-client": "15.9.0",
@@ -32,15 +32,35 @@ const shouldUseBrowserHooks =
32
32
  (getGlobalConfigProperty('isInteractive') ||
33
33
  !getGlobalConfigProperty('eyesIsGlobalHooksSupported'));
34
34
 
35
- Cypress.Commands.add('eyesGetAllTestResults', async () => {
36
- if (isCurrentTestDisabled) {
37
- isCurrentTestDisabled = false;
38
- return;
39
- }
40
- await Promise.all(closePromiseArr);
41
- return socket.request('EyesManager.closeAllEyes', {manager, throwErr});
35
+ Cypress.Commands.add('eyesGetAllTestResults', () => {
36
+ return cy.then({timeout: 86400000}, async () => {
37
+ if (isCurrentTestDisabled) {
38
+ isCurrentTestDisabled = false;
39
+ return;
40
+ }
41
+ await Promise.all(closePromiseArr);
42
+ const summary = await socket.request('EyesManager.closeManager', {manager, throwErr});
43
+ return summary // TODO delete this line
44
+
45
+
46
+ // // TODO wrap with TestResultSummary class
47
+ // const deleteTest = ({testId, batchId, secretToken}) => {
48
+ // const {serverUrl, proxy, apiKey} = Cypress.config('appliConfFile')
49
+ // return socket.request('Core.deleteTest', {testId, batchId, secretToken, serverUrl, proxy, apiKey})
50
+ // }
51
+
52
+ // return new TestResultsSummary({summary, deleteTest})
53
+ });
42
54
  });
43
55
 
56
+
57
+ // class TestResultSummary {
58
+ // constructor({summary, deleteTest}) {
59
+ // // same as in eyes-api
60
+ // }
61
+ // }
62
+
63
+
44
64
  if (shouldUseBrowserHooks) {
45
65
  after(() => {
46
66
  if (!manager) return;
@@ -57,7 +77,8 @@ if (shouldUseBrowserHooks) {
57
77
  tapFileName: Cypress.config('appliConfFile').tapFileName,
58
78
  };
59
79
  await Promise.all(closePromiseArr);
60
- const testResults = await socket.request('EyesManager.closeAllEyes', {manager, throwErr});
80
+ const summary = await socket.request('EyesManager.closeManager', {manager, throwErr});
81
+ const testResults = summary.results.map(({testResults}) => testResults)
61
82
  const message = await socket.request('Test.printTestResults', {testResults, resultConfig});
62
83
  if (
63
84
  !!getGlobalConfigProperty('eyesFailCypressOnDiff') &&
@@ -22,11 +22,11 @@ function toCheckWindowConfiguration(config = {}) {
22
22
  name: config.tag,
23
23
  scriptHooks: config.hooks,
24
24
  ignoreRegions: config.ignore,
25
- floatingRegions: config.floating,
25
+ floatingRegions: convertFloatingRegion(config.floating),
26
26
  strictRegions: config.strict,
27
27
  layoutRegions: config.layout,
28
28
  contentRegions: config.content,
29
- accessibilityRegions: config.accessibility,
29
+ accessibilityRegions: convertAccessabilityRegions(config.accessibility),
30
30
  };
31
31
 
32
32
  if (config.target === 'region') {
@@ -68,4 +68,36 @@ function toCheckWindowConfiguration(config = {}) {
68
68
  return Object.assign({}, checkSettings, regionSettings, config);
69
69
  }
70
70
 
71
+ function convertAccessabilityRegions(accessibilityRegions) {
72
+ if (!accessibilityRegions) return accessibilityRegions;
73
+
74
+ return accessibilityRegions.map(region => ({
75
+ region: region.selector,
76
+ type: region.accessibilityType,
77
+ }))
78
+ }
79
+
80
+ function convertFloatingRegion(floatingRegions){
81
+ if(!floatingRegions) return floatingRegions
82
+
83
+ return floatingRegions.map(region => {
84
+ const floatingRegion = {
85
+ maxDownOffset: region.maxDownOffset || 0,
86
+ maxLeftOffset: region.maxLeftOffset || 0,
87
+ maxUpOffset: region.maxUpOffset || 0,
88
+ maxRightOffset: region.maxRightOffset || 0
89
+ }
90
+ if(region.hasOwnProperty('selector')){
91
+ floatingRegion.region = region.selector
92
+ } else {
93
+ floatingRegion.region = {
94
+ top: region.top,
95
+ left: region.left,
96
+ width: region.width,
97
+ height: region.height,
98
+ }
99
+ }
100
+ })
101
+ }
102
+
71
103
  module.exports = {eyesCheckMapValues};
@@ -1,5 +1,15 @@
1
1
  function eyesOpenMapValues({args, appliConfFile, testName, shouldUseBrowserHooks}) {
2
2
  let browsersInfo = args.browser || appliConfFile.browser;
3
+ let accessibilitySettings = args.accessibilityValidation || appliConfFile.accessibilityValidation;
4
+ const mappedValues = [
5
+ 'accessibilityValidation',
6
+ 'browser',
7
+ 'useDom',
8
+ 'matchLevel',
9
+ 'enablePatterns',
10
+ 'ignoreDisplacements',
11
+ 'ignoreCaret',
12
+ ];
3
13
 
4
14
  if (browsersInfo) {
5
15
  if (Array.isArray(browsersInfo)) {
@@ -10,14 +20,30 @@ function eyesOpenMapValues({args, appliConfFile, testName, shouldUseBrowserHooks
10
20
  }
11
21
  }
12
22
 
23
+ const defaultMatchSettings = {
24
+ accessibilitySettings,
25
+ matchLevel: args.matchLevel || appliConfFile.matchLevel,
26
+ ignoreCaret: args.ignoreCaret || appliConfFile.ignoreCaret,
27
+ useDom: args.useDom || appliConfFile.useDom,
28
+ enablePatterns: args.enablePatterns || appliConfFile.enablePatterns,
29
+ ignoreDisplacements: args.ignoreDisplacements || appliConfFile.ignoreDisplacements,
30
+ };
31
+
32
+ for (const val of mappedValues) {
33
+ if (args.hasOwnProperty(val)) {
34
+ delete args[val];
35
+ }
36
+ if (appliConfFile.hasOwnProperty(val)) {
37
+ delete appliConfFile[val];
38
+ }
39
+ }
40
+
13
41
  const mappedArgs = {
14
42
  ...args,
15
43
  browsersInfo,
44
+ defaultMatchSettings,
16
45
  };
17
46
 
18
- delete mappedArgs.browser;
19
- delete appliConfFile.browser;
20
-
21
47
  return Object.assign(
22
48
  {testName, dontCloseBatches: !shouldUseBrowserHooks},
23
49
  appliConfFile,
@@ -1,9 +1,10 @@
1
- export type Selector = (string | {selector: string; type?: string}) & {__applitoolsBrand?: never};
1
+ type EyesSelector = {selector: string; type?: string}
2
+ export type Selector = (string | EyesSelector) & {__applitoolsBrand?: never};
2
3
  export type Context = Document & {__applitoolsBrand?: never};
3
4
  export type Element = HTMLElement & {__applitoolsBrand?: never};
4
5
 
5
6
  export function executeScript(context: Context, script: string, arg: any): any {
6
- context = getCurrenctContext(context)
7
+ context = refreshContext(context)
7
8
 
8
9
  let scriptToExecute;
9
10
  if (
@@ -52,17 +53,18 @@ export function setViewportSize(vs: any): void {
52
53
  }
53
54
 
54
55
  export function transformSelector(selector: Selector): Selector {
55
- if (selector.hasOwnProperty('selector') && (!selector.hasOwnProperty('type') || selector.type === 'css')) {
56
- return selector.selector
56
+ if (selector.hasOwnProperty('selector') && (!selector.hasOwnProperty('type') || (selector as EyesSelector).type === 'css')) {
57
+ return (selector as EyesSelector).selector
57
58
  }
58
59
  return selector
59
60
  }
60
61
 
61
62
  export function findElement(context: Context, selector: Selector, parent?: Element) {
62
- // context = getCurrenctContext(context)
63
+ context = refreshContext(context)
64
+ const eyesSelector = (selector as EyesSelector)
63
65
  const root = parent ?? context
64
- const sel = typeof selector === 'string' ? selector : selector.selector
65
- if (typeof selector !== 'string' && selector.type === 'xpath') {
66
+ const sel = typeof selector === 'string' ? selector : eyesSelector.selector
67
+ if (typeof selector !== 'string' && eyesSelector.type === 'xpath') {
66
68
  return context.evaluate(sel, context, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
67
69
  } else {
68
70
  return root.querySelector(sel)
@@ -70,10 +72,11 @@ export function findElement(context: Context, selector: Selector, parent?: Eleme
70
72
  }
71
73
 
72
74
  export function findElements(context: Context, selector: Selector, parent: Element){
73
- context = getCurrenctContext(context)
75
+ context = refreshContext(context)
76
+ const eyesSelector = (selector as EyesSelector)
74
77
  const root = parent ?? context
75
- const sel = typeof selector === 'string' ? selector : selector.selector
76
- if (typeof selector !== 'string' && selector.type === 'xpath') {
78
+ const sel = typeof selector === 'string' ? selector : eyesSelector.selector
79
+ if (typeof selector !== 'string' && eyesSelector.type === 'xpath') {
77
80
  // TODO return multiple
78
81
  return context.evaluate(sel, context, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
79
82
  } else {
@@ -82,12 +85,12 @@ export function findElements(context: Context, selector: Selector, parent: Eleme
82
85
  }
83
86
 
84
87
  export function getTitle(context: Context): string {
85
- context = getCurrenctContext(context)
88
+ context = refreshContext(context)
86
89
  return context.title
87
90
  }
88
91
 
89
92
  export function getUrl(context: Context): string {
90
- context = getCurrenctContext(context)
93
+ context = refreshContext(context)
91
94
  return context.location.href
92
95
  }
93
96
 
@@ -97,7 +100,7 @@ export function getCookies(): Array<any> {
97
100
  }
98
101
 
99
102
  // we need to method to reset the context in case the user called open before visit
100
- function getCurrenctContext(context: Context){
103
+ function refreshContext(context: Context) {
101
104
  //@ts-ignore
102
105
  return (context && context.defaultView) ? context : cy.state('window').document
103
106
  }
@@ -3,7 +3,7 @@ const flatten = require('lodash.flatten');
3
3
  const {TestResults} = require('@applitools/visual-grid-client');
4
4
  const handleTestResults = require('./handleTestResults');
5
5
 
6
- function makeGlobalRunHooks({closeAllEyes, closeBatches, closeUniversalServer}) {
6
+ function makeGlobalRunHooks({closeManager, closeBatches, closeUniversalServer}) {
7
7
  return {
8
8
  'before:run': ({config}) => {
9
9
  if (!config.isTextTerminal) return;
@@ -17,7 +17,8 @@ function makeGlobalRunHooks({closeAllEyes, closeBatches, closeUniversalServer})
17
17
  eyesFailCypressOnDiff: config.eyesFailCypressOnDiff,
18
18
  isTextTerminal: config.isTextTerminal,
19
19
  };
20
- const testResults = await closeAllEyes();
20
+ const summary = await closeManager();
21
+ const testResults = summary.results.map(({testResults}) => testResults);
21
22
  const testResultsArr = [];
22
23
  for (const result of flatten(testResults)) {
23
24
  testResultsArr.push(new TestResults(result));