Skip to content
This repository has been archived by the owner on Mar 3, 2020. It is now read-only.

resize_window has no effect on save_screenshot #354

Closed
Sephi-Chan opened this issue Jun 29, 2012 · 17 comments
Closed

resize_window has no effect on save_screenshot #354

Sephi-Chan opened this issue Jun 29, 2012 · 17 comments

Comments

@Sephi-Chan
Copy link

Hi,

I'm testing an app using modals (via Twitter Bootstrap) but I can't see al the modal on the page since the page height is too low. The resize_window method has no effect on the height.

Example: http://img29.imageshack.us/img29/6224/suggestedfixes.png

How can I change the size of the windows?

Thanks.

@jferris
Copy link
Contributor

jferris commented Jun 29, 2012

The resize_window method is how you're supposed to fix issues like this. Are you resizing the window before or after you load that page? Can you paste some of the code from this test?

@Sephi-Chan
Copy link
Author

Here is the example code. The only code executed before is to create some records.
I tried many places to resize the window but no one works.

it "should display only the automobile brands" do
  page.driver.resize_window 1200, 1200

  visit '/data_sheets'
  find('a[data-type=automobile]').click
  page.driver.resize_window 1200, 1200

  page.should have_content(automobile_brand.label_fr)
  page.should have_content(other_automobile_brand.label_fr)
  page.should_not have_content(motorcycle_brand.label_fr)

  page.driver.resize_window 1200, 1200
  page.driver.render 'tmp/screenshots/list-of-brands.png'
end

The screenshot size remains 1000 * 273.

@jferris
Copy link
Contributor

jferris commented Jul 3, 2012

Your code looks fine to me. Maybe there's an issue where the browser refuses to set a height larger than what it thinks the page height is. I'll take a look when I can.

On Monday, July 2, 2012 at 7:22 AM, Romain Tribes wrote:

Here is the example code. The only code executed before is to create some records.
I tried many places to resize the window but no one works.

it "should display only the automobile brands" do
page.driver.resize_window 1200, 1200

visit '/data_sheets'
find('a[data-type=automobile]').click
page.driver.resize_window 1200, 1200

page.should have_content(automobile_brand.label_fr)
page.should have_content(other_automobile_brand.label_fr)
page.should_not have_content(motorcycle_brand.label_fr)

page.driver.resize_window 1200, 1200
page.driver.render 'tmp/screenshots/list-of-brands.png'
end

The screenshot size remains 1000 * 273.


Reply to this email directly or view it on GitHub:
#354 (comment)

@Sephi-Chan
Copy link
Author

Thanks @jferris. :)

@kevinmpowell
Copy link

Any update on this? I'm having the same exact issue. Trying to test an infinite scrolling UI, but the browser height is too tall at the start of my test.

@jferris
Copy link
Contributor

jferris commented Oct 16, 2012

@swiego I haven't gotten to look into this yet. I'm still working on Qt 4.8 issues, then load issues, and then I'll start going through bugs like this.

@betelgeuse
Copy link
Contributor

I tested both smaller and larger sizes. Regardless of what I give to resize_window the saved screenshots look the same.

@nextmat
Copy link

nextmat commented May 20, 2013

Any update on this?

@jjb
Copy link

jjb commented Jun 14, 2014

I'm experiencing the same problem. I've tried page.driver.browser.resize_window(3000,3000) and
page.driver.resize_window(3000, 3000), neither seem to actually resize the window.

also, the values returned by page.driver.evaluate_script("window.innerWidth") and page.driver.evaluate_script("window.innerHeight") seem to not reflect reality.

@mhoran
Copy link
Collaborator

mhoran commented Jul 1, 2014

The screenshot code uses the passed-in resolution (or default of 1000x10) as the viewport size, and then enlarges the image to the current frame's contentSize. I'm not sure why window.inner{Width,Height} is not reporting the expected resolution, but the screenshot code explains why the image is always the same size. ResizeWindow does pass the provided resolution directly to the WebPage, which I would expect to be reflected in JavaScript.

@jjb
Copy link

jjb commented Jul 1, 2014

@mhoran could you show some example code that should successfully resize a window?

@mhoran
Copy link
Collaborator

mhoran commented Jul 1, 2014

Check out https://github.com/thoughtbot/capybara-webkit/blob/master/spec/driver_resize_window_spec.rb. We test resize using innerWidth and height without issue. I'm not sure why this isn't working for you.

@jferris
Copy link
Contributor

jferris commented Jul 2, 2014

Looking through the current code, it seems like we:

  • Resize the viewport to the minimum size.
  • Check to see what the actual size of the main frame is.
  • Create a buffer for the size of the main frame.
  • Resize again to the size of the mainframe.
  • Render the screenshot.

I'm not sure if resizing the viewport could have an affect on the size of the contents. If there's JavaScript or responsive CSS, I could see resizing the window having an effect. I'm also not sure what the most likely expectation is: a screenshot of the current viewport, or a screenshot of the entire page based on the viewport width.

It's possible that the minimum size code predates the resize_window code. I'm not sure we still need to specify a size when saving screenshots. We could at least rely on the browser width instead.

@jjb could you open a new issue for your specific issue? If you could include a log from :webkit_debug, that may help us find the issue.

@mhoran any thoughts on this screenshot sizing issue?

@jferris jferris changed the title Force the height of the window resize_window has no effect on save_screenshot Jul 2, 2014
@mhoran
Copy link
Collaborator

mhoran commented Jul 3, 2014

@jferris, I think the least surprising behavior would be to preserve the size of the viewport. However, it looks like Selenium prefers to render the entire page when possible. I've been thrown off by this before when a test has failed and I've looked at a screenshot of a responsive page and found unexpected content. I then have to remember that the screenshot is not of the failure, but of a different layout due to responsiveness.

Perhaps less surprising behavior would be to use the viewport width if it is greater than the content width, or the content width if it is greater than the viewport width. The same for height. We could still support user provided width and height for screenshots, and set the width and height to those exact values if they are provided.

@datapimp
Copy link

fwiw, i've found that the same version of capybara-webkit (1.3.1) works fine when resizing the window, if build against qt4 but fails if built against qt5 (on Mavericks, using Homebrew)

@calleluks
Copy link

@mhoran, @jferris have there been changes related to this issue? Can it be closed?

@jferris
Copy link
Contributor

jferris commented May 29, 2015

There haven't been any updates here.

I think a few different bugs have been discussed, and there are some issues regarding Qt 4 vs Qt 5.

Given the age of the issue, the fact that Capybara doesn't really have a spec for exactly how screenshots should work, and that we're phasing out Qt 4, I think it makes the most sense to close this issue.

If anybody is still having trouble with the way screenshots work, please open a new issue for your particular bug.

I'm also open to pull requests that change the way this works if somebody thinks the current behavior is unintuitive.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants