Mac selenium webdriver镀铬窗口始终以一个小窗口开始

jus*_*tin 10 java selenium webdriver

我有使用chrome和selenium 2 webdriver的问题.问题是当我使用chromedriver启动浏览器会话时,它总是在一个小于可用屏幕宽度一半大小的窗口中启动.因为我正在对屏幕大小发生变化的页面进行测试,所以我的测试失败了,因为我试图从页面顶部拖动一个元素并将其放到页面底部的元素中.我得到一个滚动错误.但如果窗口最大化,那么我不会得到这个错误.但问题是,每次chrome通过chrome驱动程序启动一个新会话时,它总是在一个小窗口中启动.我已经探索了许多不同的选项来让浏览器开始最大化:

  • 通过javascript拨打电话,使用window.resizeTo(width,height);更改窗口的大小.但是,这在后续版本的chrome(或firefox)中不起作用.
  • 使用开关启动chrome --start-maximized.这适用于Windows,但这在mac上没有任何作用.
  • 使用指定配置文件目录的开关启动chrome.这样,配置文件将定义窗口大小.--profile-directory =〜/ chromeprofile当我从命令行启动chrome时,这个工作正常,但是如果我从selenium webdriver/chromedriver这样做,它没有任何区别.
  • 当我尝试:driver.manage().window().setSize()我得到这个异常:

    INFO: Executing: [93debf43cf70ad3557442a7e1aee4620, setWindowSize {"windowHandle":"current","width":2560,"height":1440}]
    org.openqa.selenium.UnsupportedCommandException: [GET, HEAD, DELETE]
    Command duration or timeout: 16 milliseconds
    Build info: version: '2.15.0', revision: '15105', time: '2011-12-08 09:56:25'
    System info: os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.7.2', java.version: '1.6.0_29'
    Driver info: driver.version: RemoteWebDriver
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
        at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:147)
        at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:113)
        at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:424)
        at org.openqa.selenium.remote.RemoteWebDriver$RemoteWebDriverOptions$RemoteWindow.setSize(RemoteWebDriver.java:578)
        at com.domo.automation.framework.utility.WebDriverUtil.startWebDriver(WebDriverUtil.java:36)
        at com.domo.automation.tests.DomoWebDriverTestCase.setUp(DomoWebDriverTestCase.java:45)
        at junit.framework.TestCase.runBare(TestCase.java:132)
        at junit.framework.TestResult$1.protect(TestResult.java:110)
        at junit.framework.TestResult.runProtected(TestResult.java:128)
        at junit.framework.TestResult.run(TestResult.java:113)
        at junit.framework.TestCase.run(TestCase.java:124)
        at junit.framework.TestSuite.runTest(TestSuite.java:243)
        at junit.framework.TestSuite.run(TestSuite.java:238)
        at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:83)
        at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
        at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:71)
        at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:199)
        at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:62)
    
    Run Code Online (Sandbox Code Playgroud)

我可以探索哪些其他选项来实现这一目标?问题是窗口太小了?每次Chrome启动时,我可以通过Mac上的webdriver自动最大化窗口?

Ame*_*mey 1

driver.manage().window().setSize()是你想要使用的方法