检查 TestCafe 测试中的值

Check for value within test of TestCafe

我使用 TestCafe 自动测试特定功能。在此功能中,用户只允许有 5 个条目。该站点上有一个标签,指示剩余的条目数。 当用户已经有 5 个条目时,它应该删除一个以测试添加一个新条目。 页面的 html 标记是:

<p class="pull-left text-muted">5 / 5 possible entries</p>

现在我想准确地得到这个字符串,用 if/else 和 JavaScript 来删除一个条目,当它说有 5 / 5 个可能的条目时。到目前为止,我有这个测试代码:

await t
    .expect(location.pathname).eql(addresspath);

const extractEntries = Selector("p").withText("possible entries");
console.log('[DEBUG], Entries: ' + extractEntries.toString());
var entries = extractEntries.toString().substring(0, 1);
console.log('[DEBUG], character: ' + entries);

当测试运行时,在 extractEntries.toString() 的输出上输出:

[DEBUG], Entries: function __$$clientFunction$$() {
        var testRun = builder.getBoundTestRun() || _testRunTracker2.default.resolveContextTestRun();
        var callsite = (0, _getCallsite.getCallsiteForMethod)(builder.callsiteNames.execution);
        var args = [];

        // OPTIMIZATION: don't leak `arguments` object.
        for (var i = 0; i < arguments.length; i++) {
            args.push(arguments[i]);
        }return builder._executeCommand(args, testRun, callsite);
    }

下一行:

[DEBUG], character: f

我已尝试 extractEntries.textContentextractEntries.innerHTMLextractEntries.innerText,但无法获取文本 5 / 5 possible entries

访问文本的解决方案是什么?

TestCafe 选择器提供异步属性来获取元素状态值。要获取元素文本,请使用 await 指令调用 textContent 属性:

const paragraph      = Selector("p").withText("possible entries");
const extractEntries = await paragraph.textContent;