Selenium Webdriver(node.js)截取屏幕截图并保存测试结果 [英] Selenium Webdriver (node.js) take screenshot and save test results

查看:736
本文介绍了Selenium Webdriver(node.js)截取屏幕截图并保存测试结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始为网站应用程序开发测试,但我遇到了一些问题。

I started developing tests for a website application and I have some problems.

我正在使用Node.js,webdriver,chromedriver和selenium rc。

I'm using Node.js, webdriver, chromedriver and selenium rc.

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

The questions are: 1. How do I make a screenshot and save it in the same folder as the script. 2. Is there a way to save the test logs for a test case? For example, if check for an element on the page and don't find it, how do I output that?

推荐答案

保存测试日志通常使用测试运行器。当您检查某个元素是否在页面上并且找不到它时,则会引发异常(通常是断言错误),并且测试运行器将记录此信息并将其标记为失败的测试。 在文档中,他们建议您使用摩卡

For saving the test logs you typically use a test runner. When you check if an element is on the page and you can't find it then you raise an exception (typically an assertion error) and the test runner will record this and mark it as a failed test. In the documentation they suggest you use Mocha.

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

As for saving a screenshot to disk, the the api looks like this

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

这篇关于Selenium Webdriver(node.js)截取屏幕截图并保存测试结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆