Selenium Webdriver的屏幕截图:如何设置窗口大小


Screenshots with Selenium Webdriver: How can I set the window size?

正如其他地方所解释的(使用Selenium WebDriver截取屏幕截图),您可以使用Selenium WebDriver类PHPUnit_Extensions_Selenium2TestCase使用PHPUnit轻松截屏。

但是,我找不到设置生成的屏幕截图的屏幕尺寸的方法。默认情况下,它们的宽度似乎限制为 1000 像素。

顺便说一句:上面提到的堆栈溢出线程已关闭。所以我不能在那里发布我的问题。

您是否尝试过调整浏览器窗口的大小?我在这里找到了关于它的有趣帖子。那里的一些代码片段:

    $this->currentWindow()->size(array(
  'width' => 800,
  'height' => 600,
));

非常感谢!这解决了我的问题。我发布我的代码以提供一个更完整的示例:

您可以获取任何带有$this->currentWindow()的窗口,然后在其上调用"关闭方法"size()。我把它放进了我的setupPage()方法中。

class DrupalWebtestBase extends 'PHPUnit_Extensions_Selenium2TestCase
{
    /* ... */
    public function setUpPage()
    {       
        parent::setUpPage();
        if( $this->width && $this->height )
        {    
            // main window is named ''  
            $this->window('');
            // get window object
            $window = $this->currentWindow();
            // set window size
            $window->size( array(
                            'width'     => $this->width,
                            'height'    => $this->height) );
        }
    }
}

稍后拍摄的屏幕截图反映了上面设置的窗口尺寸。