How to set default browser window size in Protractor/WebdriverJS

前端 未结 8 1931
广开言路
广开言路 2020-11-27 15:14

For some reason when I run my tests at work the browser is maximized, but when I run them at home it only opens a browser window of about 50% width. This causes some discrep

相关标签:
8条回答
  • 2020-11-27 16:13

    You can set the default browser size by running:

    var width = 800;
    var height = 600;
    browser.driver.manage().window().setSize(width, height);
    

    To maximize the browser window, run:

    browser.driver.manage().window().maximize();
    

    To set the position, run:

    var x = 150;
    var y = 100;
    browser.driver.manage().window().setPosition(x, y);
    

    If you get an error:

    WebDriverError: unknown error: operation is unsupported with remote debugging

    Operation not supported when using remote debugging Some WebDriver commands (e.g. resizing the browser window) require a Chrome extension to be loaded into the browser. ChromeDriver normally loads this "automation extension" every time it launches a new Chrome session.

    However ChromeDriver can be instructed to connect to an existing Chrome session instead of launching a new one. This is done using 'debuggerAddress' in the Capabilities (aka ChromeOptions) object. Since the automation extension is only loaded at startup, there are some commands that ChromeDriver does not support when working with existing sessions through remote debugging.

    If you see the error "operation not supported when using remote debugging", try rewriting the test so that it launches a new Chrome session. This can be done by removing 'debuggerAddress' from the Capabilities object.

    Source: Operation not supported when using remote debugging

    0 讨论(0)
  • 2020-11-27 16:17

    Add the below code. This will maximize the browser window.

    browser.driver.manage().window().maximize();
    
    0 讨论(0)
提交回复
热议问题