在TestCafe中断言空文本框。

huangapple go评论186阅读模式
英文:

Assert empty textbox in testcafe

问题

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

  1. 页面对象方法
  2. async getTextVal(){
  3. await this.t.selectText(this.editor) //选择文本框
  4. return this.editor.innerText; //获取文本框中的值
  5. }
  6. 测试用例
  7. await t.expect(element.getTextVal()).eql(''); //断言语句

如果存在值,getTextVal 就能正常工作。但是在检查空值时,它会失败。

英文:

I am validating if the text box is empty or not. I am not sure what am I doing wrong here.

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

the getTextVal works fine if there is a value present. But checking empty value it fails

答案1

得分: 0

  1. 尝试
  2. Page Object 方法
  3. async getTextVal(){
  4. await this.t.selectText(this.editor) // 选择文本框
  5. return await this.editor.innerText; // 获取文本框中的值
  6. }
  7. 测试用例
  8. await t.expect(await element.getTextVal()).eql(''); // 断言语句
英文:

try

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

答案2

得分: 0

另外,如果没有方法,只有一个选择器,可以像这样完成:

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

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

  1. import { Selector, t } from "testcafe";
  2. class PageObjectFile {
  3. constructor() {
  4. // 输入字段,可以是许多不同样式的选择器/框架
  5. this.inputField = Selector('.class-input-element');
  6. this.inputFieldTwo = Selector('#id-input-element');
  7. }
  8. }
  9. export default PageObjectFile;

并且您的测试文件如下所示:

  1. import PageObjectFile from "/PageObjectFile";
  2. let pageObjectFile = new PageObjectFile();
  3. fixture `测试输入字段是否为空`
  4. .page(`https://examplepage.com`)
  5. test(`用户看到空的输入字段`, async t => {
  6. await t.expect(pageObjectFile.inputField.innerText).eql('');
  7. });
英文:

Also, without a method just a selector this can be done like so:

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

You can also setup your selector in a page object file:

  1. import { Selector, t } from "testcafe";
  2. class PageObjectFile {
  3. constructor() {
  4. // input field, this could be many different styles of selectors / frameworks
  5. this.inputField = Selector('.class-input-element');
  6. this.inputFieldTwo = Selector('#id-input-element');
  7. }
  8. }
  9. export default PageObjectFile;

And your test file like this:

  1. import PageObjectFile from "/PageObjectFile";
  2. let pageObjectFile = new PageObjectFile();
  3. fixture `Tests input field is empty`
  4. .page(`https://examplepage.com`)
  5. test(`User see's an empty input field`, async t => {
  6. await t.expect(pageObjectFile.inputField.innerText).eql('');
  7. });

huangapple
  • 本文由 发表于 2020年4月9日 08:00:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/61111899.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定