@@ -6,9 +6,8 @@ import { parseCoords } from './utils';
6
6
* @param {string } url - url to navigate
7
7
* @example I open 'https://google.com'
8
8
*/
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 ( ) ) ;
12
11
} ) ;
13
12
14
13
/**
@@ -17,68 +16,61 @@ When('I open {string} url', function (url) {
17
16
* @param {string } value - value to type
18
17
* @example I type 'wikipedia' to 'Google Input'
19
18
*/
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 ( ) ) ;
24
21
} ) ;
25
22
//
26
23
/**
27
24
* Click element
28
25
* @param {string } alias - element to click
29
26
* @example I click 'Google Button'
30
27
*/
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 ( ) ;
34
30
} ) ;
35
31
36
32
/**
37
33
* Click element via script
38
34
* @param {string } alias - element to click
39
35
* @example I force click 'Google Button'
40
36
*/
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 } ) ;
44
39
} ) ;
45
40
46
41
/**
47
42
* Right click element
48
43
* @param {string } alias - element to right click
49
44
* @example I right click 'Google Button'
50
45
*/
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 ( ) ;
54
48
} ) ;
55
49
56
50
/**
57
51
* Double click element
58
52
* @param {string } alias - double element to click
59
53
* @example I double click 'Google Button'
60
54
*/
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 ( ) ;
64
57
} ) ;
65
58
66
59
/**
67
60
* Clear input
68
61
* @param {string } alias - element to clear
69
62
* @example I clear 'Google Input'
70
63
*/
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 ( ) ;
74
66
} ) ;
75
67
76
68
/**
77
69
* Switch to parent frame
78
70
* @example I switch to parent frame
79
71
*/
80
72
When ( 'I switch to parent frame' , function ( ) {
81
- this . po . driver = cy ;
73
+ this . cy = cy ;
82
74
} ) ;
83
75
84
76
/**
@@ -87,9 +79,9 @@ When('I switch to parent frame', function () {
87
79
* @example I switch to 2 frame
88
80
*/
89
81
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 )
93
85
. then ( ( iframe ) => iframe . contents ( ) )
94
86
. should ( 'exist' )
95
87
. find ( 'body' ) ;
@@ -100,9 +92,8 @@ When('I switch to {int} frame', function (index) {
100
92
* @param {string } index - alias to switch
101
93
* @example I switch to 'IFrame' frame
102
94
*/
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
106
97
. then ( ( iframe ) => iframe . contents ( ) )
107
98
. should ( 'exist' )
108
99
. find ( 'body' ) ;
@@ -144,11 +135,10 @@ When('I press {string} key(s) {int} time(s)', function (key, num) {
144
135
* @param {string } alias - element to hover over
145
136
* @example I hover over 'Google Button'
146
137
*/
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' ) ;
152
142
} ) ;
153
143
154
144
/**
@@ -158,10 +148,8 @@ When('I hover over {string}', function (alias) {
158
148
* @example I select '1900' option from 'Registration Form > Date Of Birth'
159
149
* @example I select '$dateOfBirth' option from 'Registration Form > Date Of Birth' dropdown
160
150
*/
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 ( ) ) ;
165
153
} ) ;
166
154
167
155
/**
@@ -170,8 +158,7 @@ When('I select {string} option from {string} dropdown', function (option, alias)
170
158
* @param {string } alias - alias of select
171
159
* @example I select 1 option from 'Registration Form > Date Of Birth' dropdown
172
160
*/
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 ) {
175
162
select . select ( optionIndex - 1 ) ;
176
163
} ) ;
177
164
//
@@ -183,11 +170,9 @@ When('I select {int}(st|nd|rd|th) option from {string} dropdown', function (opti
183
170
* @example I click '$someVarWithText' text in 'Search Engines' collection
184
171
*/
185
172
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 ( ) ;
191
176
}
192
177
) ;
193
178
@@ -197,8 +182,8 @@ When(
197
182
* @example
198
183
* When I scroll by '0, 100'
199
184
*/
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 ( ) ) ;
202
187
cy . scrollTo ( x , y ) ;
203
188
} ) ;
204
189
@@ -209,10 +194,9 @@ When('I scroll by {string}', function (offset) {
209
194
* @example
210
195
* When I scroll by '0, 100' in 'Overflow Container'
211
196
*/
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 ) ;
216
200
} ) ;
217
201
218
202
/**
@@ -221,9 +205,8 @@ When('I scroll by {string} in {string}', function (offset, alias) {
221
205
* @example
222
206
* When I scroll to 'Some Element'
223
207
*/
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 ( )
227
210
} ) ;
228
211
229
212
@@ -233,10 +216,8 @@ When('I scroll to {string}', function (alias) {
233
216
* @param {string } value - file path
234
217
* @example I upload '/folder/file.txt' to 'File Input'
235
218
*/
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 ( ) ) ;
240
221
} ) ;
241
222
242
223
/**
@@ -266,9 +247,8 @@ When('I will dismiss alert', function () {
266
247
* I will type {string} to alert
267
248
* @example I type 'coffee' to alert
268
249
*/
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 ) {
271
251
cy . window ( ) . then ( ( win ) => {
272
- win . prompt = ( ) => resolvedValue ;
252
+ win . prompt = ( ) => text . value ( ) ;
273
253
} ) ;
274
254
} ) ;
0 commit comments