@applitools/eyes-cypress 3.27.0 → 3.27.2
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 +17 -0
- package/README.md +2 -2
- package/bin/eyes-setup.js +19 -27
- package/dist/browser/spec-driver.js +2 -2
- package/index.d.ts +4 -6
- package/package.json +16 -16
- package/src/browser/commands.js +5 -7
- package/src/browser/eyesCheckMapping.js +25 -8
- package/src/browser/refer.js +18 -5
- package/src/browser/socketCommands.js +21 -6
- package/src/browser/spec-driver.ts +2 -2
- package/src/plugin/server.js +1 -0
- package/src/setup/getCypressPaths.js +78 -0
- package/src/setup/getCypressVersion.js +13 -0
- package/src/setup/handleCommands.js +7 -41
- package/src/setup/handlePlugin.js +4 -16
- package/src/setup/handleTypeScript.js +4 -22
- package/src/setup/getCypressConfig.js +0 -16
package/CHANGELOG.md
CHANGED
|
@@ -9,6 +9,23 @@
|
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
|
|
12
|
+
|
|
13
|
+
## 3.27.2 - 2022/10/9
|
|
14
|
+
|
|
15
|
+
### Features
|
|
16
|
+
- Don't fail `eyes.open` when there is a failure to set viewport size in `UFG`.
|
|
17
|
+
- Using `lazyLoad.waitingTime` as a delay between stitches by default
|
|
18
|
+
- Deprecated "Content" match level value in favor of "IgnoreColors"
|
|
19
|
+
### Bug fixes
|
|
20
|
+
- Internal Infrastructure update
|
|
21
|
+
- Fixed bug when error was thrown when coded region wasn't found using selector
|
|
22
|
+
|
|
23
|
+
## 3.27.1 - 2022/8/1
|
|
24
|
+
|
|
25
|
+
### Features
|
|
26
|
+
### Bug fixes
|
|
27
|
+
- Fix `Maximum call stack size exceeded` error in `eyesCheck`
|
|
28
|
+
|
|
12
29
|
## 3.27.0 - 2022/7/25
|
|
13
30
|
|
|
14
31
|
### Features
|
package/README.md
CHANGED
|
@@ -662,7 +662,7 @@ cy.get('.region.two:nth-child(2)').then(el => {
|
|
|
662
662
|
cy.eyesCheckWindow({
|
|
663
663
|
fully: false,
|
|
664
664
|
ignore: [
|
|
665
|
-
{type: 'css', selector: '.region.three:nth-child(3n)'},
|
|
665
|
+
{region: {type: 'css', selector: '.region.three:nth-child(3n)'}, regionId: 'region3'},
|
|
666
666
|
{type: 'xpath', selector: '//div[@class="region one"][3]'},
|
|
667
667
|
{element: el, regionId: 'my-region-id'},
|
|
668
668
|
],
|
|
@@ -716,7 +716,7 @@ after(() => {
|
|
|
716
716
|
|
|
717
717
|
```js
|
|
718
718
|
after(() => {
|
|
719
|
-
cy.eyesGetAllTestResults().then(summary => {
|
|
719
|
+
cy.eyesGetAllTestResults().then(async summary => {
|
|
720
720
|
for(const result of summary.getAllResults()) {
|
|
721
721
|
await result.getTestResults().delete()
|
|
722
722
|
}
|
package/bin/eyes-setup.js
CHANGED
|
@@ -2,38 +2,30 @@
|
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
4
|
const chalk = require('chalk');
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const {handleTypeScript
|
|
8
|
-
const
|
|
9
|
-
const
|
|
5
|
+
const handlePlugin = require('../src/setup/handlePlugin');
|
|
6
|
+
const handleCommands = require('../src/setup/handleCommands');
|
|
7
|
+
const {handleTypeScript} = require('../src/setup/handleTypeScript');
|
|
8
|
+
const getCypressVersion = require('../src/setup/getCypressVersion');
|
|
9
|
+
const getCypressPaths = require('../src/setup/getCypressPaths');
|
|
10
|
+
|
|
10
11
|
const cwd = process.cwd();
|
|
11
12
|
const semver = require('semver');
|
|
13
|
+
const {version} = require('../package');
|
|
12
14
|
|
|
13
|
-
console.log(chalk.cyan('Setup
|
|
14
|
-
const packageJson = JSON.parse(fs.readFileSync('package.json'));
|
|
15
|
-
let cypressVersion;
|
|
15
|
+
console.log(chalk.cyan('Setup Eyes-Cypress', version));
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
const logStr = `Cypress version that was found ${cypressVersion}`;
|
|
17
|
+
const cypressVersion = getCypressVersion();
|
|
18
|
+
console.log(chalk.cyan(`Cypress version: ${cypressVersion}`));
|
|
19
|
+
|
|
20
|
+
const isCypress10 = semver.satisfies(cypressVersion, '>=10.0.0');
|
|
23
21
|
try {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
handlePlugin(cwd, false);
|
|
32
|
-
handleCommands(cwd);
|
|
33
|
-
handleTypeScript(cwd);
|
|
34
|
-
}
|
|
35
|
-
} catch (e) {
|
|
36
|
-
console.log(chalk.red('Setup error:\n', e));
|
|
22
|
+
const {plugin, support, typescript} = getCypressPaths({cwd, isCypress10});
|
|
23
|
+
handlePlugin(plugin);
|
|
24
|
+
handleCommands(support);
|
|
25
|
+
handleTypeScript(typescript);
|
|
26
|
+
} catch (err) {
|
|
27
|
+
console.log(chalk.red(`Setup error:\n${err.message}`));
|
|
28
|
+
process.exit(1);
|
|
37
29
|
}
|
|
38
30
|
|
|
39
31
|
console.log(chalk.cyan('Setup done!'));
|
|
@@ -42,8 +42,8 @@ function getViewportSize() {
|
|
|
42
42
|
//@ts-ignore
|
|
43
43
|
const currWindow = cy.state('window');
|
|
44
44
|
const viewportSize = {
|
|
45
|
-
width:
|
|
46
|
-
height:
|
|
45
|
+
width: currWindow.innerWidth || currWindow.document.documentElement.clientWidth || currWindow.document.body.clientWidth,
|
|
46
|
+
height: currWindow.innerHeight || currWindow.document.documentElement.clientHeight || currWindow.document.body.clientHeight
|
|
47
47
|
};
|
|
48
48
|
return viewportSize;
|
|
49
49
|
}
|
package/index.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ type LegacyRegion = {left: number; top: number; width: number; height: number}
|
|
|
9
9
|
type Selector = {selector: string; type?: 'css' | 'xpath', nodeType?: 'element' | 'shadow-root'} | 'string'
|
|
10
10
|
type Element = HTMLElement | JQuery<HTMLElement>
|
|
11
11
|
|
|
12
|
-
interface CypressCheckSettings extends
|
|
12
|
+
interface CypressCheckSettings extends api.CheckSettingsPlain<Element, Selector>{
|
|
13
13
|
tag?: CypressCheckSettings['name']
|
|
14
14
|
|
|
15
15
|
target?: 'window' | 'region'
|
|
@@ -22,11 +22,12 @@ interface CypressCheckSettings extends types.CheckSettings<Element, Selector> {
|
|
|
22
22
|
strict?: MaybeArray<CypressCheckSettings['strictRegions'][number] | LegacyRegion>
|
|
23
23
|
floating?: MaybeArray<CypressCheckSettings['floatingRegions'][number] | (({element: Element} | Selector | LegacyRegion) & {maxUpOffset?: number; maxDownOffset?: number; maxLeftOffset?: number; maxRightOffset?: number})>
|
|
24
24
|
accessibility?: MaybeArray<CypressCheckSettings['accessibilityRegions'][number] | (({element: Element} | Selector | LegacyRegion) & {accessibilityType?: types.AccessibilityRegionType})>
|
|
25
|
-
|
|
26
25
|
scriptHooks?: CypressCheckSettings['hooks']
|
|
26
|
+
ignoreCaret?: boolean
|
|
27
|
+
ignoreDisplacements?: boolean
|
|
27
28
|
}
|
|
28
29
|
|
|
29
|
-
interface CypressEyesConfig extends
|
|
30
|
+
interface CypressEyesConfig extends api.ConfigurationPlain<Element, Selector> {
|
|
30
31
|
browser?: MaybeArray<CypressEyesConfig['browsersInfo'][number] | {deviceName: string; screenOrientation?: types.ScreenOrientation; name?: string}>
|
|
31
32
|
|
|
32
33
|
batchId?: CypressEyesConfig['batch']['id']
|
|
@@ -36,10 +37,7 @@ interface CypressEyesConfig extends types.EyesConfig<Element, Selector> {
|
|
|
36
37
|
|
|
37
38
|
envName?: CypressEyesConfig['environmentName']
|
|
38
39
|
|
|
39
|
-
ignoreCaret?: CypressEyesConfig['defaultMatchSettings']['ignoreCaret']
|
|
40
|
-
matchLevel?: CypressEyesConfig['defaultMatchSettings']['matchLevel']
|
|
41
40
|
accessibilitySettings?: CypressEyesConfig['defaultMatchSettings']['accessibilitySettings']
|
|
42
|
-
ignoreDisplacements?: CypressEyesConfig['defaultMatchSettings']['ignoreDisplacements']
|
|
43
41
|
}
|
|
44
42
|
|
|
45
43
|
declare global {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@applitools/eyes-cypress",
|
|
3
|
-
"version": "3.27.
|
|
3
|
+
"version": "3.27.2",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git://github.com/applitools/eyes.sdk.javascript1.git",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"test:ts": "yarn test:ts:compile && yarn test:ts:run",
|
|
36
36
|
"test:ts:compile": "tsc --project test/e2e/ts/cypress",
|
|
37
37
|
"test:ts:run": "cypress run --config-file test/e2e/ts/cypress-ts.json",
|
|
38
|
-
"test:coverage": "yarn generate:tests && cd test/coverage/generic && yarn && unset APPLITOOLS_API_KEY && APPLITOOLS_BATCH_NAME='JS Coverage Tests: eyes-
|
|
38
|
+
"test:coverage": "yarn generate:tests && cd test/coverage/generic && yarn && unset APPLITOOLS_API_KEY && APPLITOOLS_BATCH_NAME='JS Coverage Tests: eyes-cypress' APPLITOOLS_BATCH_ID=$(uuidgen) npx cypress run",
|
|
39
39
|
"test:e2e": "mkdir -p test/fixtures/testAppCopies && mocha --no-timeouts 'test/e2e/**/*.test.js'",
|
|
40
40
|
"cypress": "cypress open --config-file test/fixtures/cypress-play.json",
|
|
41
41
|
"cypress:new": "cd test/play && yarn && npx cypress open",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"render": "run(){ npx cypress run --config integrationFolder=test/fixtures/testApp/cypress/render,pluginsFile=test/fixtures/testApp/cypress/plugins/index-render.js,supportFile=test/fixtures/testApp/cypress/support/index-run.js --env url=$1; }; run",
|
|
46
46
|
"prepublish:setup": "sudo apt-get install xvfb",
|
|
47
47
|
"deps": "bongo deps",
|
|
48
|
-
"preversion": "yarn build && bongo preversion --skip-deps --verifyPendingChanges",
|
|
48
|
+
"preversion": "yarn build && bongo preversion --skip-deps --verifyPendingChanges --skipVerifyInstalledVersions",
|
|
49
49
|
"version": "bongo version --withPendingChanges",
|
|
50
50
|
"postversion": "bongo postversion --skip-release-notification"
|
|
51
51
|
},
|
|
@@ -55,24 +55,25 @@
|
|
|
55
55
|
}
|
|
56
56
|
},
|
|
57
57
|
"dependencies": {
|
|
58
|
-
"@applitools/eyes-api": "1.
|
|
59
|
-
"@applitools/eyes-universal": "2.
|
|
58
|
+
"@applitools/eyes-api": "1.8.5",
|
|
59
|
+
"@applitools/eyes-universal": "2.16.3",
|
|
60
60
|
"@applitools/functional-commons": "1.6.0",
|
|
61
|
-
"@applitools/logger": "1.1.
|
|
62
|
-
"@applitools/visual-grid-client": "15.
|
|
61
|
+
"@applitools/logger": "1.1.26",
|
|
62
|
+
"@applitools/visual-grid-client": "15.14.1",
|
|
63
63
|
"chalk": "3.0.0",
|
|
64
|
+
"semver": "7.3.7",
|
|
64
65
|
"uuid": "8.3.2",
|
|
65
66
|
"ws": "8.5.0"
|
|
66
67
|
},
|
|
67
68
|
"devDependencies": {
|
|
68
|
-
"@applitools/bongo": "^2.
|
|
69
|
-
"@applitools/scripts": "1.
|
|
70
|
-
"@applitools/sdk-coverage-tests": "^2.3.
|
|
69
|
+
"@applitools/bongo": "^2.2.0",
|
|
70
|
+
"@applitools/scripts": "1.2.0",
|
|
71
|
+
"@applitools/sdk-coverage-tests": "^2.3.20",
|
|
71
72
|
"@applitools/snaptdout": "1.0.1",
|
|
72
|
-
"@applitools/test-server": "1.1.
|
|
73
|
-
"@applitools/test-utils": "1.
|
|
74
|
-
"@applitools/types": "^1.5.
|
|
75
|
-
"@applitools/utils": "1.3.
|
|
73
|
+
"@applitools/test-server": "1.1.5",
|
|
74
|
+
"@applitools/test-utils": "1.5.2",
|
|
75
|
+
"@applitools/types": "^1.5.19",
|
|
76
|
+
"@applitools/utils": "1.3.12",
|
|
76
77
|
"@types/node": "12",
|
|
77
78
|
"@types/ws": "^8.2.2",
|
|
78
79
|
"@typescript-eslint/eslint-plugin": "^5.10.2",
|
|
@@ -80,7 +81,7 @@
|
|
|
80
81
|
"chai": "4.2.0",
|
|
81
82
|
"chai-spies": "1.0.0",
|
|
82
83
|
"cookie-parser": "1.4.4",
|
|
83
|
-
"cypress": "
|
|
84
|
+
"cypress": "9.7.0",
|
|
84
85
|
"eslint": "8.10.0",
|
|
85
86
|
"eslint-plugin-mocha-no-only": "1.1.0",
|
|
86
87
|
"eslint-plugin-node": "7.0.1",
|
|
@@ -92,7 +93,6 @@
|
|
|
92
93
|
"ncp": "2.0.0",
|
|
93
94
|
"node-fetch": "2.6.0",
|
|
94
95
|
"prettier": "1.19.1",
|
|
95
|
-
"semver": "^7.3.7",
|
|
96
96
|
"typescript": "4.6.4"
|
|
97
97
|
},
|
|
98
98
|
"engines": {
|
package/src/browser/commands.js
CHANGED
|
@@ -7,11 +7,7 @@ const {socketCommands} = require('./socketCommands');
|
|
|
7
7
|
const {eyesOpenMapValues} = require('./eyesOpenMapping');
|
|
8
8
|
const {eyesCheckMapValues} = require('./eyesCheckMapping');
|
|
9
9
|
const {TestResultsSummary} = require('@applitools/eyes-api');
|
|
10
|
-
const refer = new Refer(
|
|
11
|
-
if (!value || !value.constructor || !value.constructor.name) return false;
|
|
12
|
-
const name = value.constructor.name;
|
|
13
|
-
return name === 'HTMLDocument' || name === 'Window' || value.ownerDocument;
|
|
14
|
-
});
|
|
10
|
+
const refer = new Refer();
|
|
15
11
|
const socket = new Socket();
|
|
16
12
|
const throwErr = Cypress.config('failCypressOnDiff');
|
|
17
13
|
socketCommands(socket, refer);
|
|
@@ -42,7 +38,7 @@ Cypress.Commands.add('eyesGetAllTestResults', () => {
|
|
|
42
38
|
await Promise.all(closePromiseArr);
|
|
43
39
|
const summary = await socket.request('EyesManager.closeManager', {manager, throwErr});
|
|
44
40
|
|
|
45
|
-
const deleteTest = ({testId, batchId, secretToken}) => {
|
|
41
|
+
const deleteTest = ({settings: {testId, batchId, secretToken}}) => {
|
|
46
42
|
const {serverUrl, proxy, apiKey} = Cypress.config('appliConfFile');
|
|
47
43
|
return socket.request('Core.deleteTest', {
|
|
48
44
|
settings: {
|
|
@@ -55,7 +51,9 @@ Cypress.Commands.add('eyesGetAllTestResults', () => {
|
|
|
55
51
|
},
|
|
56
52
|
});
|
|
57
53
|
};
|
|
58
|
-
|
|
54
|
+
summary.results = summary.results.map(res => {
|
|
55
|
+
return {...res, result: res.testResults, error: res.exception};
|
|
56
|
+
});
|
|
59
57
|
return new TestResultsSummary({summary, deleteTest});
|
|
60
58
|
});
|
|
61
59
|
});
|
|
@@ -36,14 +36,29 @@ function eyesCheckMapValues({args, refer}) {
|
|
|
36
36
|
if (config.element) {
|
|
37
37
|
if (isHTMLElement(config.element)) {
|
|
38
38
|
regionSettings = {
|
|
39
|
-
region: refer.ref(config.element),
|
|
39
|
+
region: Object.assign(refer.ref(config.element), {type: 'element'}),
|
|
40
40
|
};
|
|
41
41
|
} else {
|
|
42
42
|
// JQuery element
|
|
43
43
|
regionSettings = {
|
|
44
|
-
region: refer.ref(config.element[0]),
|
|
44
|
+
region: Object.assign(refer.ref(config.element[0]), {type: 'element'}),
|
|
45
45
|
};
|
|
46
46
|
}
|
|
47
|
+
} else if (
|
|
48
|
+
config.region &&
|
|
49
|
+
config.region.hasOwnProperty('top') &&
|
|
50
|
+
config.region.hasOwnProperty('left') &&
|
|
51
|
+
config.region.hasOwnProperty('width') &&
|
|
52
|
+
config.region.hasOwnProperty('height')
|
|
53
|
+
) {
|
|
54
|
+
regionSettings = {
|
|
55
|
+
region: {
|
|
56
|
+
y: config.region.top,
|
|
57
|
+
x: config.region.left,
|
|
58
|
+
width: config.region.width,
|
|
59
|
+
height: config.region.height,
|
|
60
|
+
},
|
|
61
|
+
};
|
|
47
62
|
} else if (!config.hasOwnProperty('selector')) {
|
|
48
63
|
regionSettings = {
|
|
49
64
|
region: config.region,
|
|
@@ -128,8 +143,8 @@ function eyesCheckMapValues({args, refer}) {
|
|
|
128
143
|
}
|
|
129
144
|
} else {
|
|
130
145
|
accessabilityRegion.region = {
|
|
131
|
-
|
|
132
|
-
|
|
146
|
+
y: region.top,
|
|
147
|
+
x: region.left,
|
|
133
148
|
width: region.width,
|
|
134
149
|
height: region.height,
|
|
135
150
|
};
|
|
@@ -161,8 +176,8 @@ function eyesCheckMapValues({args, refer}) {
|
|
|
161
176
|
}
|
|
162
177
|
} else {
|
|
163
178
|
floatingRegion.region = {
|
|
164
|
-
|
|
165
|
-
|
|
179
|
+
y: region.top,
|
|
180
|
+
x: region.left,
|
|
166
181
|
width: region.width,
|
|
167
182
|
height: region.height,
|
|
168
183
|
};
|
|
@@ -178,11 +193,13 @@ function eyesCheckMapValues({args, refer}) {
|
|
|
178
193
|
const elements = [];
|
|
179
194
|
for (const region of regions) {
|
|
180
195
|
if (isHTMLElement(region)) {
|
|
181
|
-
elements.push(refer.ref(region));
|
|
196
|
+
elements.push(Object.assign(refer.ref(region), {type: 'element'}));
|
|
182
197
|
} else if (region.jquery) {
|
|
183
198
|
region.each(function() {
|
|
184
199
|
// there's a small chance that `this` is not an HTML element. So we just verify it.
|
|
185
|
-
elements.push(
|
|
200
|
+
elements.push(
|
|
201
|
+
isHTMLElement(this) ? Object.assign(refer.ref(this), {type: 'element'}) : this,
|
|
202
|
+
);
|
|
186
203
|
});
|
|
187
204
|
} else {
|
|
188
205
|
elements.push(region);
|
package/src/browser/refer.js
CHANGED
|
@@ -1,19 +1,32 @@
|
|
|
1
|
-
|
|
1
|
+
/* global Node */
|
|
2
2
|
|
|
3
|
+
const uuid = require('uuid');
|
|
3
4
|
const REF_ID = 'applitools-ref-id';
|
|
5
|
+
|
|
4
6
|
class Refer {
|
|
5
|
-
constructor(
|
|
7
|
+
constructor() {
|
|
6
8
|
this.store = new Map();
|
|
7
9
|
this.relation = new Map();
|
|
8
|
-
this.check = check;
|
|
9
10
|
}
|
|
10
11
|
|
|
11
12
|
isRef(ref) {
|
|
12
13
|
return Boolean(ref && ref[REF_ID]);
|
|
13
14
|
}
|
|
14
15
|
|
|
16
|
+
check(value) {
|
|
17
|
+
if (!value) return;
|
|
18
|
+
if (value.nodeType === Node.ELEMENT_NODE) {
|
|
19
|
+
return 'element';
|
|
20
|
+
} else if (value.nodeType === Node.DOCUMENT_NODE || value.ownerDocument) {
|
|
21
|
+
return 'context';
|
|
22
|
+
} else if (value.constructor && value.constructor.name === 'Window') {
|
|
23
|
+
return 'driver';
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
15
27
|
ref(value, parentRef) {
|
|
16
|
-
|
|
28
|
+
const refType = this.check(value);
|
|
29
|
+
if (refType) {
|
|
17
30
|
const ref = uuid.v4();
|
|
18
31
|
this.store.set(ref, value);
|
|
19
32
|
if (parentRef) {
|
|
@@ -24,7 +37,7 @@ class Refer {
|
|
|
24
37
|
}
|
|
25
38
|
childRefs.add({[REF_ID]: ref});
|
|
26
39
|
}
|
|
27
|
-
return {[REF_ID]: ref};
|
|
40
|
+
return {[REF_ID]: ref, type: refType};
|
|
28
41
|
} else if (Array.isArray(value)) {
|
|
29
42
|
return value.map(value => this.ref(value, parentRef));
|
|
30
43
|
} else if (typeof value === 'object' && value !== null) {
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
+
/* global Node */
|
|
1
2
|
const spec = require('../../dist/browser/spec-driver');
|
|
2
3
|
|
|
3
4
|
function socketCommands(socket, refer) {
|
|
4
5
|
socket.command('Driver.executeScript', ({context, script, arg = []}) => {
|
|
5
6
|
const res = spec.executeScript(refer.deref(context), script, derefArgs(arg));
|
|
6
|
-
return refer.ref(res);
|
|
7
|
+
return res ? refer.ref(res) : res;
|
|
7
8
|
});
|
|
9
|
+
|
|
8
10
|
socket.command('Driver.mainContext', () => {
|
|
9
|
-
return refer.ref(spec.mainContext());
|
|
11
|
+
return refer.ref(spec.mainContext()), {type: 'context'};
|
|
10
12
|
});
|
|
11
13
|
|
|
12
14
|
socket.command('Driver.parentContext', ({context}) => {
|
|
@@ -42,12 +44,12 @@ function socketCommands(socket, refer) {
|
|
|
42
44
|
);
|
|
43
45
|
});
|
|
44
46
|
|
|
45
|
-
socket.command('Driver.getUrl',
|
|
46
|
-
return spec.getUrl(refer.deref(
|
|
47
|
+
socket.command('Driver.getUrl', ({driver}) => {
|
|
48
|
+
return spec.getUrl(refer.deref(driver));
|
|
47
49
|
});
|
|
48
50
|
|
|
49
|
-
socket.command('Driver.getTitle',
|
|
50
|
-
return spec.getTitle(refer.deref(
|
|
51
|
+
socket.command('Driver.getTitle', ({driver}) => {
|
|
52
|
+
return spec.getTitle(refer.deref(driver));
|
|
51
53
|
});
|
|
52
54
|
|
|
53
55
|
socket.command('Driver.getCookies', async () => {
|
|
@@ -76,6 +78,19 @@ function socketCommands(socket, refer) {
|
|
|
76
78
|
return arg;
|
|
77
79
|
}
|
|
78
80
|
}
|
|
81
|
+
|
|
82
|
+
function getType(value) {
|
|
83
|
+
if (!value) return;
|
|
84
|
+
if (value.nodeType === Node.ELEMENT_NODE) {
|
|
85
|
+
return 'element';
|
|
86
|
+
} else if (
|
|
87
|
+
value.nodeType === Node.DOCUMENT_NODE ||
|
|
88
|
+
value.ownerDocument ||
|
|
89
|
+
(value.constructor && value.constructor.name === 'Window')
|
|
90
|
+
) {
|
|
91
|
+
return 'context';
|
|
92
|
+
}
|
|
93
|
+
}
|
|
79
94
|
}
|
|
80
95
|
|
|
81
96
|
module.exports = {socketCommands};
|
|
@@ -47,8 +47,8 @@ export function getViewportSize(): Object {
|
|
|
47
47
|
//@ts-ignore
|
|
48
48
|
const currWindow = cy.state('window')
|
|
49
49
|
const viewportSize = {
|
|
50
|
-
width:
|
|
51
|
-
height:
|
|
50
|
+
width: currWindow.innerWidth || currWindow.document.documentElement.clientWidth || currWindow.document.body.clientWidth,
|
|
51
|
+
height: currWindow.innerHeight || currWindow.document.documentElement.clientHeight || currWindow.document.body.clientHeight
|
|
52
52
|
};
|
|
53
53
|
return viewportSize;
|
|
54
54
|
}
|
package/src/plugin/server.js
CHANGED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
|
|
6
|
+
function getCypressPaths({cwd, isCypress10}) {
|
|
7
|
+
if (isCypress10) {
|
|
8
|
+
return getCypressPaths10AndAbove(cwd);
|
|
9
|
+
} else {
|
|
10
|
+
return getCypressPaths9AndBelow(cwd);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function getCypressPaths10AndAbove(cwd) {
|
|
15
|
+
const cypressConfigPath = path.resolve(cwd, 'cypress.config.js');
|
|
16
|
+
if (fs.existsSync(cypressConfigPath)) {
|
|
17
|
+
const configContent = fs.readFileSync(cypressConfigPath, 'utf-8');
|
|
18
|
+
const supportFilePath = getSupportFilePathFromCypress10Config({cwd, configContent});
|
|
19
|
+
const typeScriptFilePath = supportFilePath
|
|
20
|
+
? path.resolve(path.dirname(supportFilePath), 'index.d.ts')
|
|
21
|
+
: undefined;
|
|
22
|
+
return {
|
|
23
|
+
config: cypressConfigPath,
|
|
24
|
+
plugin: cypressConfigPath,
|
|
25
|
+
support: supportFilePath,
|
|
26
|
+
typescript: typeScriptFilePath,
|
|
27
|
+
};
|
|
28
|
+
} else {
|
|
29
|
+
throw new Error(
|
|
30
|
+
`No configuration file found at ${cypressConfigPath}. This is usually caused by setting up Eyes before setting up Cypress. Please run "npx cypress open" first.`,
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function getSupportFilePathFromCypress10Config({cwd, configContent}) {
|
|
36
|
+
let supportFilePath;
|
|
37
|
+
if (configContent.includes('supportFile')) {
|
|
38
|
+
const regex = new RegExp(/(?:supportFile:)(?:\s*)(.*)/g);
|
|
39
|
+
const filePath = regex.exec(configContent)[1].replace(/['|"|,]*/g, '');
|
|
40
|
+
supportFilePath = path.resolve(cwd, filePath);
|
|
41
|
+
} else {
|
|
42
|
+
if (fs.existsSync(path.resolve(cwd, 'cypress/support/e2e.js'))) {
|
|
43
|
+
supportFilePath = path.resolve(cwd, 'cypress/support/e2e.js');
|
|
44
|
+
} else if (fs.existsSync(path.resolve(cwd, 'cypress/support/e2e.ts'))) {
|
|
45
|
+
supportFilePath = path.resolve(cwd, 'cypress/support/e2e.ts');
|
|
46
|
+
} else if (fs.existsSync(path.resolve(cwd, 'cypress/support/component.js'))) {
|
|
47
|
+
supportFilePath = path.resolve(cwd, 'cypress/support/component.js');
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return supportFilePath;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function getCypressPaths9AndBelow(cwd) {
|
|
54
|
+
const cypressConfigPath = path.resolve(cwd, 'cypress.json');
|
|
55
|
+
if (fs.existsSync(cypressConfigPath)) {
|
|
56
|
+
try {
|
|
57
|
+
const configContent = JSON.parse(fs.readFileSync(cypressConfigPath));
|
|
58
|
+
const supportFilePath = path.resolve(configContent.supportFile || 'cypress/support/index.js');
|
|
59
|
+
const typeScriptFilePath = supportFilePath
|
|
60
|
+
? path.resolve(path.dirname(supportFilePath), 'index.d.ts')
|
|
61
|
+
: undefined;
|
|
62
|
+
return {
|
|
63
|
+
config: cypressConfigPath,
|
|
64
|
+
plugin: path.resolve(cwd, configContent.pluginsFile || 'cypress/plugins/index.js'),
|
|
65
|
+
support: supportFilePath,
|
|
66
|
+
typescript: typeScriptFilePath,
|
|
67
|
+
};
|
|
68
|
+
} catch (err) {
|
|
69
|
+
throw new Error(`cypress.json at ${cypressConfigPath} is not a valid JSON: ${err.message}`);
|
|
70
|
+
}
|
|
71
|
+
} else {
|
|
72
|
+
throw new Error(
|
|
73
|
+
`No configuration file found at ${cypressConfigPath}. This is usually caused by setting up Eyes before setting up Cypress. Please run "npx cypress open" first.`,
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
module.exports = getCypressPaths;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const cwd = process.cwd();
|
|
4
|
+
|
|
5
|
+
function getCypressVersion() {
|
|
6
|
+
const cypressPackage = require.resolve('cypress', {paths: [cwd]});
|
|
7
|
+
const packageJson = JSON.parse(
|
|
8
|
+
fs.readFileSync(path.resolve(path.dirname(cypressPackage), 'package.json')),
|
|
9
|
+
);
|
|
10
|
+
return packageJson.version;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
module.exports = getCypressVersion;
|
|
@@ -1,57 +1,23 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const fs = require('fs');
|
|
4
|
-
const path = require('path');
|
|
5
|
-
|
|
6
4
|
const chalk = require('chalk');
|
|
7
|
-
const {readFileSync, writeFileSync} = require('fs');
|
|
8
5
|
const addEyesCommands = require('./addEyesCommands');
|
|
9
6
|
const isCommandsDefined = require('./isCommandsDefined');
|
|
10
|
-
const getFilePath = require('./getFilePath');
|
|
11
|
-
const getCypressConfig = require('./getCypressConfig');
|
|
12
|
-
|
|
13
|
-
function handleCommands(cwd) {
|
|
14
|
-
const cypressConfig = getCypressConfig(cwd);
|
|
15
|
-
const commandsFilePath = getFilePath('support', cypressConfig, cwd);
|
|
16
|
-
const commandsFileContent = readFileSync(commandsFilePath).toString();
|
|
17
|
-
|
|
18
|
-
if (!isCommandsDefined(commandsFileContent)) {
|
|
19
|
-
writeFileSync(commandsFilePath, addEyesCommands(commandsFileContent));
|
|
20
|
-
console.log(chalk.cyan('Commands defined.'));
|
|
21
|
-
} else {
|
|
22
|
-
console.log(chalk.cyan('Commands already defined.'));
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function handlerCommandsCypress10(cwd) {
|
|
27
|
-
const configContent = fs.readFileSync(path.resolve(cwd, 'cypress.config.js'), 'utf-8');
|
|
28
|
-
let supportFilePath;
|
|
29
|
-
if (configContent.includes('supportFile')) {
|
|
30
|
-
const regex = new RegExp(/(?:supportFile:)(?:\s*)(.*)/g);
|
|
31
|
-
const filePath = regex.exec(configContent)[1].replace(/['|"|,]*/g, '');
|
|
32
|
-
supportFilePath = path.resolve(cwd, filePath);
|
|
33
|
-
} else {
|
|
34
|
-
if (fs.existsSync(path.resolve(cwd, 'cypress/support/e2e.js'))) {
|
|
35
|
-
supportFilePath = path.resolve(cwd, 'cypress/support/e2e.js');
|
|
36
|
-
} else if (fs.existsSync(path.resolve(cwd, 'cypress/support/e2e.ts'))) {
|
|
37
|
-
supportFilePath = path.resolve(cwd, 'cypress/support/e2e.ts');
|
|
38
|
-
} else if (fs.existsSync(path.resolve(cwd, 'cypress/support/component.js'))) {
|
|
39
|
-
supportFilePath = path.resolve(cwd, 'cypress/support/component.js');
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
7
|
|
|
8
|
+
function handleCommands(supportFilePath) {
|
|
43
9
|
if (supportFilePath) {
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
10
|
+
const supportFileContent = fs.readFileSync(supportFilePath, 'utf-8');
|
|
11
|
+
|
|
12
|
+
if (!isCommandsDefined(supportFileContent)) {
|
|
13
|
+
fs.writeFileSync(supportFilePath, addEyesCommands(supportFileContent));
|
|
47
14
|
console.log(chalk.cyan('Commands defined.'));
|
|
48
15
|
} else {
|
|
49
16
|
console.log(chalk.cyan('Commands already defined.'));
|
|
50
17
|
}
|
|
51
18
|
} else {
|
|
52
|
-
throw new Error('Commands file not found
|
|
19
|
+
throw new Error('Commands could not be defined. Support file could not be found');
|
|
53
20
|
}
|
|
54
|
-
return supportFilePath;
|
|
55
21
|
}
|
|
56
22
|
|
|
57
|
-
module.exports =
|
|
23
|
+
module.exports = handleCommands;
|
|
@@ -1,31 +1,19 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const {readFileSync, writeFileSync} = require('fs');
|
|
4
3
|
const chalk = require('chalk');
|
|
5
4
|
const {addEyesCypressPlugin} = require('./addEyesCypressPlugin');
|
|
6
5
|
const isPluginDefined = require('./isPluginDefined');
|
|
7
|
-
const getFilePath = require('./getFilePath');
|
|
8
|
-
const getCypressConfig = require('./getCypressConfig');
|
|
9
6
|
const fs = require('fs');
|
|
10
|
-
const path = require('path');
|
|
11
7
|
|
|
12
|
-
function handlePlugin(
|
|
13
|
-
|
|
14
|
-
if (!isCypress10) {
|
|
15
|
-
const cypressConfig = getCypressConfig(cwd);
|
|
16
|
-
filePath = getFilePath('plugins', cypressConfig, cwd);
|
|
17
|
-
fileContent = readFileSync(filePath).toString();
|
|
18
|
-
} else {
|
|
19
|
-
filePath = path.resolve(cwd, 'cypress.config.js');
|
|
20
|
-
fileContent = fs.readFileSync(filePath, 'utf-8');
|
|
21
|
-
}
|
|
8
|
+
function handlePlugin(pluginsFilePath) {
|
|
9
|
+
const fileContent = fs.readFileSync(pluginsFilePath, 'utf-8');
|
|
22
10
|
|
|
23
11
|
if (!isPluginDefined(fileContent)) {
|
|
24
|
-
writeFileSync(
|
|
12
|
+
fs.writeFileSync(pluginsFilePath, addEyesCypressPlugin(fileContent));
|
|
25
13
|
console.log(chalk.cyan('Plugins defined.'));
|
|
26
14
|
} else {
|
|
27
15
|
console.log(chalk.cyan('Plugins already defined'));
|
|
28
16
|
}
|
|
29
17
|
}
|
|
30
18
|
|
|
31
|
-
module.exports =
|
|
19
|
+
module.exports = handlePlugin;
|
|
@@ -1,33 +1,15 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
const chalk = require('chalk');
|
|
3
3
|
const {writeFileSync, existsSync} = require('fs');
|
|
4
|
-
const getFilePath = require('./getFilePath');
|
|
5
|
-
const getCypressConfig = require('./getCypressConfig');
|
|
6
4
|
const eyesIndexContent = `import "@applitools/eyes-cypress"`;
|
|
7
|
-
const {resolve, dirname} = require('path');
|
|
8
5
|
|
|
9
|
-
function handleTypeScript(
|
|
10
|
-
const cypressConfig = getCypressConfig(cwd);
|
|
11
|
-
const typeScriptFilePath = getFilePath('typeScript', cypressConfig, cwd);
|
|
12
|
-
|
|
13
|
-
if (!existsSync(typeScriptFilePath)) {
|
|
14
|
-
writeFileSync(typeScriptFilePath, eyesIndexContent);
|
|
15
|
-
console.log(chalk.cyan('Typescript defined.'));
|
|
16
|
-
} else {
|
|
17
|
-
console.log(chalk.cyan('Typescript already defined.'));
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function handlerTypeScriptCypress10(suportFilePath) {
|
|
22
|
-
const supportDir = dirname(suportFilePath);
|
|
23
|
-
const typeScriptFilePath = resolve(supportDir, 'index.d.ts');
|
|
6
|
+
function handleTypeScript(typeScriptFilePath) {
|
|
24
7
|
if (!existsSync(typeScriptFilePath)) {
|
|
25
8
|
writeFileSync(typeScriptFilePath, eyesIndexContent);
|
|
26
|
-
console.log(chalk.cyan('
|
|
9
|
+
console.log(chalk.cyan('TypeScript defined.'));
|
|
27
10
|
} else {
|
|
28
|
-
console.log(chalk.cyan('
|
|
11
|
+
console.log(chalk.cyan('TypeScript already defined.'));
|
|
29
12
|
}
|
|
30
13
|
}
|
|
31
14
|
|
|
32
|
-
module.exports = {handleTypeScript,
|
|
33
|
-
module.exports.eyesIndexContent = eyesIndexContent;
|
|
15
|
+
module.exports = {handleTypeScript, eyesIndexContent};
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const {readFileSync} = require('fs');
|
|
4
|
-
const {resolve} = require('path');
|
|
5
|
-
const chalk = require('chalk');
|
|
6
|
-
|
|
7
|
-
function getCypressConfig(cwd) {
|
|
8
|
-
const cypressConfigPath = resolve(cwd, 'cypress.json');
|
|
9
|
-
try {
|
|
10
|
-
return JSON.parse(readFileSync(cypressConfigPath));
|
|
11
|
-
} catch (ex) {
|
|
12
|
-
console.log(chalk.red('cypress.json not found at ', cypressConfigPath));
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
module.exports = getCypressConfig;
|