'ExpectedConditions' does not exist on typ

2019-07-11 05:36发布

问题:

I'm writing a protractor test in TypeScript in Visual Studio 2013 and I'm getting the error:

Property 'ExpectedConditions' does not exist on type 'typeof protractor'.

I read a similar question (here) but it did not help my situation.

This is my page objects code:

class SheetObjects {
    EC = protractor.ExpectedConditions;
    showList = element(by.buttonText('Show as List'));
    copyItem = element.all(by.binding('item.name')).get(2);
    copyDiv = element(by.className('md-inline-list-icon-label'));
    alertItem = element(by.binding('alert'));
    alertDiv = element(by.css('[ng-if="alert"]'))

    NavigateToPage() {
        browser.get('https://material.angularjs.org/latest/#/demo/material.components.bottomSheet');
    }

    WaitForElements(element: any) {
        browser.wait(() => element.isPresent(), 5000);
    }

    ClickOn(element: any) {
        element.click();
    }
}
module.exports = new SheetObjects();

This is my packages.config:

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="angular-protractor.TypeScript.DefinitelyTyped" version="2.1.1" targetFramework="net45" />
  <package id="jasmine.TypeScript.DefinitelyTyped" version="1.3.4" targetFramework="net45" />
  <package id="node.TypeScript.DefinitelyTyped" version="1.5.6" targetFramework="net45" />
  <package id="Protractor" version="0.5.0" targetFramework="net45" />
  <package id="Selenium.WebDriver" version="2.45.0" targetFramework="net45" />
  <package id="selenium-webdriver.TypeScript.DefinitelyTyped" version="0.3.7" targetFramework="net45" />
</packages>

I figured ExpectedConditions would be included in one of those packages but so far nothing has fixed it.

回答1:

I figured ExpectedConditions would be included in one of those packages but so far nothing has fixed it.

its not https://github.com/borisyankov/DefinitelyTyped/search?utf8=%E2%9C%93&q=ExpectedConditions This implies that the definition is a bit out of date with the current actual protractor code : http://angular.github.io/protractor/#/api?view=ExpectedConditions

Hot fix

Just use it in an untyped manner:

EC = (<any>protractor).ExpectedConditions;