【发布时间】:2018-02-16 19:28:27
【问题描述】:
有没有办法从属性装饰器向属性对象添加一个函数。我试图这样做,但无法在装饰器中获取属性对象的引用。 我正在使用 Intern js 版本 4 进行 UI 自动化项目。我已经实现了页面对象模型来做到这一点。我在这里想要实现的是
- 将包含验证消息的 div 的 xpath 传递给页面对象 通过属性装饰器的文本框。
- 从属性装饰器内部,在文本框的页面对象中添加一个函数到 从该 div 中获取可见文本。
这是我迄今为止尝试过的:
ClientPage.ts
export class ClientPage extends AbstractSearchPage implements LandingPage {
@Validate({xpath: '//sumit/shrestha'})
public clientId: TextBox;
constructor(remote: any) {
super(remote)
this.clientId = new TextBox(remote,'//*[@id="clientId"]')
this.dataGrid = new DataGrid(remote, '//table[@id="Table"]')
this.searchBtn = '//*[@id="search"]';
}
getPageUrl(): string {
return '#/clients/clients'
};
}
文本框.ts
export class TextBox extends InputElement {
constructor(remote: any, locator: any) {
super(remote, locator);
}
async enterValue(input: string) {
await this.remote.findByXpath(this.locator).clearValue().type(input);
}
async clearValue() {
await this.remote.findByXpath(this.locator).clearValue()
// return Promise.resolve(this);
}
}
验证.ts
export function Validate(config: any) {
var remote = getRemote();
return function (target: Object, property: string | symbol) {
/*
// I thought target is reference to Textbox object but it refers to
// ClientPage object and even clientpage object here (target) shows only
// functions when doing console.log(target)
*/
console.log(config.xpath)
target.prototype.requiredFieldValidation = async function (): Promise<string> {
await target.enterValue('ddd')
await target.clearValue('ddd')
return await remote.findByXpath(config.xpath).getVisibleText();
}
}
}
【问题讨论】:
标签: javascript typescript intern