Bug?
Trying to get the innerHTLM and pass it as a message to notOk
const el1 = await Selector('#errorArea');
const errorMessage = ClientFunction(() => document.getElementById('errorMessage').innerHTML);
await t.expect(el1.visible).notOk('Error visible: ' + errorMessage);
The printout is the following:
1) AssertionError: Error visible: function __$$clientFunction$$() {
var testRun = builder.getBoundTestRun() ||
_testRunTracker2.default.resolveContextTestRun();
var callsite = (0,
_getCallsite.getCallsiteForMethod)(builder.callsiteNames.execution);
var args = [];
...
I have also tried to do
const errorMessage = el1.filter('#errorMessage').innerHTML;
I hoped to get the content/text of the following HTML
<div id="errorArea" class="">
<span id="errorMessage">We couldn't draw some things because ...</span>
</div>
So in this case I was hoping to get We couldn't draw some things ... text to print it in the debug console.
Use HTML and the above test code.
Hi @jesperalmstrom, result of ClientFunction is an async function, you can call it and await the result:
const el1 = Selector('#errorArea');
const getErrorMessage = ClientFunction(() => document.getElementById('errorMessage').innerHTML);
const errorMessage = await getErrorMessage();
await t.expect(el1.visible).notOk('Error visible: ' + errorMessage);
or use t.eval instead of ClientFunction:
const el1 = Selector('#errorArea');
const errorMessage = await t.eval(() => document.getElementById('errorMessage').innerHTML);
await t.expect(el1.visible).notOk('Error visible: ' + errorMessage);
Thanks for super fast answer. I will try.
Is there a way to get this directly from the el1 Selector ?
You can pass Selectors into t.eval or ClientFunction as a dependencies:
const el = Selector('#errorMessage');
const getErrorMessage = ClientFunction(() => el().innerHTML, { dependencies: { el } });
const errorMessage = await getErrorMessage();
await t.expect(el1.visible).notOk('Error visible: ' + errorMessage);
const el = Selector('#errorMessage');
const errorMessage = await t.eval(() => el().innerHTML, { dependencies: { el } });
await t.expect(el1.visible).notOk('Error visible: ' + errorMessage);
Also please note that there is no await in el = Selector(..., in the previous case too
This thread has been automatically locked since it is closed and there has not been any recent activity. Please open a new issue for related bugs or feature requests. We recommend you ask TestCafe API, usage and configuration inquiries on StackOverflow.