javascript - Testcafe过滤功能

标签 javascript testing automated-tests e2e-testing testcafe

我有一个 Selector 的过滤器函数,如下所示,它接受两个参数 { subject: subject, from: from } 作为依赖对象。

但是运行这个函数后,我得到一个错误

ReferenceError: subject is not defined

async function getMessage(subject, from) {
  return await Selector('[data-test=messageListItem]').filter(( message ) => {
    return message.querySelector('[data-test=subject]').textContent.includes(subject) &&
      message.querySelector('[data-test=email]').textContent.includes(from);
  }, { dependencies: { subject: subject,  from: from } });
}

TestCafe 团队可以帮我解决这个问题吗?

最佳答案

In the case of the .filter method你需要重写你的 dependencies 参数 ({ dependencies: { subject: subject, from: from } } ) 如下:

{ subject: subject,  from: from }

我准备了一个示例测试来说明它:

import { Selector } from 'testcafe';

fixture `New Fixture`
    .page `google.com`;

test('New Test', async t => {
    await t
        .click(Selector('#tsf').find('[name="q"]'))
        .typeText(Selector('#tsf').find('[name="q"]'), 'testcafe')
        .pressKey('enter');

    await t.expect(Selector('.LC20lb').count).eql(10);


    function fn (title) {
        return Selector('.LC20lb').filter((node, idx) => {
            return node.textContent.includes(title);
        }, { title }); // dependencies parameter
    }

    await t.expect(fn('TestCafe').count).gt(1);
});

关于javascript - Testcafe过滤功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57627053/

相关文章:

javascript - 仅单击标题而不单击其指定的子项

testing - 删除QC中生成的脚本

具有许多 phantomjs 并发实例的 Selenium 网格节点

java - Gradle 忽略 testng 中的优先级

selenium - WebdriverIO - 截取整页截图

Javascript 弹出窗口 - 需要创建类并将事件绑定(bind)到 document.getElementsByClassName 返回的每个元素

javascript - 如何获得文字中的金额?

grails - "Could not find ApplicationContext, configure Grails correctly first"

database - 测试运行时 Django 测试数据库看起来是空的

c# - 如何使用 jquery 或仅使用表单例份验证的 javascript 注销?