@qavajs/cypress 2.5.0 → 2.7.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
@@ -10,6 +10,12 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
10
10
  :pencil: - chore
11
11
  :microscope: - experimental
12
12
 
13
+ ## [2.7.0]
14
+ - :rocket: added logic to display resolved selector chain
15
+
16
+ ## [2.6.0]
17
+ - :rocket: added `I save value of...` step
18
+
13
19
  ## [2.5.0]
14
20
  - :rocket: added http steps
15
21
 
package/lib/memory.js CHANGED
@@ -3,9 +3,9 @@ import { dataTable2Object } from './utils';
3
3
 
4
4
  /**
5
5
  * Save text of element to memory
6
- * @param {string} alias - element to get value
6
+ * @param {string} alias - element to get text
7
7
  * @param {string} key - key to store value
8
- * @example I save text of '#1 of Search Results' as 'firstSearchResult'
8
+ * @example I save text of 'Search Result' as 'firstSearchResult'
9
9
  */
10
10
  When('I save text of {locator} as {value}', function (locator, key) {
11
11
  locator.then(e => {
@@ -13,6 +13,19 @@ When('I save text of {locator} as {value}', function (locator, key) {
13
13
  });
14
14
  });
15
15
 
16
+ /**
17
+ * Save value of element to memory
18
+ * @param {string} alias - element to get value
19
+ * @param {string} key - key to store value
20
+ * @example I save value of 'Search Input' as 'searchInput'
21
+ */
22
+ When('I save value of {locator} as {value}', function (locator, key) {
23
+ locator.then(e => {
24
+ key.set(e.val());
25
+ });
26
+ });
27
+
28
+
16
29
  /**
17
30
  * Save property of element to memory
18
31
  * @param {string} property - property to store
@@ -22,16 +22,22 @@ export const locator = function locator(selector) {
22
22
  return new Selector(selector);
23
23
  }
24
24
 
25
- locator.template = function(selector) {
25
+ locator.template = function (selector) {
26
26
  return new Selector(selector, 'template');
27
27
  }
28
28
 
29
- locator.native = function(selector) {
29
+ locator.native = function (selector) {
30
30
  return new Selector(selector, 'native');
31
31
  }
32
32
 
33
+ locator.as = function (component) {
34
+ const selector = new Selector(null);
35
+ selector.component = component;
36
+ return selector;
37
+ }
38
+
33
39
  export class ChainItem {
34
- constructor({ alias, argument, selector, type }) {
40
+ constructor({alias, argument, selector, type}) {
35
41
  this.alias = alias;
36
42
  this.argument = argument;
37
43
  this.selector = selector;
@@ -67,26 +73,51 @@ export function query(root, path) {
67
73
  }
68
74
 
69
75
  export function element(path) {
70
- const chain = query(this.pageObject, path);
71
- let current = this.cy;
72
- let method = 'get';
73
- for (const item of chain) {
74
- switch (item.type) {
75
- case 'simple':
76
- current = current[method](item.selector);
77
- break;
78
- case 'template':
79
- current = current[method](item.selector(item.argument));
80
- break;
81
- case 'native':
82
- current = item.selector({
83
- parent: current,
84
- cy: this.cy,
85
- argument: item.argument
86
- });
87
- break;
76
+ return cy.then(() => {
77
+ const chain = query(this.pageObject, path);
78
+ let current = this.cy;
79
+ let method = 'get';
80
+ let logChain = `cy`;
81
+
82
+ const applySelector = (selector) => {
83
+ if (!selector) return;
84
+ logChain += `.${method}('${selector}')`;
85
+ current = current[method](selector);
86
+ };
87
+
88
+ const applyNative = (item) => {
89
+ logChain += `.${method}([native])`;
90
+ current = item.selector({
91
+ parent: current,
92
+ cy: this.cy,
93
+ argument: item.argument
94
+ });
95
+ };
96
+
97
+ for (const item of chain) {
98
+ switch (item.type) {
99
+ case 'simple': {
100
+ applySelector(item.selector);
101
+ }
102
+ break;
103
+ case 'template': {
104
+ const selector = item.selector(item.argument);
105
+ applySelector(selector);
106
+ }
107
+ break;
108
+ case 'native': {
109
+ applyNative(item);
110
+ }
111
+ break;
112
+ default:
113
+ throw new Error(`Unsupported selector type '${item.type}' for alias '${item.alias}'`);
114
+ }
115
+ method = item.selector ? 'find' : 'get';
88
116
  }
89
- method = 'find';
90
- }
91
- return current;
117
+ Cypress.log({
118
+ name: `${path} →`,
119
+ message: logChain
120
+ });
121
+ return current;
122
+ });
92
123
  }
package/lib/setup.js CHANGED
@@ -5,9 +5,10 @@ import {element} from './pageObjects';
5
5
  const logger = {
6
6
  log: (value) => {
7
7
  const [displayName, divider, message] = value.split(/\s(->|<-)\s/);
8
+ const displayedDivider = divider === '->' ? '→' : '←';
8
9
  cy.then(() => {
9
10
  Cypress.log({
10
- displayName: `${displayName} ${divider}`,
11
+ displayName: `${displayName} ${displayedDivider}`,
11
12
  message,
12
13
  type: 'parent',
13
14
  consoleProps: () => {
package/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "@qavajs/cypress",
3
- "version": "2.5.0",
3
+ "version": "2.7.0",
4
4
  "description": "qavajs for cypress runner",
5
5
  "main": "index.js",
6
6
  "scripts": {
7
7
  "debug": "cypress open --config-file test-e2e/cypress.config.js",
8
- "test": "cypress run --config-file test-e2e/cypress.config.js"
8
+ "test": "cypress run --config-file test-e2e/cypress.config.js",
9
+ "test:it": "MODE=it cypress run --config-file test-e2e/cypress.config.js"
9
10
  },
10
11
  "keywords": [
11
12
  "QA",
@@ -27,8 +28,8 @@
27
28
  "author": "Alexandr Galichenko",
28
29
  "license": "MIT",
29
30
  "devDependencies": {
30
- "@qavajs/cypress-runner-adapter": "^1.5.0",
31
+ "@qavajs/cypress-runner-adapter": "^1.6.0",
31
32
  "@qavajs/memory": "^1.10.3",
32
- "cypress": "^15.8.1"
33
+ "cypress": "^15.10.0"
33
34
  }
34
35
  }