Skip to content

unhelpful error message when taking screenshot of element with zero height #5149

@egrubbs

Description

@egrubbs

Current behavior:

cy.get(element).screenshot() displays a very confusing error if the element has zero height.

TypeError: Cannot destructure property `duration` of 'undefined' or 'null'.

image

The code that is causing the confusing error

numScreenshots ends up being zero when elPosition.height is zero.

numScreenshots = Math.ceil(elPosition.height / viewportHeight)

This causes _.last(results) to return undefined.

Which causes takeScreenshot().then() to receive an undefined props parameter that it cannot destructure with { duration, path, size } = props;.

{ duration, path, size } = props

Desired behavior:

cy.get(element).screenshot() should report an error that the element has zero height.

It is also extremely difficult to troubleshoot an error like this because bluebirdjs doesn't automatically log exceptions, so I have no idea where the code in the error message existed.

It appears that bluebirdjs has events for unhandled errors. It would be great if Cypress provided a filename and line number of the where the error is occurring in the Cypress log as well as a stack trace in the browser console.

http://bluebirdjs.com/docs/api/error-management-configuration.html

process.on("unhandledRejection", function(reason, promise) {
});
process.on("rejectionHandled", function(promise) {
});

Steps to reproduce: (app code and test code)

You can recreate the confusing error message by trying to take a screenshot of a span with zero height.

cy.get('.zero_height_element').screenshot();

Versions

Cypress 3.4.1
Ubuntu 16.04 & 18.04

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions