Skip to content

Commit 9755fe8

Browse files
Merge pull request #3 from qavajs/new-po
implemented new po approach
2 parents e801e7e + 1cd9856 commit 9755fe8

22 files changed

+960
-738
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
1010
:pencil: - chore
1111
:microscope: - experimental
1212

13+
## [2.0.0]
14+
- :rocket: implemented new page object approach
15+
1316
## [0.2.0]
1417
- :rocket: added memory write logs support
1518

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
# @qavajs/cypress
2-
qavajs implementation on top of cypress runner
2+
qavajs implementation for cypress runner
33

44
## Installation
55

6-
`npm install @qavajs/cypress`
7-
`npm install @qavajs/cypress-runner-adapter`
6+
`npm install @qavajs/cypress @qavajs/cypress-runner-adapter @qavajs/memory`
87

98
## Configuration
109
cypress.config.js

lib/actions.js

Lines changed: 41 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ import { parseCoords } from './utils';
66
* @param {string} url - url to navigate
77
* @example I open 'https://google.com'
88
*/
9-
When('I open {string} url', function (url) {
10-
const urlValue = this.value(url);
11-
cy.visit(urlValue);
9+
When('I open {value} url', function (url) {
10+
cy.visit(url.value());
1211
});
1312

1413
/**
@@ -17,68 +16,61 @@ When('I open {string} url', function (url) {
1716
* @param {string} value - value to type
1817
* @example I type 'wikipedia' to 'Google Input'
1918
*/
20-
When('I type {string} to {string}', function (value, alias) {
21-
const element = this.element(alias);
22-
const typeValue = this.value(value);
23-
element.type(typeValue);
19+
When('I type {value} to {locator}', function (type, locator) {
20+
locator.type(type.value());
2421
});
2522
//
2623
/**
2724
* Click element
2825
* @param {string} alias - element to click
2926
* @example I click 'Google Button'
3027
*/
31-
When('I click {string}', function (alias) {
32-
const element = this.element(alias);
33-
element.click();
28+
When('I click {locator}', function (locator) {
29+
locator.click();
3430
});
3531

3632
/**
3733
* Click element via script
3834
* @param {string} alias - element to click
3935
* @example I force click 'Google Button'
4036
*/
41-
When('I force click {string}', function (alias) {
42-
const element = this.element(alias);
43-
element.click({force: true});
37+
When('I force click {locator}', function (locator) {
38+
locator.click({force: true});
4439
});
4540

4641
/**
4742
* Right click element
4843
* @param {string} alias - element to right click
4944
* @example I right click 'Google Button'
5045
*/
51-
When('I right click {string}', function (alias) {
52-
const element = this.element(alias);
53-
element.rightclick();
46+
When('I right click {locator}', function (locator) {
47+
locator.rightclick();
5448
});
5549

5650
/**
5751
* Double click element
5852
* @param {string} alias - double element to click
5953
* @example I double click 'Google Button'
6054
*/
61-
When('I double click {string}', function (alias) {
62-
const element = this.element(alias);
63-
element.dblclick();
55+
When('I double click {locator}', function (locator) {
56+
locator.dblclick();
6457
});
6558

6659
/**
6760
* Clear input
6861
* @param {string} alias - element to clear
6962
* @example I clear 'Google Input'
7063
*/
71-
When('I clear {string}', function (alias) {
72-
const element = this.element(alias);
73-
element.clear();
64+
When('I clear {locator}', function (locator) {
65+
locator.clear();
7466
});
7567

7668
/**
7769
* Switch to parent frame
7870
* @example I switch to parent frame
7971
*/
8072
When('I switch to parent frame', function () {
81-
this.po.driver = cy;
73+
this.cy = cy;
8274
});
8375

8476
/**
@@ -87,9 +79,9 @@ When('I switch to parent frame', function () {
8779
* @example I switch to 2 frame
8880
*/
8981
When('I switch to {int} frame', function (index) {
90-
const root = this.po.driver === cy ? cy.get('iframe') : this.po.driver.find('iframe');
91-
this.po.driver = root
92-
.eq(0)
82+
const root = this.cy === cy ? this.cy.get('iframe') : this.cy.find('iframe');
83+
this.cy = root
84+
.eq(index - 1)
9385
.then((iframe) => iframe.contents())
9486
.should('exist')
9587
.find('body');
@@ -100,9 +92,8 @@ When('I switch to {int} frame', function (index) {
10092
* @param {string} index - alias to switch
10193
* @example I switch to 'IFrame' frame
10294
*/
103-
When('I switch to {string} frame', function (frameAlias) {
104-
const frame = this.element(frameAlias);
105-
this.po.driver = frame
95+
When('I switch to {locator} frame', function (frame) {
96+
this.cy = frame
10697
.then((iframe) => iframe.contents())
10798
.should('exist')
10899
.find('body');
@@ -144,11 +135,10 @@ When('I press {string} key(s) {int} time(s)', function (key, num) {
144135
* @param {string} alias - element to hover over
145136
* @example I hover over 'Google Button'
146137
*/
147-
When('I hover over {string}', function (alias) {
148-
const element = this.element(alias);
149-
element.trigger('mouseenter');
150-
element.trigger('mouseover');
151-
element.trigger('mousemove');
138+
When('I hover over {locator}', function (locator) {
139+
locator.trigger('mouseenter');
140+
locator.trigger('mouseover');
141+
locator.trigger('mousemove');
152142
});
153143

154144
/**
@@ -158,10 +148,8 @@ When('I hover over {string}', function (alias) {
158148
* @example I select '1900' option from 'Registration Form > Date Of Birth'
159149
* @example I select '$dateOfBirth' option from 'Registration Form > Date Of Birth' dropdown
160150
*/
161-
When('I select {string} option from {string} dropdown', function (option, alias) {
162-
const optionValue = this.value(option);
163-
const select = this.element(alias);
164-
select.select(optionValue);
151+
When('I select {value} option from {locator} dropdown', function (option, select) {
152+
select.select(option.value());
165153
});
166154

167155
/**
@@ -170,8 +158,7 @@ When('I select {string} option from {string} dropdown', function (option, alias)
170158
* @param {string} alias - alias of select
171159
* @example I select 1 option from 'Registration Form > Date Of Birth' dropdown
172160
*/
173-
When('I select {int}(st|nd|rd|th) option from {string} dropdown', function (optionIndex, alias) {
174-
const select = this.element(alias);
161+
When('I select {int}(st|nd|rd|th) option from {locator} dropdown', function (optionIndex, select) {
175162
select.select(optionIndex - 1);
176163
});
177164
//
@@ -183,11 +170,9 @@ When('I select {int}(st|nd|rd|th) option from {string} dropdown', function (opti
183170
* @example I click '$someVarWithText' text in 'Search Engines' collection
184171
*/
185172
When(
186-
'I click {string} text in {string} collection',
187-
function (value, alias) {
188-
const resolvedValue = this.value(value);
189-
const collection = this.element(alias);
190-
collection.filter(`:contains(${resolvedValue})`).click();
173+
'I click {value} text in {locator} collection',
174+
function (text, collection) {
175+
collection.filter(`:contains(${text.value()})`).click();
191176
}
192177
);
193178

@@ -197,8 +182,8 @@ When(
197182
* @example
198183
* When I scroll by '0, 100'
199184
*/
200-
When('I scroll by {string}', function (offset) {
201-
const [x, y] = parseCoords(this.value(offset));
185+
When('I scroll by {value}', function (offset) {
186+
const [x, y] = parseCoords(offset.value());
202187
cy.scrollTo(x, y);
203188
});
204189

@@ -209,10 +194,9 @@ When('I scroll by {string}', function (offset) {
209194
* @example
210195
* When I scroll by '0, 100' in 'Overflow Container'
211196
*/
212-
When('I scroll by {string} in {string}', function (offset, alias) {
213-
const [x, y] = parseCoords(this.value(offset));
214-
const element = this.element(alias);
215-
element.scrollTo(x, y);
197+
When('I scroll by {value} in {locator}', function (offset, locator) {
198+
const [x, y] = parseCoords(offset.value());
199+
locator.scrollTo(x, y);
216200
});
217201

218202
/**
@@ -221,9 +205,8 @@ When('I scroll by {string} in {string}', function (offset, alias) {
221205
* @example
222206
* When I scroll to 'Some Element'
223207
*/
224-
When('I scroll to {string}', function (alias) {
225-
const element = this.element(alias);
226-
element.scrollIntoView()
208+
When('I scroll to {locator}', function (locator) {
209+
locator.scrollIntoView()
227210
});
228211

229212

@@ -233,10 +216,8 @@ When('I scroll to {string}', function (alias) {
233216
* @param {string} value - file path
234217
* @example I upload '/folder/file.txt' to 'File Input'
235218
*/
236-
When('I upload {string} file to {string}', function (value, alias) {
237-
const element = this.element(alias);
238-
const filePath = this.value(value);
239-
element.selectFile(filePath);
219+
When('I upload {value} file to {locator}', function (filePath, locator) {
220+
locator.selectFile(filePath.value());
240221
});
241222

242223
/**
@@ -266,9 +247,8 @@ When('I will dismiss alert', function () {
266247
* I will type {string} to alert
267248
* @example I type 'coffee' to alert
268249
*/
269-
When('I will type {string} to alert', function (value) {
270-
const resolvedValue = this.value(value);
250+
When('I will type {value} to alert', function (text) {
271251
cy.window().then((win) => {
272-
win.prompt = () => resolvedValue;
252+
win.prompt = () => text.value();
273253
});
274254
});

lib/execute.js

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import { When } from '@qavajs/cypress-runner-adapter';
66
* @example I execute '$fn' function // fn is function reference
77
* @example I execute 'window.scrollBy(0, 100)' function
88
*/
9-
When('I execute {string} function', function (functionKey) {
10-
const fnContent = this.value(functionKey);
9+
When('I execute {value} function', function (functionKey) {
10+
const fnContent = functionKey.value();
1111
const fn = typeof fnContent === 'string' ? new Function(`return ${fnContent}`): fnContent;
1212
cy.window().then(win => {
1313
fn.apply(win);
@@ -21,11 +21,11 @@ When('I execute {string} function', function (functionKey) {
2121
* @example I execute '$fn' function and save result as 'result' // fn is function reference
2222
* @example I execute 'window.scrollY' function and save result as 'scroll'
2323
*/
24-
When('I execute {string} function and save result as {string}', function (functionKey, memoryKey) {
25-
const fnContent = this.value(functionKey);
24+
When('I execute {value} function and save result as {value}', function (functionKey, memoryKey) {
25+
const fnContent = functionKey.value();
2626
const fn = typeof fnContent === 'string' ? new Function(`return ${fnContent}`): fnContent;
2727
cy.window().then(win => {
28-
this.setValue(memoryKey, fn.apply(win));
28+
memoryKey.set(fn.apply(win));
2929
});
3030
});
3131

@@ -36,12 +36,11 @@ When('I execute {string} function and save result as {string}', function (functi
3636
* @example I execute '$fn' function on 'Component > Element' // fn is function reference
3737
* @example I execute 'arguments[0].scrollIntoView()' function on 'Component > Element'
3838
*/
39-
When('I execute {string} function on {string}', function (functionKey, alias) {
40-
const element = this.element(alias);
41-
const fnContent = this.value(functionKey);
39+
When('I execute {value} function on {locator}', function (functionKey, locator) {
40+
const fnContent = functionKey.value();
4241
const fn = typeof fnContent === 'string' ? new Function(`return ${fnContent}`): fnContent;
4342
cy.window().then(win => {
44-
element.then((e) => {
43+
locator.then((e) => {
4544
fn.apply(win, e);
4645
});
4746
});
@@ -55,14 +54,13 @@ When('I execute {string} function on {string}', function (functionKey, alias) {
5554
* @example I execute 'arguments[0].innerText' function on 'Component > Element' and save result as 'innerText'
5655
*/
5756
When(
58-
'I execute {string} function on {string} and save result as {string}',
59-
function (functionKey, alias, memoryKey) {
60-
const element = this.element(alias);
61-
const fnContent = this.value(functionKey);
57+
'I execute {value} function on {locator} and save result as {value}',
58+
function (functionKey, locator, memoryKey) {
59+
const fnContent = functionKey.value();
6260
const fn = typeof fnContent === 'string' ? new Function(`return ${fnContent}`): fnContent;
6361
cy.window().then(win => {
64-
element.then((e) => {
65-
this.setValue(memoryKey, fn.apply(win, e));
62+
locator.then((e) => {
63+
memoryKey.set(fn.apply(win, e));
6664
});
6765
});
6866
}

0 commit comments

Comments
 (0)