You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/playwright.md
+41-19Lines changed: 41 additions & 19 deletions
Original file line number
Diff line number
Diff line change
@@ -175,8 +175,10 @@ If you need to get element's value inside a test you can use `grab*` methods. Th
175
175
```js
176
176
constassert=require('assert');
177
177
Scenario('get value of current tasks', async ({ I }) => {
178
-
I.createTodo('do 1');
179
-
I.createTodo('do 2');
178
+
I.fillField('.todo', 'my first item');
179
+
I.pressKey('Enter')
180
+
I.fillField('.todo', 'my second item');
181
+
I.pressKey('Enter')
180
182
let numTodos =awaitI.grabTextFrom('.todo-count strong');
181
183
assert.equal(2, numTodos);
182
184
});
@@ -188,17 +190,35 @@ In case some actions should be taken inside one element (a container or modal wi
188
190
Please take a note that you can't use within inside another within in Playwright helper:
189
191
190
192
```js
191
-
within('.todoapp', () => {
192
-
I.createTodo('my new item');
193
+
awaitwithin('.todoapp', () => {
194
+
I.fillField('.todo', 'my new item');
195
+
I.pressKey('Enter')
193
196
I.see('1 item left', '.todo-count');
194
197
I.click('.todo-list input.toggle');
195
198
});
196
199
I.see('0 items left', '.todo-count');
197
200
```
198
201
199
-
> [▶ Learn more about basic commands](/basics#writing-tests)
202
+
### Each Element <Badgetext="Since 3.3"type="warning"/>
200
203
201
-
CodeceptJS allows you to implement custom actions like `I.createTodo` or use **PageObjects**. Learn how to improve your tests in [PageObjects](https://codecept.io/pageobjects/) guide.
204
+
Usually, CodeceptJS performs an action on the first matched element.
205
+
In case you want to do an action on each element found, use the special function `eachElement` which comes from [eachElement](https://codecept.io/plugins/#eachelement) plugin.
206
+
207
+
`eachElement` function matches all elements by locator and performs a callback on each of those element. A callback function receives [ElementHandle instance](https://playwright.dev/docs/api/class-elementhandle) from Playwright API. `eachElement` may perform arbitrary actions on a page, so the first argument should by a description of the actions performed. This description will be used for logging purposes.
208
+
209
+
Usage example
210
+
211
+
```js
212
+
awaiteachElement(
213
+
'tick all checkboxes',
214
+
'input.custom-checkbox',
215
+
async (el, index) => {
216
+
awaitel.check();
217
+
});
218
+
);
219
+
```
220
+
221
+
> ℹ Learn more about [eachElement plugin](/plugins/#eachelement)
Playwright can be added to GitHub Actions using [official action](https://github.com/microsoft/playwright-github-action). Use it before starting CodeceptJS tests to install all dependencies. It is important to run tests in headless mode ([otherwise you will need to enable xvfb to emulate desktop](https://github.com/microsoft/playwright-github-action#run-in-headful-mode)).
315
-
316
-
```yml
317
-
# from workflows/tests.yml
318
-
- uses: microsoft/playwright-github-action@v1
319
-
- name: run CodeceptJS tests
320
-
run: npx codeceptjs run
321
-
```
322
-
323
330
## Accessing Playwright API
324
331
325
332
To get [Playwright API](https://playwright.dev/docs/api/class-playwright) inside a test use `I.usePlaywrightTo` method with a callback.
@@ -496,6 +503,7 @@ Open `index.html` in your browser to view the full interactive coverage report.
To create custom `I.*` commands using Playwright API you need to create a custom helper.
@@ -538,3 +546,17 @@ async setPermissions() {
538
546
> [▶ Learn more about BrowserContext](https://github.com/microsoft/playwright/blob/master/docs/src/api/class-browsercontext.md)
539
547
540
548
> [▶ Learn more about Helpers](https://codecept.io/helpers/)
549
+
550
+
551
+
## Configuring CI
552
+
553
+
### GitHub Actions
554
+
555
+
Playwright can be added to GitHub Actions using [official action](https://github.com/microsoft/playwright-github-action). Use it before starting CodeceptJS tests to install all dependencies. It is important to run tests in headless mode ([otherwise you will need to enable xvfb to emulate desktop](https://github.com/microsoft/playwright-github-action#run-in-headful-mode)).
Use the [faker.js][4] package to generate fake data inside examples on your gherkin tests
571
+
Use the [faker.js][11] package to generate fake data inside examples on your gherkin tests
507
572
508
-
![Faker.js][5]
573
+
![Faker.js][12]
509
574
510
575
#### Usage
511
576
@@ -543,7 +608,7 @@ Scenario Outline: ...
543
608
544
609
## pauseOnFail
545
610
546
-
Automatically launches [interactive pause][6] when a test fails.
611
+
Automatically launches [interactive pause][13] when a test fails.
547
612
548
613
Useful for debugging flaky tests on local environment.
549
614
Add this plugin to config file:
@@ -726,14 +791,14 @@ Possible config options:
726
791
727
792
## selenoid
728
793
729
-
[Selenoid][7] plugin automatically starts browsers and video recording.
794
+
[Selenoid][14] plugin automatically starts browsers and video recording.
730
795
Works with WebDriver helper.
731
796
732
797
### Prerequisite
733
798
734
799
This plugin **requires Docker** to be installed.
735
800
736
-
> If you have issues starting Selenoid with this plugin consider using the official [Configuration Manager][8] tool from Selenoid
801
+
> If you have issues starting Selenoid with this plugin consider using the official [Configuration Manager][15] tool from Selenoid
737
802
738
803
### Usage
739
804
@@ -762,7 +827,7 @@ plugins: {
762
827
}
763
828
```
764
829
765
-
When `autoCreate` is enabled it will pull the [latest Selenoid from DockerHub][9] and start Selenoid automatically.
830
+
When `autoCreate` is enabled it will pull the [latest Selenoid from DockerHub][16] and start Selenoid automatically.
766
831
It will also create `browsers.json` file required by Selenoid.
767
832
768
833
In automatic mode the latest version of browser will be used for tests. It is recommended to specify exact version of each browser inside `browsers.json` file.
@@ -774,10 +839,10 @@ In automatic mode the latest version of browser will be used for tests. It is re
774
839
While this plugin can create containers for you for better control it is recommended to create and launch containers manually.
775
840
This is especially useful for Continous Integration server as you can configure scaling for Selenoid containers.
776
841
777
-
> Use [Selenoid Configuration Manager][8] to create and start containers semi-automatically.
842
+
> Use [Selenoid Configuration Manager][15] to create and start containers semi-automatically.
778
843
779
844
1. Create `browsers.json` file in the same directory `codecept.conf.js` is located
780
-
[Refer to Selenoid documentation][10] to know more about browsers.json.
845
+
[Refer to Selenoid documentation][17] to know more about browsers.json.
781
846
782
847
_Sample browsers.json_
783
848
@@ -802,7 +867,7 @@ _Sample browsers.json_
802
867
803
868
2. Create Selenoid container
804
869
805
-
Run the following command to create a container. To know more [refer here][11]
870
+
Run the following command to create a container. To know more [refer here][18]
806
871
807
872
```bash
808
873
docker create \
@@ -835,15 +900,15 @@ When `allure` plugin is enabled a video is attached to report automatically.
835
900
| enableVideo | Enable video recording and use `video` folder of output (default: false) |
836
901
| enableLog | Enable log recording and use `logs` folder of output (default: false) |
837
902
| deletePassed | Delete video and logs of passed tests (default : true) |
838
-
| additionalParams | example: `additionalParams:'--env TEST=test'` [Refer here][12] to know more |
903
+
| additionalParams | example: `additionalParams:'--env TEST=test'` [Refer here][19] to know more |
839
904
840
905
### Parameters
841
906
842
907
- `config`
843
908
844
909
## stepByStepReport
845
910
846
-
![step-by-step-report][13]
911
+
![step-by-step-report][20]
847
912
848
913
Generates step by step report for a test.
849
914
After each step in a test a screenshot is created. After test executed screenshots are combined into slideshow.
@@ -1024,7 +1089,7 @@ This plugin allows to run webdriverio services like:
1024
1089
- browserstack
1025
1090
- appium
1026
1091
1027
-
A complete list of all available services can be found on [webdriverio website][14].
1092
+
A complete list of all available services can be found on [webdriverio website][21].
1028
1093
1029
1094
#### Setup
1030
1095
@@ -1036,7 +1101,7 @@ See examples below:
1036
1101
1037
1102
#### Selenium Standalone Service
1038
1103
1039
-
Install `@wdio/selenium-standalone-service` package, as [described here][15].
1104
+
Install `@wdio/selenium-standalone-service` package, as [described here][22].
1040
1105
It is important to make sure it is compatible with current webdriverio version.
1041
1106
1042
1107
Enable `wdio` plugin in plugins list and add `selenium-standalone` service:
@@ -1055,7 +1120,7 @@ Please note, this service can be used with Protractor helper as well!
1055
1120
1056
1121
#### Sauce Service
1057
1122
1058
-
Install `@wdio/sauce-service` package, as [described here][16].
1123
+
Install `@wdio/sauce-service` package, as [described here][23].
1059
1124
It is important to make sure it is compatible with current webdriverio version.
1060
1125
1061
1126
Enable `wdio` plugin in plugins list and add `sauce` service:
@@ -1091,28 +1156,42 @@ In the same manner additional services from webdriverio can be installed, enable
Copy file name to clipboardExpand all lines: docs/puppeteer.md
+24-8Lines changed: 24 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -110,7 +110,6 @@ Tests consist with a scenario of user's action taken on a page. The most widely
110
110
All actions which interact with elements **support CSS and XPath locators**. Actions like `click` or `fillField` by locate elements by their name or value on a page:
111
111
112
112
```js
113
-
114
113
// search for link or button
115
114
I.click('Login');
116
115
// locate field by its label
@@ -172,8 +171,10 @@ If you need to get element's value inside a test you can use `grab*` methods. Th
172
171
```js
173
172
constassert=require('assert');
174
173
Scenario('get value of current tasks', async ({ I }) => {
175
-
I.createTodo('do 1');
176
-
I.createTodo('do 2');
174
+
I.fillField('.todo', 'my first item');
175
+
I.pressKey('Enter')
176
+
I.fillField('.todo', 'my second item');
177
+
I.pressKey('Enter')
177
178
let numTodos =awaitI.grabTextFrom('.todo-count strong');
178
179
assert.equal(2, numTodos);
179
180
});
@@ -185,20 +186,35 @@ In case some actions should be taken inside one element (a container or modal wi
185
186
Please take a note that you can't use within inside another within in Puppeteer helper:
186
187
187
188
```js
188
-
within('.todoapp', () => {
189
-
I.createTodo('my new item');
189
+
awaitwithin('.todoapp', () => {
190
+
I.fillField('.todo', 'my new item');
191
+
I.pressKey('Enter')
190
192
I.see('1 item left', '.todo-count');
191
193
I.click('.todo-list input.toggle');
192
194
});
193
195
I.see('0 items left', '.todo-count');
194
196
```
195
197
196
-
> [▶ Learn more about basic commands](/basics#writing-tests)
198
+
### Each Element <Badgetext="Since 3.3"type="warning"/>
199
+
200
+
Usually, CodeceptJS performs an action on the first matched element.
201
+
In case you want to do an action on each element found, use the special function `eachElement` which comes from [eachElement](https://codecept.io/plugins/#eachelement) plugin.
202
+
203
+
`eachElement` function matches all elements by locator and performs a callback on each of those element. A callback function receives [ElementHandle instance](https://pptr.dev/#?product=Puppeteer&show=api-class-elementhandle) from Puppeteer API. `eachElement` may perform arbitrary actions on a page, so the first argument should by a description of the actions performed. This description will be used for logging purposes.
197
204
198
-
CodeceptJS allows you to implement custom actions like `I.createTodo` or use **PageObjects**. Learn how to improve your tests in [PageObjects](https://codecept.io/pageobjects/) guide.
205
+
Usage example
199
206
200
-
> [▶ Demo project is available on GitHub](https://github.com/DavertMik/codeceptjs-todomvc-puppeteer)
207
+
```js
208
+
awaiteachElement(
209
+
'click all checkboxes',
210
+
'input.custom-checkbox',
211
+
async (el, index) => {
212
+
awaitel.click();
213
+
});
214
+
);
215
+
```
201
216
217
+
> ℹ Learn more about [eachElement plugin](/plugins/#eachelement)
0 commit comments