簡體   English   中英

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

您還可以在頁面 object 文件中設置您的選擇器:

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

我正在驗證文本框是否為空。 我不確定我在這里做錯了什么。

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 可以正常工作。 但檢查空值失敗

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM