简体   繁体   English

检查TestCafe测试中的值

[英]Check for value within test of TestCafe

I use TestCafe to automate testing a specific function. 我使用TestCafe自动测试特定的功能。 In this function, the user is only allowed to have 5 entries. 在此功能中,用户只能拥有5个条目。 On the site is a label that indicates how many entries are left. 该站点上有一个标签,指示剩余的条目数。 When the user already has 5 entries it should delete one in order to test adding a new one. 当用户已有5个条目时,应删除一个条目以测试添加新条目。 The html markup of the page is: 页面的html标记是:

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

Now I want to get exactly this string to make a little if/else with JavaScript to delete an entry when it says 5 / 5 possible entries. 现在我想得到这个字符串,以便在使用JavaScript时删除一个条目,当它显示5/5个可能的条目时。 So far I have this test-code: 到目前为止,我有这个测试代码:

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);

When the test runs, on the output of extractEntries.toString() outputs this: 当测试运行时,在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);
    }

And the next line: 而下一行:

[DEBUG], character: f

I have tried extractEntries.textContent , extractEntries.innerHTML , extractEntries.innerText but I am not able to get the text 5 / 5 possible entries . 我已经尝试过extractEntries.textContentextractEntries.innerHTMLextractEntries.innerText但是我无法获得5 / 5 possible entries

What would be the solution to access the text? 访问文本的解决方案是什么?

TestCafe Selectors provide asynchronous properties to obtain element state values. TestCafe选择器提供异步属性以获取元素状态值。 To get element text, call the textContent property with the await directive: 要获取元素文本,请使用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