How to get full stack trace in Test Cafe errors
I have been using Test Cafe to write an internal test framework where actions (t.click) and assertions (t.expect) are not directly written inside the spec, but are defined and aggregated in other files.
Everything cool until a test does not fail: in this case the Test Cafe reporter writes in console the assertion/action failed and the relative snippet of code, but I did not find the way to understand the full stack trace of function calls from my test down to the failed assertions.
How can I make sure to provide a full stack trace in the reporter, logging a stack trace with all the calls to function that made my test fail?
I understood that the reason should be linked to how async/await is transpiled into generators: the stack trace of the error shows only the last await executed and not all the previous calls.
<section> ... </section>
<section class="section--modifier">
<h1> ... </h1>
<div>
...
<button class="section__button">
<div class="button__label">
<span class="label__text">Hello!</span> <-- Target of my test
</div>
</button>
...
</div>
</section>
<section> ... </section>
//
// My spec file
//
import { Selector } from 'testcafe';
import {
verifyButtonColor
} from './button';
fixture`My Fixture`
.page`....`;
test('Test my section', async (t) => {
const MySection = Selector('.section--modifier');
const MyButton1 = MySection.find('.section__button');
const MySection2 = Selector('.section--modifier2');
const MyButton2 = MySection2.find('.section__button');
....
await verifyButtonColor(t, MyButton1, 'green'); // it will fail!
....
....
....
await verifyButtonColor(t, MyButton2, 'green');
});
//
// Definition of assertion verifyButtonColor (button.js)
//
import { Selector } from 'testcafe';
import {
verifyLabelColor
} from './label';
export async function verifyButtonColor(t, node, expectedColor) {
const MyLabel = node.find('.button__label');
await verifyLabelColor(t, MyLabel, expectedColor);
}
//
// Definition of assertion verifyLabelColor (label.js)
//
export async function verifyLabelColor(t, node, expectedColor) {
const MyText= node.find('.label__text');
const color = await MyText.getStyleProperty('color');
await t.expect(color).eql(expectedColor, `Color should be ${expectedColor}, found ${color}`); // <-- it will FAIL!
}
What I get not in the reporter is that my test failed because the assertion defined in "verifyLabelColor" failed (the color is not green :(),
...
await t.expect(color).eql(expectedColor, `Color should be ${expectedColor}, found ${color}`);
...
but in the reporter I have no evidence that failed due to the following stack of calls
- await verifyButtonColor(t, MyButton1, 'green');
- await verifyLabelColor(t, MyLabel, expectedColor);
- await t.expect(color).eql(expectedColor, `Color should be ${expectedColor}, found ${color}`);
Any body faced a similar problem?
An alternative could be to log the "path" of the selector that caused the failure, but looking to Test Cafe documentation I did not find the possibility to do it: knowing that the assertion failed on element with the path below could at least help to understand what went wrong
.section--modifier .section__button .button__label .label__text
exception automated-tests stack-trace e2e-testing testcafe
add a comment |
I have been using Test Cafe to write an internal test framework where actions (t.click) and assertions (t.expect) are not directly written inside the spec, but are defined and aggregated in other files.
Everything cool until a test does not fail: in this case the Test Cafe reporter writes in console the assertion/action failed and the relative snippet of code, but I did not find the way to understand the full stack trace of function calls from my test down to the failed assertions.
How can I make sure to provide a full stack trace in the reporter, logging a stack trace with all the calls to function that made my test fail?
I understood that the reason should be linked to how async/await is transpiled into generators: the stack trace of the error shows only the last await executed and not all the previous calls.
<section> ... </section>
<section class="section--modifier">
<h1> ... </h1>
<div>
...
<button class="section__button">
<div class="button__label">
<span class="label__text">Hello!</span> <-- Target of my test
</div>
</button>
...
</div>
</section>
<section> ... </section>
//
// My spec file
//
import { Selector } from 'testcafe';
import {
verifyButtonColor
} from './button';
fixture`My Fixture`
.page`....`;
test('Test my section', async (t) => {
const MySection = Selector('.section--modifier');
const MyButton1 = MySection.find('.section__button');
const MySection2 = Selector('.section--modifier2');
const MyButton2 = MySection2.find('.section__button');
....
await verifyButtonColor(t, MyButton1, 'green'); // it will fail!
....
....
....
await verifyButtonColor(t, MyButton2, 'green');
});
//
// Definition of assertion verifyButtonColor (button.js)
//
import { Selector } from 'testcafe';
import {
verifyLabelColor
} from './label';
export async function verifyButtonColor(t, node, expectedColor) {
const MyLabel = node.find('.button__label');
await verifyLabelColor(t, MyLabel, expectedColor);
}
//
// Definition of assertion verifyLabelColor (label.js)
//
export async function verifyLabelColor(t, node, expectedColor) {
const MyText= node.find('.label__text');
const color = await MyText.getStyleProperty('color');
await t.expect(color).eql(expectedColor, `Color should be ${expectedColor}, found ${color}`); // <-- it will FAIL!
}
What I get not in the reporter is that my test failed because the assertion defined in "verifyLabelColor" failed (the color is not green :(),
...
await t.expect(color).eql(expectedColor, `Color should be ${expectedColor}, found ${color}`);
...
but in the reporter I have no evidence that failed due to the following stack of calls
- await verifyButtonColor(t, MyButton1, 'green');
- await verifyLabelColor(t, MyLabel, expectedColor);
- await t.expect(color).eql(expectedColor, `Color should be ${expectedColor}, found ${color}`);
Any body faced a similar problem?
An alternative could be to log the "path" of the selector that caused the failure, but looking to Test Cafe documentation I did not find the possibility to do it: knowing that the assertion failed on element with the path below could at least help to understand what went wrong
.section--modifier .section__button .button__label .label__text
exception automated-tests stack-trace e2e-testing testcafe
add a comment |
I have been using Test Cafe to write an internal test framework where actions (t.click) and assertions (t.expect) are not directly written inside the spec, but are defined and aggregated in other files.
Everything cool until a test does not fail: in this case the Test Cafe reporter writes in console the assertion/action failed and the relative snippet of code, but I did not find the way to understand the full stack trace of function calls from my test down to the failed assertions.
How can I make sure to provide a full stack trace in the reporter, logging a stack trace with all the calls to function that made my test fail?
I understood that the reason should be linked to how async/await is transpiled into generators: the stack trace of the error shows only the last await executed and not all the previous calls.
<section> ... </section>
<section class="section--modifier">
<h1> ... </h1>
<div>
...
<button class="section__button">
<div class="button__label">
<span class="label__text">Hello!</span> <-- Target of my test
</div>
</button>
...
</div>
</section>
<section> ... </section>
//
// My spec file
//
import { Selector } from 'testcafe';
import {
verifyButtonColor
} from './button';
fixture`My Fixture`
.page`....`;
test('Test my section', async (t) => {
const MySection = Selector('.section--modifier');
const MyButton1 = MySection.find('.section__button');
const MySection2 = Selector('.section--modifier2');
const MyButton2 = MySection2.find('.section__button');
....
await verifyButtonColor(t, MyButton1, 'green'); // it will fail!
....
....
....
await verifyButtonColor(t, MyButton2, 'green');
});
//
// Definition of assertion verifyButtonColor (button.js)
//
import { Selector } from 'testcafe';
import {
verifyLabelColor
} from './label';
export async function verifyButtonColor(t, node, expectedColor) {
const MyLabel = node.find('.button__label');
await verifyLabelColor(t, MyLabel, expectedColor);
}
//
// Definition of assertion verifyLabelColor (label.js)
//
export async function verifyLabelColor(t, node, expectedColor) {
const MyText= node.find('.label__text');
const color = await MyText.getStyleProperty('color');
await t.expect(color).eql(expectedColor, `Color should be ${expectedColor}, found ${color}`); // <-- it will FAIL!
}
What I get not in the reporter is that my test failed because the assertion defined in "verifyLabelColor" failed (the color is not green :(),
...
await t.expect(color).eql(expectedColor, `Color should be ${expectedColor}, found ${color}`);
...
but in the reporter I have no evidence that failed due to the following stack of calls
- await verifyButtonColor(t, MyButton1, 'green');
- await verifyLabelColor(t, MyLabel, expectedColor);
- await t.expect(color).eql(expectedColor, `Color should be ${expectedColor}, found ${color}`);
Any body faced a similar problem?
An alternative could be to log the "path" of the selector that caused the failure, but looking to Test Cafe documentation I did not find the possibility to do it: knowing that the assertion failed on element with the path below could at least help to understand what went wrong
.section--modifier .section__button .button__label .label__text
exception automated-tests stack-trace e2e-testing testcafe
I have been using Test Cafe to write an internal test framework where actions (t.click) and assertions (t.expect) are not directly written inside the spec, but are defined and aggregated in other files.
Everything cool until a test does not fail: in this case the Test Cafe reporter writes in console the assertion/action failed and the relative snippet of code, but I did not find the way to understand the full stack trace of function calls from my test down to the failed assertions.
How can I make sure to provide a full stack trace in the reporter, logging a stack trace with all the calls to function that made my test fail?
I understood that the reason should be linked to how async/await is transpiled into generators: the stack trace of the error shows only the last await executed and not all the previous calls.
<section> ... </section>
<section class="section--modifier">
<h1> ... </h1>
<div>
...
<button class="section__button">
<div class="button__label">
<span class="label__text">Hello!</span> <-- Target of my test
</div>
</button>
...
</div>
</section>
<section> ... </section>
//
// My spec file
//
import { Selector } from 'testcafe';
import {
verifyButtonColor
} from './button';
fixture`My Fixture`
.page`....`;
test('Test my section', async (t) => {
const MySection = Selector('.section--modifier');
const MyButton1 = MySection.find('.section__button');
const MySection2 = Selector('.section--modifier2');
const MyButton2 = MySection2.find('.section__button');
....
await verifyButtonColor(t, MyButton1, 'green'); // it will fail!
....
....
....
await verifyButtonColor(t, MyButton2, 'green');
});
//
// Definition of assertion verifyButtonColor (button.js)
//
import { Selector } from 'testcafe';
import {
verifyLabelColor
} from './label';
export async function verifyButtonColor(t, node, expectedColor) {
const MyLabel = node.find('.button__label');
await verifyLabelColor(t, MyLabel, expectedColor);
}
//
// Definition of assertion verifyLabelColor (label.js)
//
export async function verifyLabelColor(t, node, expectedColor) {
const MyText= node.find('.label__text');
const color = await MyText.getStyleProperty('color');
await t.expect(color).eql(expectedColor, `Color should be ${expectedColor}, found ${color}`); // <-- it will FAIL!
}
What I get not in the reporter is that my test failed because the assertion defined in "verifyLabelColor" failed (the color is not green :(),
...
await t.expect(color).eql(expectedColor, `Color should be ${expectedColor}, found ${color}`);
...
but in the reporter I have no evidence that failed due to the following stack of calls
- await verifyButtonColor(t, MyButton1, 'green');
- await verifyLabelColor(t, MyLabel, expectedColor);
- await t.expect(color).eql(expectedColor, `Color should be ${expectedColor}, found ${color}`);
Any body faced a similar problem?
An alternative could be to log the "path" of the selector that caused the failure, but looking to Test Cafe documentation I did not find the possibility to do it: knowing that the assertion failed on element with the path below could at least help to understand what went wrong
.section--modifier .section__button .button__label .label__text
exception automated-tests stack-trace e2e-testing testcafe
exception automated-tests stack-trace e2e-testing testcafe
edited Jan 18 at 16:15
Alex Skorkin
2,13711633
2,13711633
asked Jan 17 at 15:52
user2000631user2000631
212
212
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
This subject is related to TestCafe proposal : Have a multiple stacktrace reporter for fast analysis when a test fails
In the meantime you could give a try to this reporter: /testcafe-reporter-cucumber-json or maybe you could develop your own reporter
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54239586%2fhow-to-get-full-stack-trace-in-test-cafe-errors%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
This subject is related to TestCafe proposal : Have a multiple stacktrace reporter for fast analysis when a test fails
In the meantime you could give a try to this reporter: /testcafe-reporter-cucumber-json or maybe you could develop your own reporter
add a comment |
This subject is related to TestCafe proposal : Have a multiple stacktrace reporter for fast analysis when a test fails
In the meantime you could give a try to this reporter: /testcafe-reporter-cucumber-json or maybe you could develop your own reporter
add a comment |
This subject is related to TestCafe proposal : Have a multiple stacktrace reporter for fast analysis when a test fails
In the meantime you could give a try to this reporter: /testcafe-reporter-cucumber-json or maybe you could develop your own reporter
This subject is related to TestCafe proposal : Have a multiple stacktrace reporter for fast analysis when a test fails
In the meantime you could give a try to this reporter: /testcafe-reporter-cucumber-json or maybe you could develop your own reporter
answered Jan 18 at 12:22
hdorgevalhdorgeval
5264
5264
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54239586%2fhow-to-get-full-stack-trace-in-test-cafe-errors%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown