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
{{ message }}
This repository was archived by the owner on Jul 29, 2024. It is now read-only.
Please see [our TypeScript examples which use `async`/`await`](/exampleTypescript/asyncAwait/).
4
+
**Background**
5
+
6
+
- The Web Driver Control Flow is used to synchronize your commands so they reach
7
+
the browser in the correct order (see
8
+
[/docs/control-flow.md](/docs/control-flow.md) for details). In the future, the
9
+
control flow is being removed (see [SeleniumHQ's github issue](
10
+
https://github.com/SeleniumHQ/selenium/issues/2969) for details). Instead of the
11
+
control flow, you can synchronize your commands with promise chaining or the
12
+
upcoming ES7 feature `async`/`await`.
13
+
14
+
- Previously, we have Typescript support for `async`/`await`: Please see [TypeScript examples which use `async`/`await`](/exampleTypescript/asyncAwait/README.md).
15
+
16
+
- The latest [Node.js](https://nodejs.org/en/) provides native async/await,
17
+
which means we can get stable e2e test without using control flow in javascript test.
18
+
19
+
**Note**: To write and run native async/await test, the node.js version should be greater than or equal to 8.0, and Jasmine version should be greater than or equal to 2.7
20
+
21
+
- If we disable control flow and use async/await to write tests, we can get a
22
+
better debugging experience by using [chrome
23
+
inspector](./debugging.md#disabled-control-flow)
24
+
25
+
**How to use native async/await in test**
26
+
27
+
We have a simple example to show how to use async/await in test.
28
+
29
+
You can find the whole example in
30
+
[here](/debugging/async_await.js)
31
+
32
+
```javascript
33
+
describe('angularjs homepage', function() {
34
+
it('should greet the named user', asyncfunction() {
Copy file name to clipboardExpand all lines: docs/debugging.md
+121-59
Original file line number
Diff line number
Diff line change
@@ -7,8 +7,7 @@ state of the application they're testing. WebDriver tests in particular
7
7
can be difficult to debug because of long error messages and the separation
8
8
between the browser and the process running the test.
9
9
10
-
Types of Failure
11
-
----------------
10
+
## Types of Failure
12
11
13
12
Protractor comes with examples of failing tests ([failure_spec.js](https://github.com/angular/protractor/blob/master/debugging/failure_spec.js)).
14
13
To run, start up the test application and a Selenium Server, and run the command below. Then look at all the stack traces.
@@ -28,15 +27,125 @@ This test suite shows various types of failure:
28
27
like.
29
28
30
29
31
-
Timeouts
32
-
--------
30
+
## Timeouts
33
31
34
32
There are several ways that Protractor can time out. See the [Timeouts](/docs/timeouts.md)
35
33
reference for full documentation.
36
34
35
+
## Disabled Control Flow
37
36
38
-
Pausing to Debug
39
-
----------------
37
+
38
+
The latest [Node.js](https://nodejs.org/en/) provides native async/await, which
39
+
means we can get stable e2e test easily without using control flow. Furthermore,
40
+
if we write our test by using async/await[(how to?)](./async-await.md), we can
41
+
use chrome development tool and chrome inspector together to debug the new
42
+
tests, which will give a nicer debugging experience.
43
+
44
+
**Debuging tests in chrome inspector**
45
+
46
+
We can debug both javascript and TypeScript async/await tests in chrome
47
+
inspector and the debugging process is almost the same.
48
+
49
+
We have a simple example to show how to debug async/await in test. You can find
50
+
the whole example in
51
+
[here](../debugging/async_await.js)
52
+
53
+
- Add “debugger” keyword to the test case that we want to debug.
54
+
55
+
```javascript
56
+
it('should greet the named user', asyncfunction() {
- Start test processwith a newargument"inspect-brk", which will enable
69
+
inspector agent, listen on default address and port (127.0.0.1:9229) and
70
+
break before user code starts
71
+
72
+
Use
73
+
74
+
```
75
+
node --inspect-brk bin/protractor <config_file>
76
+
```
77
+
78
+
- Open chrome inspector: Enter "chrome://inspect/#devices"in browser, find
79
+
the current running target and click “Inspect”
80
+
81
+

82
+
83
+
- The test will start and pause at the beginning.
84
+
85
+

86
+
87
+
- We can click F8 (resume script execution), and the test will pause at the
88
+
first line that has our “debugger” keyword. We can then add breakpoints and
89
+
debug tests.
90
+
91
+

92
+
93
+
- We can also open chrome development tool on the webdriver controlled browser
94
+
to check the html elements and do some queries while the test execution is
95
+
pausing.
96
+
97
+

98
+
99
+
- Known Issues
100
+
101
+
1. If we resume test execution after a long time pause, it will jump to next
102
+
test case even we have some other breaking points in current test case since
103
+
current test case has already been timeout. You can set
104
+
jasmine.DEFAULT_TIMEOUT_INTERVAL to an arbitrary high value so that your
105
+
test doesn't time out.
106
+
107
+
2. If we step into protractor lib code which was written in Typescript, we
108
+
cannot see the TypeScript code. In general, you can add breakpoints to each
109
+
line that you want it to pause, and use F8 (resume script execution) to
110
+
debug(To avoid step into protractor lib).
111
+
112
+
113
+
**Setting Up VSCode for Debugging**
114
+
115
+
VS Code has built-in [debugging](https://code.visualstudio.com/docs/editor/debugging) support for the Node.js runtime and can debug JavaScript, TypeScript, and any other language that gets transpiled to JavaScript.
116
+
117
+
To set up VSCode for Protractor, follow the below steps:
118
+
119
+
1. Click on the Debugging icon in the View Bar on the side of VS Code.
120
+
2. Click on the Configure gear icon on the Debug view top bar and choose nodejs environment.
121
+
3. It will generate a `launch.json` file under your workspace's `.vscode` folder.
122
+
4. Setup your launch.json file by configuring below two commands:
If you've set the `SELENIUM_PROMISE_MANAGER` config value to false to [disable the control flow](https://github.com/angular/protractor/blob/master/docs/control-flow.md),
155
-
the above methods will not work. Instead, you can now use native `debugger` statements to pause your code. However, you
156
-
will need to start your tests using Node's `--inspect-brk` option:
You will then be able to use the Chrome devtools at chrome://inspect to connect to the tests.
163
-
164
-
165
-
Setting Up VSCode for Debugging
166
-
-------------------------------
167
-
VS Code has built-in [debugging](https://code.visualstudio.com/docs/editor/debugging) support for the Node.js runtime and can debug JavaScript, TypeScript, and any other language that gets transpiled to JavaScript.
168
-
169
-
To set up VSCode for Protractor, follow the below steps:
170
-
171
-
1. Click on the Debugging icon in the View Bar on the side of VS Code.
172
-
2. Click on the Configure gear icon on the Debug view top bar and choose nodejs environment.
173
-
3. It will generate a `launch.json` file under your workspace's `.vscode` folder.
174
-
4. Setup your launch.json file by configuring below two commands:
0 commit comments