如何在 TypeScript 中反映量角器(WebDriver)操作的链接(ControlFlow) [英] How to reflect chaining (ControlFlow) of Protractor (WebDriver) actions in TypeScript
问题描述
在量角器测试中,可以像这样在元素上链接clear"和sendKeys"等操作:
In a protractor test it is possible to chain actions like "clear" and "sendKeys" on an Element like this:
element(by.id('myId')).clear().sendKeys('123456789')
我喜欢它紧凑的风格.但它为什么有效?
I like the compact style of it. But why does it work?
根据webdriver.Element.clear() clear() 的返回类型是 webdriver.promise.Promise.
According to the API Docs of webdriver.Element.clear() the return type of clear() is webdriver.promise.Promise.<void>
当我使用 TypeScript (1.8.x) 编译它时,编译器抱怨 Promise
上没有名为 sendKeys()
的属性.我认为事实确实如此.
When i compile it with TypeScript (1.8.x), the compiler complains that there is no property called sendKeys()
on Promise
. And I think that's actually the case.
我相信这在运行时有效,因为 WebDriver ControlFlow Magic.
I believe this works at runtime due to the WebDriver ControlFlow Magic.
我如何扩展 TypeScript 声明文件 的量角器,反映这个 ControlFlow-Magic 并让我的 TypeScript 编译器满意?
How can i extend the TypeScript Declaration File of Protractor, to reflect this ControlFlow-Magic and make my TypeScript compiler happy?
推荐答案
我们最终像这样将函数添加到命名空间
we ended up adding the function to the namespace like this
declare namespace webdriver.promise {
interface Promise<T> {
sendKeys(s: String);
}
}
这篇关于如何在 TypeScript 中反映量角器(WebDriver)操作的链接(ControlFlow)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!