问题描述
我刚刚开始使用带有浏览器堆栈的守夜器,并且注意到当我们测试失败时,守夜器会记录失败,但浏览器栈不会.我正在使用的示例测试.另外,我正在使用BrowserStack的免费试用版.
I just started using nightwatch with browserstack and I'm noticing that when we get a failed test, nightwatch registers the failure, but browserstack does not. sample test I am using. Also I am using free trial version of BrowserStack.
我的问题是:
- 有什么想法可以告诉浏览器何时测试运行失败?
来自BrowserStack 文档:
From BrowserStack doc:
可以使用 以下代码段:
It is possible to mark tests as either a pass or a fail, using the following snippet:
var request = require("request");
request({
uri: "https://user:[email protected]/automate/sessions/<session-id>.json",
method: "PUT",
form: {
"status": "completed",
"reason":""
}
});
我的问题是:
- 测试执行后如何获取"session-id"?
- 如果我已经可以在仪表板上看到已完成"状态怎么办?
推荐答案
-
BrowserStack上的会话只有三种类型的状态:已完成,错误或超时.如果测试通过或失败,Selenium(以及因此的BrowserStack)将无法理解.通过控制台上出现的测试中的多个断言,可以推断测试是否通过/失败.但是,这些断言不会到达BrowserStack.如您所知,可以使用 REST-API 来更改其状态如果您在控制台中看到失败,则将会话切换为错误".
A session on BrowserStack has only three types of statuses: Completed, Error or Timeout. Selenium (and hence, BrowserStack) does not have a way of understanding, if a test has passed or failed. Its by the multiple assertions in your tests that appear on your console, that you infer if a test has passed / failed. These assertions however, do not reach BrowserStack. As you rightly identified, you can use the REST-API, to change the status of the session to 'Error', if you see a failure in your console.
我建议在执行测试时获取测试的会话ID,因为在测试执行后 之后获取会话ID是一个漫长的过程.在Nightwatch中,您可以按以下方式获取会话ID:
I would suggest fetching the session ID of the test as the test is being executed, since fetching the session ID after the test execution is a lengthy process. In Nightwatch, you can fetch session ID as follows:
browser.session(function(session) {
console.log(session.sessionId);
});
- 是的,您当然可以在会话完成后更改其状态.这就是REST-API来提供帮助的地方!
这篇关于即使Nightwatch.js中的测试失败,Browserstack也报告成功的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!