我使用 TestCafe 来自动测试特定功能。在此功能中,用户只允许有 5 个条目。网站上有一个标签,指示剩余的条目数。当用户已经有 5 个条目时,它应该删除一个以测试添加一个新条目。页面的html标记为:
<p class="pull-left text-muted">5 / 5 possible entries</p>
现在我想准确地得到这个字符串,以便在它说 5 / 5 个可能的条目时使用 JavaScript 进行一点 if/else 来删除一个条目。到目前为止,我有这个测试代码:
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.textContent
,extractEntries.innerHTML
但extractEntries.innerText
我无法得到文本5 / 5 possible entries
。
访问文本的解决方案是什么?