繁体   English   中英

检查TestCafe测试中的值

[英]Check for value within test of TestCafe

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

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

现在我想得到这个字符串,以便在使用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;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM