简体   繁体   English

在 Angular 中导入 protractor 时如何修复“浏览器”未定义

[英]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 .在 Angualr 应用程序中导入量角器时,我尝试使用 function browser.waitForAngularEnabled

When I run the code I get the error:当我运行代码时,我收到错误:

E/launcher - Error: TypeError: Cannot read property 'waitForAngularEnabled' of undefined E/启动器 - 错误:TypeError:无法读取未定义的属性“waitForAngularEnabled”

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.当我在 VS 代码中单击 protractor 模块时,我可以在其中看到浏览器 object 但在运行时会引发此错误。

In Protractor, you are provided with a global browser object.在 Protractor 中,为您提供了一个全局浏览器 object。 So you don't need to require it, the browser object is accessible without requiring it.所以你不需要它,浏览器 object 不需要它就可以访问。

Solution: Just remove the require and it will work.解决方案:只需删除 require 即可。

Note: You have to import it only if you are working with typescript.注意:只有在使用 typescript 时才需要导入它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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