问题
I use TestCafe to automate testing a specific function. 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>
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. 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:
[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
.
What would be the solution to access the text?
回答1:
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;
来源:https://stackoverflow.com/questions/47770606/check-for-value-within-test-of-testcafe