简体   繁体   中英

How to fix 'browser' being undefined when importing protractor in Angular

When importing protrator in an Angualr application I try to use the function browser.waitForAngularEnabled .

When I run the code I get the error:

E/launcher - Error: TypeError: Cannot read property 'waitForAngularEnabled' of undefined

I am importing the browser in this way

   const { browser } = require('protractor');

When I click through to the protractor module in VS code I can see the browser object in there but in runtime this error is thrown.

In Protractor, you are provided with a global browser object. So you don't need to require it, the browser object is accessible without requiring it.

Solution: Just remove the require and it will work.

Note: You have to import it only if you are working with typescript.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM