Skip to content

Commit

Permalink
Handle 0px tall elements with a better error message
Browse files Browse the repository at this point in the history
  • Loading branch information
sebinsua authored and NMinhNguyen committed Sep 25, 2019
1 parent 86adf42 commit 9459baf
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/driver/src/cy/commands/screenshot.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ scrollOverrides = (win, doc) ->
win.scrollTo(originalX, originalY)

takeScrollingScreenshots = (scrolls, win, state, automationOptions) ->
if scrolls.length is 0
return Promise.reject(
new Error("It was not possible to take a screenshot, since the number of scrolls calculated to do so was zero.")
)

scrollAndTake = ({ y, clip, afterScroll }, index) ->
win.scrollTo(0, y)
if afterScroll
Expand Down
7 changes: 7 additions & 0 deletions packages/driver/test/cypress/fixtures/screenshots.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
border: solid 1px black;
margin: 20px;
}
.empty-element {
height: 0px;
width: 0px;
border: 0px;
margin: 0px;
}
.short-element {
height: 100px;
margin-left: 40px;
Expand All @@ -28,6 +34,7 @@
</style>
</head>
<body>
<div class="empty-element"></div>
<div class="short-element"></div>
<div class="tall-element"></div>
<div class="multiple"></div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,11 @@ describe "src/cy/commands/screenshot", ->
@assertErrorMessage("cy.screenshot() 'blackout' option must be an array of strings. You passed: true", done)
cy.screenshot({ blackout: [true] })

it "throws if there is a 0px tall element height", (done) ->
@assertErrorMessage("It was not possible to take a screenshot, since the number of scrolls calculated to do so was zero.", done)
cy.visit("/fixtures/screenshots.html")
cy.get('.empty-element').screenshot()

it "throws if clip is not an object", (done) ->
@assertErrorMessage("cy.screenshot() 'clip' option must be an object of with the keys { width, height, x, y } and number values. You passed: true", done)
cy.screenshot({ clip: true })
Expand Down

0 comments on commit 9459baf

Please sign in to comment.