0

I've been hunting this one for a while, and I can't seem to find a clear answer.

Basically, it looks like when writing protractor tests (With Node 8 or higher) now everything has to be async/awaited to be able to debug the test. Is this correct?

As a test I did place await/async on one of my tests. To be able to debug, it required almost every single line to be awaited. If I missed a single line, it wouldn't debug properly. This made writing and debugging the test very janky.

Am I just missing something obvious, or is this really what I need to do?

I found the following video which seems to show this is required.

https://www.youtube.com/watch?v=6aPfHrSl0Qk&t=976s

Limey
  • 2,642
  • 6
  • 37
  • 62

1 Answers1

1

Yes async/await is the way of the future. You can see in this question here that node 8 breaks a lot of what you're expecting to work to debug your code. To be able to keep up with the direction that Protractor is going you get to heavily alter all of your existing tests. It sucks, but I'll tell you what I've found helps.

Sounds like the first thing you need is to add the lint rule for no-floating-promises which will tell you which awaits you are missing. You can even set it to where only your e2e folder is affected by this rule, which helps if you aren't wanting to change your entire app.

Since now everything is a promise I also suggest replacing any forEach you have that involves promises. While you think that it should be sequential, it isn't. Pretty much anything and everything coming back from the browser is a promise, and if your types are outdated then some things that aren't marked as a promise will be anyhow. A for-of loop works as a decent replacement in this case. Why? The forEach will start every promise in the loop at the same time, causing WebDriver to error on you.

While you're at it, you will likely want to upgrade jasmine if you haven't already. If you're not yet on typescript 3.0 I have found that "jasmine-core": "2.99.1" along with "@types/jasmine": "2.8.9" will tell you when you are not awaiting a promise in an expect. It also does type checking in your expect, which is a plus over the older versions. These are very specific versions, the next ones up didn't seem to work with older versions of typescript.

Lastly, suggest looking at your protractor.conf and changing any beforeEach, afterEach, etc to be async and await whatever is in them.

I'm sure I've forgotten a few things, but that should get you started.

Wesley Trantham
  • 1,154
  • 6
  • 12