Selenium Webdriver(node.js)截图并保存testing结果

我开始开发一个网站应用程序的testing,我有一些问题。

我使用的是Node.js,webdriver,chromedriver和selenium rc。

问题是:1.如何制作截图并将其保存在与脚本相同的文件夹中。 2.有没有办法保存testing用例的testing日志? 例如,如果检查页面上的一个元素,但没有find它,那么我该如何输出?

为了保存testing日志,您通常使用testing运行器。 当你检查一个元素是否在页面上,但是你找不到它时,你会引发一个exception(通常是一个断言错误),testing运行器会logging下来,并将其标记为失败的testing。 在文档中,他们build议你使用摩卡 。

至于保存截图到磁盘, api看起来像这样

driver.takeScreenshot().then( function(image, err) { require('fs').writeFile('out.png', image, 'base64', function(err) { console.log(err); }); } ); 

只是为了logging,这是你如何使用WebdriverJS截图:

 var webdriverjs = require('webdriverjs'), client = webdriverjs.remote({ desiredCapabilities: { browserName: 'chrome' } }); client .init() .url('http://google.com') .saveScreenshot(__dirname + '/googleScreenshot.png') .end(); 

您也可以使用WebdriverCSS截图。 它是WebdriverJS做CSS回归testing的一个插件。 这和PhantomCSS差不多 。