I'd like to find a way to debug JavaScript errors reported by testcafe
. It's not a big problem locally where we can just look into browser's console and read errors. It's a bit more complicated in continuous integration environments in headless browsers.
At the moment tests are run:
- locally // always succeed, the problem doesn't exist
- locally in docker // always succeed, the problem doesn't exist
- circleci in docker // sometimes fail
As written above, tests always succeed locally and it doesn't matter whether they are run inside or outside docker. The problem is with tests that are run on circleci and sometimes they fail. They fail because of uncaught JavaScript error and testcafe
reports the error like below:
<failure>
<![CDATA[
1) Uncaught exception:
Error:
Browser: HeadlessChrome 77.0.3865 / Linux 0.0.0
]]>
</failure>
There is no stack trace, no message, no info, no screenshot. It's really hard to debug because it only occurs on circleci environment.
I was trying to use built-in client-side code injection from testcafe
to bind into onerror
/ addEventListener('error')
like in examples here: #1, #2. Unfortunately nothing is reported.
At the moment the logging mechanism on my side look like this
fixture('Profile - remove account')
.page(url('/sign-up'))
.beforeEach(resize)
.afterEach(async t => {
console.log(await t.getBrowserConsoleMessages());
});
test(`should:
▹ Sign up
▹ Visit /profile/account
▹ Remove current account
▹ Visit /login
`, async t => {
log.js
window.addEventListener('error', function (error) {
console.error('Got uncaught error');
console.error(error.message);
try {
console.error(JSON.stringify(error, undefined, 2));
catch (_) {
}
});
CLI
docker-compose run --rm e2e \
"chromium:headless --no-sandbox --disable-dev-shm-usage" \
tests/e2e/src \
--cs=tests/e2e/log.js \
--skip-js-errors \
-S -s /tests/screenshots \
-r xunit:/tests/test-results/testcafe/results.xml
This issue has been already reported several times:
- https://github.com/DevExpress/testcafe/issues/3183
- https://github.com/DevExpress/testcafe/issues/4708
I'm using official testcafe docker image.
Aucun commentaire:
Enregistrer un commentaire