量角器中的ExpectedConditions未定义

SMP*_*MPH 4 typescript protractor

我是量角器的新手,使用量角器 Version 4.0.2

但是,当我有下面的代码时,我得到错误的protractor关键字

   import { browser } from 'protractor/globals';

   let EC =  protractor.ExpectedConditions;
Run Code Online (Sandbox Code Playgroud)

错误:

[ts] 
Cannot find name 'protractor'.
Run Code Online (Sandbox Code Playgroud)

我需要在这里专门导入任何东西吗?

此外,我尝试'预期条件'在类型'typeof量角器'上不存在.虽然没有运气.

cni*_*ina 6

对于版本4.0.2 - 4.0.8,ExpectedConditions已通过以下方式导出:

import { ExpectedConditions } from 'protractor/globals';
Run Code Online (Sandbox Code Playgroud)

它也可以从全局量角器对象访问:

import { protractor } from 'protractor/globals';

let EC = protractor.EC;
Run Code Online (Sandbox Code Playgroud)

在版本4.0.9+中,导入略有不同.导入不再是'protractor/globals',应该只是来自'protractor'.例如:

import { protractor } from 'protractor';
Run Code Online (Sandbox Code Playgroud)

4.0.14更新:

使用pull请求https://github.com/angular/protractor/pull/3766,EC不再是静态的,并且与浏览器实例绑定.因此,如果您的浏览器会话已关闭,则需要再次设置EC.如果不这样做,您将收到有关正在关闭的会话的硒错误.

describe('ec' () => {
  it('is tied to the browser instance', () => {
    let EC = protractor.ExpectedConditions;
    // Or EC = browser.ExpectedConditions;
  });
});
Run Code Online (Sandbox Code Playgroud)