selenium webdriver - Typescript'te Protractor/WebDriverJS ControlFlow'a yerleşik ES6 Promise ekle


Şu anda Protractor testlerimde ES6 Promises döndüren bazı harici kodları çağırıyorum.

Bu sözleri bir ControlFlow kullanarak zincirlemeyi umuyordum, ama Typescript derlendiğinde bir tip hatası alıyorum.

Testte:

import {browser} from 'protractor';
...
it('should have a title', () => {
  let flow = browser.controlFlow();
  flow.execute(testServer.fixture('user_test_roles'));
});

Çalıştırıldığında:

[13:04:39] E/launcher - Error: ⨯ Unable to compile TypeScript
src/app/app.e2e.ts (9,18): Argument of type 'Promise<{}>' is not assignable to parameter of type '() => {} | Promise<{}>'.
  Type 'Promise<{}>' provides no match for the signature '(): {} | Promise<{}>' (2345)

Eğer flow.wait() denersen farklı bir tür hatası alıyorum:

[13:08:27] E/launcher - Error: ⨯ Unable to compile TypeScript
src/app/app.e2e.ts (9,15): Argument of type 'Promise<{}>' is not assignable to parameter of type 'Function | Promise<{}>'.
  Type 'Promise<{}>' is not assignable to type 'webdriver.promise.Promise<{}>'.
    Property 'cancel' is missing in type 'Promise<{}>'. (2345)

Sözleşmeleri uyumlu hale getirmek için onları sarmanın bir yolu var mı?

Cevap #1

Kontrol akışı, selenium-webdriver tarafından sağlanan bir ManagedPromise'i arıyor. Eğer testServer.fixture yerel bir ES6 promise döndürüyorsa bu çalışmaz. Yerel ES6 promise'ler aynı webdriver.promise.Promise değildir.