Skip to content

Commit 4c8b597

Browse files
committed
feat: Add instructions for while, until and repeat loops
1 parent 77acc55 commit 4c8b597

File tree

4 files changed

+288
-18
lines changed

4 files changed

+288
-18
lines changed

Gruntfile.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,49 @@ module.exports = function (grunt) {
414414
wait: 1
415415
}]
416416
},
417+
{
418+
url: 'http://localhost:8881/test/pages/dynamic.html',
419+
hasClass: {
420+
selector: 'body',
421+
value: '!dynamic'
422+
}
423+
},
424+
{
425+
while: {
426+
hasClass: {
427+
selector: 'body',
428+
value: '!dynamic'
429+
}
430+
},
431+
do: {
432+
wait: 10
433+
}
434+
},
435+
{
436+
url: 'http://localhost:8881/test/pages/input.html',
437+
isNotFocused: 'input'
438+
},
439+
{
440+
do: {
441+
keys: ['Tab']
442+
},
443+
until: {
444+
isFocused: 'input'
445+
}
446+
},
447+
{
448+
go: 'refresh',
449+
isNotFocused: 'input'
450+
},
451+
{
452+
repeat: 2,
453+
do: {
454+
click: 'input'
455+
}
456+
},
457+
{
458+
isFocused: 'input'
459+
},
417460
{
418461
setViewport: {
419462
width: 768,

INSTRUCTIONS.md

Lines changed: 116 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@
33
One of the instructions has to be present in every command. These properties are evaluated (and their effect is executed) in the order, in which they are listed below:
44

55
- [if-then-else](#if-then-else)
6+
- [while-do](#while-do)
7+
- [do-until](#do-until)
8+
- [repeat-do](#repeat-do)
69
- [setViewport](#setviewport)
710
- [url](#url)
811
- [go](#go)
912
- [scroll](#scroll)
13+
- [focus](#focus)
1014
- [clearValue](#clearvalue)
1115
- [setValue](#setvalue)
1216
- [addValue](#addvalue)
@@ -50,12 +54,14 @@ Type: `Object` | `Array` (optional)
5054
### else
5155
Type: `Object` | `Array` (optional)
5256

53-
At first the sub-commands from the `if` instruction are performed. If they succeed, the execution continues with sub-sommands from the `then` instruction. If they fail, the execution continues with sub-sommands from the `else` instruction. The success or failure of the whole conditional command will depend on either of `then` and `else` instructions, which are executed. The success or failure of the `if` instruction decides only the following condition branch.
57+
At first the sub-commands from the `if` instruction are performed. If they succeed, the execution continues with sub-commands from the `then` instruction. If they fail, the execution continues with sub-commands from the `else` instruction. The success or failure of the whole conditional command will depend on either of `then` and `else` instructions, which are executed. The success or failure of the `if` instruction decides only the following condition branch.
5458

5559
```js
5660
{
5761
url: 'https://google.com',
58-
wait: '#lst-ib',
62+
wait: '#lst-ib'
63+
},
64+
{
5965
if: {
6066
hasAttribute: {
6167
selector: '#lst-ib',
@@ -66,9 +72,100 @@ At first the sub-commands from the `if` instruction are performed. If they succe
6672
then: {
6773
setValue: {
6874
selector: '#lst-ib',
69-
value: 'autocomplete is off'
75+
value: 'why is autocomplete off'
7076
}
77+
}
78+
},
79+
{
80+
file: 'google'
81+
}
82+
```
83+
84+
## while-do
85+
86+
Cyclic command with the condition evaluated before the loop body. If the condition evaluates to a truthy value, the loop body will be executed. Then the condition will be evaluated again and so on. The command consists of two instructions, which each points to a sub-command or to an array of sub-commands to evaluate and perform:
87+
88+
### while
89+
Type: `Object` | `Array` (mandatory)
90+
91+
### do
92+
Type: `Object` | `Array` (optional)
93+
94+
At first the sub-commands from the `while` instruction are performed. If they succeed, the execution continues with sub-commands from the `do` instruction. If they fail, sub-commands from the `do` instruction will be skipped and the execution will continue with the next command. The success or failure of the whole cyclic command will depend on the loop body in the `do` instruction. The success or failure of the `while` instruction decides only if the loop is entered or not.
95+
96+
```js
97+
{
98+
url: 'https://google.com',
99+
wait: '#lst-ib'
100+
},
101+
{
102+
while: {
103+
isNotFocused: '#lst-ib'
71104
},
105+
do: {
106+
keys: ['Tab']
107+
}
108+
},
109+
{
110+
file: 'google'
111+
}
112+
```
113+
114+
## do-until
115+
116+
Cyclic command with the condition evaluated after the loop body. The loop body will be executed and then the condition evaluated. If it evaluates to a falsy value, the loop body will be executed again and so on. The command consists of two instructions, which each points to a sub-command or to an array of sub-commands to evaluate and perform:
117+
118+
### do
119+
Type: `Object` | `Array` (optional)
120+
121+
### until
122+
Type: `Object` | `Array` (mandatory)
123+
124+
At first the sub-commands from the `do` instruction are performed. Then the sub-commands from the `until` instruction are performed. If they succeed, the execution will continue with the next command. The success or failure of the `until` instruction decides only if the loop is re-entered or not. The success or failure of the whole cyclic command will depend on the loop body in the `do` instruction.
125+
126+
```js
127+
{
128+
url: 'https://google.com',
129+
wait: '#lst-ib'
130+
},
131+
{
132+
do: {
133+
keys: ['Tab']
134+
}
135+
until: {
136+
isFocused: '#lst-ib'
137+
}
138+
},
139+
{
140+
file: 'google'
141+
}
142+
```
143+
144+
## repeat-do
145+
146+
Cyclic command with the known count of repetitions of the loop body. The loop body will be executed the specified count of times. The command consists of two instructions, which one points to a repetition count and the other to a sub-command or to an array of sub-commands to perform:
147+
148+
### repeat
149+
Type: `Number` (mandatory)
150+
151+
### do
152+
Type: `Object` | `Array` (optional)
153+
154+
At first the current repetition count is compared to the specified target one. If if is less, the execution continues with sub-commands from the `do` instruction. It it is greater or equal to it, sub-commands from the `do` instruction will be skipped and the execution will continue with the next command. Then the current repetition count is incremented by one and the condition evaluated again and so on. The success or failure of the whole cyclic command will depend on the loop body in the `do` instruction.
155+
156+
```js
157+
{
158+
url: 'https://google.com',
159+
wait: '#lst-ib'
160+
},
161+
{
162+
repeat: 10,
163+
do: {
164+
click: '#lst-ib'
165+
}
166+
},
167+
{
168+
isFocused: '#lst-ib',
72169
file: 'google'
73170
}
74171
```
@@ -134,6 +231,22 @@ Scrolls the page, so that the element with the specified selector or mouse coord
134231

135232
The `offset` value can be specified instead of the `selector` and shares the format with the [`moveCursor`](#moveCursor) instruction.
136233

234+
## focus
235+
Type: `String`
236+
237+
Focuses the the specified element by JavaScript.
238+
239+
The input string should contain selector of the element to set focus to.
240+
241+
```js
242+
{
243+
url: 'https://google.com',
244+
wait: '#lst-ib',
245+
focus: 'input[name=btnK]',
246+
file: 'google'
247+
}
248+
```
249+
137250
## clearValue
138251
Type: `String`
139252

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,10 +272,15 @@ You can use sub-tasks, `commands` and `scenarios` to structure your code and exe
272272

273273
One of the [instructions] has to be present in every command, otherwise its execution will fail. If you include a key in your command object, which is not recognised as an instruction or other known key (`file`, `options`), the execution will fail too. The following instructions are recognised (and their effect is executed) in the order, in which they are listed below:
274274

275+
* [if-then-else](INSTRUCTIONS.md#if-then-else)
276+
* [while-do](INSTRUCTIONS.md#while-do)
277+
* [do-until](INSTRUCTIONS.md#do-until)
278+
* [repeat-do](INSTRUCTIONS.md#repeat-do)
275279
* [setViewport](INSTRUCTIONS.md#setviewport)
276280
* [url](INSTRUCTIONS.md#url)
277281
* [go](INSTRUCTIONS.md#go)
278282
* [scroll](INSTRUCTIONS.md#scroll)
283+
* [focus](INSTRUCTIONS.md#focus)
279284
* [clearValue](INSTRUCTIONS.md#clearvalue)
280285
* [setValue](INSTRUCTIONS.md#setvalue)
281286
* [addValue](INSTRUCTIONS.md#addvalue)

0 commit comments

Comments
 (0)