SeleniumHQ / selenium-google-code-issue-archive

Archive, please see main selenium repo
https://github.com/seleniumhq/selenium
345 stars 195 forks source link

IE8 is unnecessarily (and incorrectly) resized before screenshots #6503

Open lukeis opened 8 years ago

lukeis commented 8 years ago

Originally reported on Google Code with ID 6503

What steps will reproduce the problem?
1. Run a test which opens http://artur.virtuallypreinstalled.com/selenium1.html and
takes a screenshot

        DesiredCapabilities cap = DesiredCapabilities.internetExplorer();
        cap.setVersion("8"); // Compare with 9+
        WebDriver driver = new RemoteWebDriver(new URL(
                HUB_URL, cap);
        driver = new Augmenter().augment(driver);

        // Load a page which shows the resizes
        driver.get("http://artur.virtuallypreinstalled.com/selenium1.html");
        String base64 = ((TakesScreenshot) driver)
                .getScreenshotAs(OutputType.BASE64);
        driver.close();

2. Observe the difference when running the test on IE8 and IE9
3. Observe the browser window when running on IE8

What is the expected output? What do you see instead?

Expected would be that a screenshot is taken and nothing else happens as the content
fits the browser window. 

What actually happens in IE8 is that the calculation (I think it's the one in IEDriver
/ ScreenshotCommandHandler.h) figures out that the window should be resized by (-4,-4).
AFAIK the resize logic is used to ensure that the browser window contains the full
page before taking the screenshot as described in https://code.google.com/p/selenium/issues/detail?id=5332.

From what I see a simple check for negative resize values should fix this issue and
speed up complex tests in IE8.

A side effect from this is also that screenshots get the wrong resolution in IE8. If
you ensure the viewport is 1000x1000, the screenshot will be 996x996.

The above test finishes in 5s on IE9 and produces the expected screenshot.
On IE8 the test takes 20s and produces an image with the wrong clientWidth/scrollWidth
values.

Reported by artur@vaadin.com on 2013-10-30 13:22:13

lukeis commented 8 years ago

Reported by barancev on 2013-10-30 14:13:23

lukeis commented 8 years ago
To eliminate the constant resizing, I switched from maximizing my window to setting
its window size explicitly, i.e. context.browser.set_window_size(1280, 1024)

This gave me a slight improvement in my IE8 testing time, from 4m31s to 4m17s

Reported by jonathan@act.md on 2014-02-18 20:51:01

lukeis commented 8 years ago

Reported by nirvdrum on 2014-03-23 20:43:47

lukeis commented 8 years ago
@jonathan@act.md

The reason you'd get a slight performance gain is we can't resize a maximized window.
 So, we have to fix restore its original size, then set the size needed to take the
screenshot, and then maximize the window again.  The only canveat about not maximizing
the window is we get the canvas dimensions based upon DOM inspection in the current
viewport.  So, if you're doing some form of responsive design, you may very well want
to maximize anyway to ensure you get a screenshot for the size you actually want.

Reported by nirvdrum on 2014-03-23 20:59:36

lukeis commented 8 years ago
If someone could post this right on the InternetExplorerDriver project page it would
be a huge help to many, I'm sure. This was like finding the holy grail of IE tests
for me, not just for the performance gain I realized, but also for the hover effect
issues I was having when taking screenshots. The problem is that I'm doing screenshot
based verification and when I would have the mouse hover over some element to display
a div, then attempt to take a screenshot in IE, the window would be re-sized to an
awkward dimension, the mouse would no longer be hovering over the the target element,
and the div would disappear. This was very frustrating until I stopped maximizing my
IE windows and started explicitly defining their size at test startup.

Reported by AdamJasonDev on 2014-05-16 14:46:10

lukeis commented 8 years ago

Reported by luke.semerau on 2015-09-17 17:45:56