在 testcafe 中断言空文本框

Assert empty textbox in testcafe

我正在验证文本框是否为空。我不确定我在这里做错了什么。

Page Object method
async getTextVal(){
  await this.t.selectText(this.editor) //selecting the text box
  return this.editor.innerText; //fetching the value in the textbox      
}
TestCase
await t.expect(element.getTextVal()).eql(''); //assert statement

如果存在值,getTextVal 工作正常。但是检查空值失败

尝试

Page Object method
async getTextVal(){
  await this.t.selectText(this.editor) //selecting the text box
  return await this.editor.innerText; //fetching the value in the textbox      
}
TestCase
await t.expect(await element.getTextVal()).eql(''); //assert statement

此外,如果没有方法,只有一个选择器,可以这样做:

await t.expect(selector.innerText).eql('');

您还可以在页面对象文件中设置选择器:

import { Selector, t } from "testcafe";

class PageObjectFile {
    constructor() {
        // input field, this could be many different styles of selectors / frameworks
        this.inputField = Selector('.class-input-element');
        this.inputFieldTwo = Selector('#id-input-element');
    }
}

export default PageObjectFile;

你的测试文件是这样的:

import PageObjectFile from "/PageObjectFile";

let pageObjectFile = new PageObjectFile();

fixture `Tests input field is empty`
    .page(`https://examplepage.com`)


test(`User see's an empty input field`, async t => {
     await t.expect(pageObjectFile.inputField.innerText).eql('');
});