Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

macaca 导出的报告、截图在哪,以及相应文档。 #85

Closed
lemonadam opened this issue Jul 12, 2016 · 10 comments
Closed

macaca 导出的报告、截图在哪,以及相应文档。 #85

lemonadam opened this issue Jul 12, 2016 · 10 comments
Assignees

Comments

@lemonadam
Copy link

之前连接里的内容:#13
已经不支持观看了。对应文档 http://macacajs.github.io/macaca/client-usage.html 是404

求报告如何导出,以及截图如果看到。

  • Macaca Version:
  • Macaca Doctor:
  • Platform:
@xudafeng
Copy link
Member

xudafeng commented Jul 12, 2016

@zenzhu 提供个示例代码,可以写截图文件到当前目录

@ziczhu
Copy link
Member

ziczhu commented Jul 12, 2016

macaca run -o 会默认保存到 macaca-test 目录下面。
macaca run -o dir 会保存到 dir 文件夹
macaca run -o xxx.html 会保存到特定文件

@lemonadam
Copy link
Author

@zenzhu 看了一下 网页是纯log输出,和terminal 下是一样的。
请问有失败截图么。我看代码中很多 .takeScreenshot(); 这个是怎么和报告结合的?
求教,感谢。

@ziczhu
Copy link
Member

ziczhu commented Jul 13, 2016

@lemonadam 失败截图的话。可以在每个测试用例 promise chain 的最后加一个 catch 语句,其中添加driver.takeScreenshot(), 就相当于在失败的情况下进行截图。
另外,takeScreenshot 是返回 base64 字符串,如果希望能在报告中看到,可以使用 CDN 服务上传转换成图片的 url,然后打印出 html 的 img 标签,就可以在报告中看到。

 ...
 .takeScreenshot()
 .then(base64Str => {
    var imgUrl = fakeCdn.upload(base64Str);
    console.log('<img src =' + imgUrl + '/>')
 })

或者直接把 base64 字符串打印成 img 标签,这样的问题是终端会看到过长的字符串,但 html 上会显示成图片。

 ...
 .takeScreenshot()
 .then(base64Str => {
    console.log('<img src="data:image/png;base64,' + imgUrl + '" />')
 })

saveScreenshot(path) 是可以将截图保存到指定的地址。

@lemonadam
Copy link
Author

@zenzhu 非常感谢。我试试

@lemonadam
Copy link
Author

@zenzhu
我直接用base64 放src里会有问题。不过decode之后没问题了。
贴代码在这吧,方便其他人用。
var fs = require('fs');
function base64_decode(base64str, file) {
// create buffer object from base64 encoded string, it is important to tell the constructor that the string is base64 encoded
var bitmap = new Buffer(base64str, 'base64');
// write buffer to file
fs.writeFileSync(file, bitmap);
console.log(' File created from base64 encoded string ');
}
...
...
.takeScreenshot()
.then(base64Str => {
base64_decode(base64Str, 'macaca-test/copy.jpg');
console.log('')
});

@ziczhu
Copy link
Member

ziczhu commented Jul 13, 2016

@lemonadam 谢谢分享~

@ziczhu ziczhu closed this as completed Jul 13, 2016
@xudafeng
Copy link
Member

@zenzhu @lemonadam 👍

@xudafeng xudafeng added the FAQ label Nov 21, 2016
@AllocAndInit
Copy link

AllocAndInit commented Jan 5, 2017

@lemonadam @zenzhu @xudafeng 看了你们关于测试用例运行失败 截图的问题,我有一个疑问,如果在自动化测试过程中,app 发生 crash ,此时 如何捕获当前 app 崩溃的时机并截图?请问这个可以实现吗?对nodejs 不是很熟悉,如果能实现,请问在测试用例里面该怎么写?

在此 多谢啦

@AllocAndInit
Copy link

AllocAndInit commented Jan 5, 2017

@lemonadam @xudafeng @zenzhu 请问一下,因为对 nodejs不是很熟悉,那么如何在每个测试用例 promise chain 的最后加一个 catch 语句?能不能说的具体一点?

多谢啦

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants