How can I take a screenshot with Selenium WebDriver?

后端 未结 30 2622
不知归路
不知归路 2020-11-21 07:48

Is it possible to take a screenshot using Selenium WebDriver?

(Note: Not Selenium Remote Control)

30条回答
  •  别跟我提以往
    2020-11-21 08:38

    PHP (PHPUnit)

    It uses PHPUnit_Selenium extension version 1.2.7:

    class MyTestClass extends PHPUnit_Extensions_Selenium2TestCase {
        ...
        public function screenshot($filepath) {
            $filedata = $this->currentScreenshot();
            file_put_contents($filepath, $filedata);
        }
    
        public function testSomething() {
            $this->screenshot('/path/to/screenshot.png');
        }
        ...
    }
    

提交回复
热议问题