量角器:我应该如何从browser.executeAsync内部传播错误? [英] Protractor: How should I propagate an error from within browser.executeAsync?

查看:96
本文介绍了量角器:我应该如何从browser.executeAsync内部传播错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果根据量角器规范,我在browser.executeAsyncScript中执行了脚本,我该如何传达该脚本确实失败了?考虑以下对browser.executeAsyncScript的调用:

If from a Protractor spec, I execute a script within browser.executeAsyncScript, how should I communicate that the script has indeed failed? Consider the following call to browser.executeAsyncScript:

browser.executeAsyncScript((callback) ->
  # How do I communicate an error condition here!?
  callback()
)
.then((data) ->
  console.log("Browser async finished without errors: #{data}")
, (data) ->
  console.log("Browser async finished with errors: #{data}")
)

我想发生的是调用了错误回调。我该怎么做?

What I want to happen is that the error callback to then is invoked. How do I do this?

推荐答案

来自 webdriverjs文件

driver.executeAsyncScript(function() {
  var callback = arguments[arguments.length - 1];
  var xhr = new XMLHttpRequest();
  xhr.open("GET", "/resource/data.json", true);
  xhr.onreadystatechange = function() {
    if (xhr.readyState == 4) {
      callback(xhr.responseText);
    }
  }
  xhr.send('');
}).then(function(str) {
  console.log(JSON.parse(str)['food']);
});

因此,它似乎没有错误回调,但是您可以将一些参数传递给回调方法。您可以使用它来传播错误。

So, it does not seem to have an error callback, but you can pass some arguments to the callback method. You can use it to propagate errors.

这篇关于量角器:我应该如何从browser.executeAsync内部传播错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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