【问题标题】:Assert empty textbox in testcafe在 testcafe 中断言空文本框
【发布时间】:2020-07-21 12:38:13
【问题描述】:

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

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 可以正常工作。但是检查空值它失败了

【问题讨论】:

  • 你好。你遇到了什么错误? (stackoverflow.com/help/minimal-reproducible-example)
  • 1) 尝试在 Promise 对象上运行断言。你忘了等待吗?如果不是,则将“{allowUnawaitedPromise: true }”传递给断言选项。这就是我所看到的。我试过“{allowUnawaitedPromise: true }”但没有运气

标签: javascript java selenium automation testcafe


【解决方案1】:

试试

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

【讨论】:

    【解决方案2】:

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

    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('');
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-04-29
      • 1970-01-01
      • 2019-12-26
      • 2020-06-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多