如何使用打字稿在量角器和黄瓜中传递动态xpath
how to pass dynamic xpath in protractor and cucumber using typescript
我想在我的 xpath 中动态传递一个参数。对于页面对象,我创建了一个 class 并在我的步骤定义中调用它。请看下面
下面是我的代码和错误信息
//this is my page object
export class accountPage{
accountNo: string;
public accountNumberLabel = element(by.xpath('//span[text()=" '+this.accountNo+' "]'))
async getAccountNumberLabel(): Promise<string>{
return await Promise.resolve(this.accountNumberLabel.getText());
}
}
//and this is my step definition
const accountpage = new new accountPage();
Then('I assert the row {string} for {string}',async(account_number, account_value)=>{
accountpage.accountNo = account_number;
await browser.sleep(2000);
if(searchKey.includes("account_number")){
assert.equal(await accountpage.getAccountNumberLabel(),account_value);
}
});```
//I am receiving an error
NoSuchElementError: No element found using locator: By(xpath, //span[text()=" undefined "])
when I read the value console.log(accountpage.accountNo) it is returning correct value
问题 1:
`this.accountNo` is undefined.
第 2 期:
使用模板文字连接字符串。
element(by.xpath(`//span[text()='${this.accountNo}']`))
检查控制台中是否有两个空格。我的意思是未定义之前和之后
NoSuchElementError: No element found using locator: By(xpath, //span[text()=" undefined "]
我想在我的 xpath 中动态传递一个参数。对于页面对象,我创建了一个 class 并在我的步骤定义中调用它。请看下面
下面是我的代码和错误信息
//this is my page object
export class accountPage{
accountNo: string;
public accountNumberLabel = element(by.xpath('//span[text()=" '+this.accountNo+' "]'))
async getAccountNumberLabel(): Promise<string>{
return await Promise.resolve(this.accountNumberLabel.getText());
}
}
//and this is my step definition
const accountpage = new new accountPage();
Then('I assert the row {string} for {string}',async(account_number, account_value)=>{
accountpage.accountNo = account_number;
await browser.sleep(2000);
if(searchKey.includes("account_number")){
assert.equal(await accountpage.getAccountNumberLabel(),account_value);
}
});```
//I am receiving an error
NoSuchElementError: No element found using locator: By(xpath, //span[text()=" undefined "])
when I read the value console.log(accountpage.accountNo) it is returning correct value
问题 1:
`this.accountNo` is undefined.
第 2 期:
使用模板文字连接字符串。
element(by.xpath(`//span[text()='${this.accountNo}']`))
检查控制台中是否有两个空格。我的意思是未定义之前和之后
NoSuchElementError: No element found using locator: By(xpath, //span[text()=" undefined "]