我是Typescript和Protractor的新手。我在不同的类中有可重用的代码。在我的测试类中,而不是单独导入所有库类,我只想仅导入一个将继承我所有可重用代码的类/接口。 当我使用继承我的Protractor类中的类的接口时,在运行时出现以下错误:无法读取未定义的属性'keyText' 这是我的代码段。
export class textInputLibrary {
async keyText(element, text)
{
//my implementation
}
}
export class listItemLibrary{
async selectDropdownValues(element, textToSelect)
{
//my implementation
}
}
//These classes are extended in my interface
export interface library extends checkboxLibrary, elementsLibrary, listItemLibrary, textInputLibrary {
}
//Interface is imported into my Protractor test class:
import {library} from "../library/library";
describe('angularjs homepage', async function() {
it('should greet the named user', async function() {
await browser.get('http://www.angularjs.org');
let yourName: ElementFinder = await element(by.model('yourName'));
let library: library;
await library.keyText(yourName,"Test123");
});
});
答案 0 :(得分:0)
在TypeScript中,似乎接口的限制如下所示: “ ICustomer接口有很大的限制-您只能将其与扩展了与扩展接口相同的类的类(在这种情况下,这是Customer类)一起使用。”
因此,要使用我的界面,我还需要扩展Test中的类。但是,我只能延长一堂课。在我的界面扩展多个类的地方。