Search code examples
linuxgoogle-chromeprotractorheadlessxvfb

Xvfb (xvfb-run) incorrect resolution


i'm running protractor tests (chrome) headless and Xvfb or xvfb-run creates displays with incorrect resolution. I have two variants of tests starting:

Xvfb :10 -screen 0 1920x1200x24 -ac &
export DISPLAY=:10
<command>

or

xvfb-run --auto-servernum --server-args='-screen 0, 1920x1200x24' <command>

but it creates screens with resolution 945x1180 (resolutiion can be a little bit smaller, it's chrome viewport). BTW. If I change screen to 1, resolution will be 1050x1004


Solution

  • I search resolving of the problem almost 4 ours and, when I ask, answer was founded. Need to hardcode window size (I have chrome flag to start maximized and protractor parameter browser.driver.manage().window().maximize()). Answer from here helps me How to set default browser window size in Protractor/WebdriverJS

    onPrepare: function() {
        setTimeout(function() {
            browser.driver.executeScript(function() {
                return {
                    width: window.screen.availWidth,
                    height: window.screen.availHeight
                };
            }).then(function(result) {
                browser.driver.manage().window().setSize(result.width, result.height);
            });
        });
    },