检查TestCafe测试中的值 [英] Check for value within test of TestCafe

查看:357
本文介绍了检查TestCafe测试中的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I use TestCafe to automate testing a specific funtion. In this function the user is only allowed to have 5 entries. 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. The html markup of the page is:

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

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

Now i want to get exact this string to make a little if/else with JavaScript to delete an entry when it say 5 / 5 possible entries. 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);

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

When the test runs, on the output of extractEntries.toString() outputs this:

[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

I尝试 extractEntries.textContent extractEntries.innerHTML extractEntries.innerText 但我无法获得 5/5可能的条目

I have tried extractEntries.textContent, extractEntries.innerHTML, extractEntries.innerText but I am not able to get the text 5 / 5 possible entries.

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

What would be the solution to access the text?

推荐答案

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

TestCafe Selectors provide asynchronous properties to obtain element state values. To get element text, call the textContent property with the await directive:

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

这篇关于检查TestCafe测试中的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆