首页 \ 问答 \ 清理量角器堆栈跟踪(Cleaning up Protractor stack trace)

清理量角器堆栈跟踪(Cleaning up Protractor stack trace)

问题:

是否有可能清理堆栈跟踪并仅留下相关的框架,从而消除ProtractorWebDriverJSJasmine特有的所有内容?

故事:

让我们执行这个示例测试:

describe("SO test", function () {
    beforeEach(function () {
        browser.get("https://angularjs.org");
    });

    it("should throw a meaningful error", function () {
        element(by.id("not_found")).click();
    });
});

它会因以下堆栈跟踪而失败:

SO test should throw a meaningful error
  - Failed: No element found using locator: By.id("not_found")
      at new bot.Error (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/atoms/error.js:108:18)
      at /usr/local/lib/node_modules/protractor/lib/element.js:676:15
      at [object Object].promise.Promise.goog.defineClass.invokeCallback_ (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:1337:14)
      at [object Object].promise.ControlFlow.goog.defineClass.goog.defineClass.abort_.error.executeNext_.execute_ (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:2776:14)
      at [object Object].promise.ControlFlow.goog.defineClass.goog.defineClass.abort_.error.executeNext_ (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:2758:21)
      at goog.async.run.processWorkQueue (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/async/run.js:124:15)
      at process._tickCallback (node.js:377:9)
  Error
      at [object Object].ElementArrayFinder.applyAction_ (/usr/local/lib/node_modules/protractor/lib/element.js:382:21)
      at [object Object].ElementArrayFinder.(anonymous function) [as click] (/usr/local/lib/node_modules/protractor/lib/element.js:78:17)
      at [object Object].ElementFinder.(anonymous function) [as click] (/usr/local/lib/node_modules/protractor/lib/element.js:711:7)
      at Object.<anonymous> (/Users/user/job/project/test/e2e/specs/test.spec.js:9:37)
      at /usr/local/lib/node_modules/protractor/node_modules/jasminewd2/index.js:96:23
      at [object Object].promise.Promise.goog.defineClass.constructor (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:1056:7)
      at new wrappedCtr (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/base.js:2468:26)
      at controlFlowExecute (/usr/local/lib/node_modules/protractor/node_modules/jasminewd2/index.js:82:18)
      at [object Object].promise.ControlFlow.goog.defineClass.goog.defineClass.abort_.error.executeNext_.execute_ (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:2776:14)
      at [object Object].promise.ControlFlow.goog.defineClass.goog.defineClass.abort_.error.executeNext_ (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:2758:21)
  From: Task: Run it("should throw a meaningful error") in control flow
      at Object.<anonymous> (/usr/local/lib/node_modules/protractor/node_modules/jasminewd2/index.js:81:14)
      at /usr/local/lib/node_modules/protractor/node_modules/jasminewd2/index.js:18:5
      at [object Object].promise.Promise.goog.defineClass.invokeCallback_ (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:1337:14)
      at [object Object].promise.ControlFlow.goog.defineClass.goog.defineClass.abort_.error.executeNext_.execute_ (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:2776:14)
      at [object Object].promise.ControlFlow.goog.defineClass.goog.defineClass.abort_.error.executeNext_ (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:2758:21)
      at goog.async.run.processWorkQueue (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/async/run.js:124:15)
  From asynchronous test: 
  Error
      at Suite.<anonymous> (/Users/user/job/project/test/e2e/specs/test.spec.js:8:5)
      at Object.<anonymous> (/Users/user/job/project/test/e2e/specs/test.spec.js:3:1)
      at Module._compile (module.js:425:26)
      at Object.Module._extensions..js (module.js:432:10)
      at Module.load (module.js:356:32)

正如您所看到的,在测试中找到错误实际发生的位置并不容易。 它隐藏在由ProtractorWebDriverJSJasmine堆栈框架覆盖的堆栈跟踪内部。 这使得调试和开发端到端测试变得困难。

期望的输出:

SO test should throw a meaningful error
  - Failed: No element found using locator: By.id("not_found")
      at Object.<anonymous> (/Users/user/job/project/test/e2e/specs/test.spec.js:9:37)
  From asynchronous test: 
  Error
      at Suite.<anonymous> (/Users/user/job/project/test/e2e/specs/test.spec.js:8:5)
      at Object.<anonymous> (/Users/user/job/project/test/e2e/specs/test.spec.js:3:1)
      at Module._compile (module.js:425:26)
      at Object.Module._extensions..js (module.js:432:10)
      at Module.load (module.js:356:32)
      at Function.Module._load (module.js:311:12)

使用protractor 3.0.0和jasmine2


mocha世界中,有一个相关的mocha-clean软件包可以过滤掉来自node_modulesmocha本身的所有内容,留下一个易于阅读的干净堆栈跟踪。


The Question:

Is it possible to clean up the stack trace and leave only relevant frames eliminating everything Protractor, WebDriverJS and Jasmine specific?

The Story:

Let's execute this example test:

describe("SO test", function () {
    beforeEach(function () {
        browser.get("https://angularjs.org");
    });

    it("should throw a meaningful error", function () {
        element(by.id("not_found")).click();
    });
});

It would fail with a following stacktrace:

SO test should throw a meaningful error
  - Failed: No element found using locator: By.id("not_found")
      at new bot.Error (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/atoms/error.js:108:18)
      at /usr/local/lib/node_modules/protractor/lib/element.js:676:15
      at [object Object].promise.Promise.goog.defineClass.invokeCallback_ (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:1337:14)
      at [object Object].promise.ControlFlow.goog.defineClass.goog.defineClass.abort_.error.executeNext_.execute_ (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:2776:14)
      at [object Object].promise.ControlFlow.goog.defineClass.goog.defineClass.abort_.error.executeNext_ (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:2758:21)
      at goog.async.run.processWorkQueue (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/async/run.js:124:15)
      at process._tickCallback (node.js:377:9)
  Error
      at [object Object].ElementArrayFinder.applyAction_ (/usr/local/lib/node_modules/protractor/lib/element.js:382:21)
      at [object Object].ElementArrayFinder.(anonymous function) [as click] (/usr/local/lib/node_modules/protractor/lib/element.js:78:17)
      at [object Object].ElementFinder.(anonymous function) [as click] (/usr/local/lib/node_modules/protractor/lib/element.js:711:7)
      at Object.<anonymous> (/Users/user/job/project/test/e2e/specs/test.spec.js:9:37)
      at /usr/local/lib/node_modules/protractor/node_modules/jasminewd2/index.js:96:23
      at [object Object].promise.Promise.goog.defineClass.constructor (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:1056:7)
      at new wrappedCtr (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/base.js:2468:26)
      at controlFlowExecute (/usr/local/lib/node_modules/protractor/node_modules/jasminewd2/index.js:82:18)
      at [object Object].promise.ControlFlow.goog.defineClass.goog.defineClass.abort_.error.executeNext_.execute_ (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:2776:14)
      at [object Object].promise.ControlFlow.goog.defineClass.goog.defineClass.abort_.error.executeNext_ (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:2758:21)
  From: Task: Run it("should throw a meaningful error") in control flow
      at Object.<anonymous> (/usr/local/lib/node_modules/protractor/node_modules/jasminewd2/index.js:81:14)
      at /usr/local/lib/node_modules/protractor/node_modules/jasminewd2/index.js:18:5
      at [object Object].promise.Promise.goog.defineClass.invokeCallback_ (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:1337:14)
      at [object Object].promise.ControlFlow.goog.defineClass.goog.defineClass.abort_.error.executeNext_.execute_ (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:2776:14)
      at [object Object].promise.ControlFlow.goog.defineClass.goog.defineClass.abort_.error.executeNext_ (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:2758:21)
      at goog.async.run.processWorkQueue (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/async/run.js:124:15)
  From asynchronous test: 
  Error
      at Suite.<anonymous> (/Users/user/job/project/test/e2e/specs/test.spec.js:8:5)
      at Object.<anonymous> (/Users/user/job/project/test/e2e/specs/test.spec.js:3:1)
      at Module._compile (module.js:425:26)
      at Object.Module._extensions..js (module.js:432:10)
      at Module.load (module.js:356:32)

As you can see, it's not easy to find on which line in the test the error actually happened. It's hidden somewhere inside the stack trace covered by Protractor, WebDriverJS and Jasmine stack frames. This makes it difficult to debug and develop end-to-end tests.

Desired output:

SO test should throw a meaningful error
  - Failed: No element found using locator: By.id("not_found")
      at Object.<anonymous> (/Users/user/job/project/test/e2e/specs/test.spec.js:9:37)
  From asynchronous test: 
  Error
      at Suite.<anonymous> (/Users/user/job/project/test/e2e/specs/test.spec.js:8:5)
      at Object.<anonymous> (/Users/user/job/project/test/e2e/specs/test.spec.js:3:1)
      at Module._compile (module.js:425:26)
      at Object.Module._extensions..js (module.js:432:10)
      at Module.load (module.js:356:32)
      at Function.Module._load (module.js:311:12)

Using protractor 3.0.0 and jasmine2.


In mocha world, there is a relevant mocha-clean package that filters out everything coming from inside node_modules and mocha itself leaving a clean stack trace that is easy to read.


原文:https://stackoverflow.com/questions/34049365
更新时间:2023-12-28 11:12

最满意答案

它不能是你的问题或错误的来源,但我认为所有出现的行[: - 2]都应该被行[: - 1]取代,如果你想要除了一个所有索引(Python不包括索引) row[begin:end]类的范围内给出的row[begin:end]

你应该有:

y_ = tf.placeholder(tf.float32,[None,numberOFClasses])
...
sess.run(train_step,feed_dict={x:batch_xs[i],y_:np.reshape(batch_ys[i],(batchSize, numberOFClasses ))})
...
print(sess.run(accuracy,feed_dict={x:batch_txs[i],y_:np.reshape(batch_tys[i],(batchSize, numberOFClasses ))}))

无论如何,您应该batch_size != numberOFClasses使用batch_size != numberOFClasses ,因为它会抛出一个错误,您可以使用它来理解代码中的错误。 如果不这样做,则会丢失异常消息,但错误仍然存​​在,隐藏(您的网络仍然无法学习您想要的内容)。 当你得到重新检查问题的错误外观,并试图理解为什么(看看形状是什么,应该是什么)


It can't be the source of your problem or errors, but I think all occurrences of row[:-2] should be replaced by row[:-1], if you want to take all indices but one (Python excludes the index end given in a range like row[begin:end])

You should have:

y_ = tf.placeholder(tf.float32,[None,numberOFClasses])
...
sess.run(train_step,feed_dict={x:batch_xs[i],y_:np.reshape(batch_ys[i],(batchSize, numberOFClasses ))})
...
print(sess.run(accuracy,feed_dict={x:batch_txs[i],y_:np.reshape(batch_tys[i],(batchSize, numberOFClasses ))}))

Anyway, you should definetly use batch_size != numberOFClasses, because it throws an error that you can use to understand what is wrong in your code. If you don't, you lose the exception message but the error is still there, hidden (you network still does not learn what you want). When you get the error look which reshapecauses a problem, and try to understand why (look what the shapes are and should be)

相关问答

更多
  • 如果通过取消一项工作你的意思是删除它,那么你可以使用DELETE动词: DELETE /jobs?ids=123,321,... 如果通过取消工作,你的意思是设置一些状态字段取消,那么你可以使用PATCH动词: PATCH /jobs Content-Type: application/json [ { "id": 123, "status": "cancelled" }, { "id": 321, "status": "cancelled" } ] If by cancelling a job you ...
  • 你必须记住,就用户而言,TensorFlow只是“机器学习API”。 人们可能碰巧将它用于图像分类 - 2017年Dev Summit展示了皮肤癌检测和视网膜成像的医疗用例 - 但是监督和无监督机器学习的所有主题都是TensorFlow的候选者,就像它们对任何其他ML库一样; 通过广告预算回归销售,社交网络中的用户聚类以及通过协同过滤基于先前购买推荐书籍,仅举几例。 如果您听说过最近的自动驾驶汽车项目,请考虑从实时摄像头输入获取方向盘和制动控制命令。 例如,NVIDIA就此发表了一篇论文 。 一个相当有趣的 ...
  • 您的代码中缺少的是您希望如何使用data_batch和label_batch张量。 根据这段代码(假设number_OF_features == len(content)-1 ) (BATCH_SIZE, number_OF_features)这些张量的形状(BATCH_SIZE, number_OF_features) (分别为(BATCH_SIZE, 1) ): features = tf.stack(content[:-2]) labels = content[-1] ... data_batch, ...
  • 所以一天之后,我终于找到了解决办法: 像Yaroslav为param服务器所建议的那样,以便工作人员不会耗尽GPU内存 参数服务器和worker不能在同一个端口上运行(与原来的post相同),所以将workers = [ "1.2.3.4:2222", "5.6.7.8:2222"]更改为workers = [ "1.2.3.4:2223", "5.6.7.8:2222"] 。 注意端口号的变化。 这就是需要完成的一切。 So after a day I finally got the fix: Do as ...
  • model.ckpt.meta:存储图形信息的文件 model.ckpt.index:存储变量索引的文件 model.ckpt.data0000-of-0001:存储变量值的文件 这三个文件都是真正的检查点文件。 使用tf.train.Saver.restore恢复模型时,参数“save_path”应为“~model.ckpt”。 您的错误可能是由于save_path无效而发生的。 检查save_path中的三个文件(.meta,.index,.data~)(相对路径或绝对路径)。 model.ckpt.m ...
  • 一旦你训练了模型,你应该通过添加类似的代码将它保存到某个地方 builder = saved_model_builder.SavedModelBuilder(export_path) builder.add_meta_graph_and_variables( sess, [tag_constants.SERVING], signature_def_map={ 'predict_images': prediction_signatur ...
  • 最后,我们通过仔细调整网络参数并将温度应用于结果以获得一些很好的建议,从而获得了良好的结果。 序列长度在训练期间非常重要。 Finally, we have been able to obtain good results by carefully tuning the parameters of the network and applying temperature to the results to get some good suggestions. The sequence length was ...
  • 一个滑块是任何不是prvalue的东西。 示例是实体的名称,或具有引用类型的表达式(无论引用的类型如何)。 int i; int* p = &i; int& f(); int&& g(); int h(); h() // prvalue g() // glvalue (xvalue) f() // glvalue (lvalue) i // glvalue (lvalue) *p // glvalue (lvalue) std::move(i) // glvalue (xvalue) 正如你 ...
  • 它不能是你的问题或错误的来源,但我认为所有出现的行[: - 2]都应该被行[: - 1]取代,如果你想要除了一个所有索引(Python不包括索引) row[begin:end]类的范围内给出的row[begin:end] 你应该有: y_ = tf.placeholder(tf.float32,[None,numberOFClasses]) ... sess.run(train_step,feed_dict={x:batch_xs[i],y_:np.reshape(batch_ys[i],(batchSiz ...
  • 欢迎来到TensorFlow。 以下行: input_fn = tf.contrib.learn.io.numpy_input_fn({"x":x}, y, batch_size=4, num_epochs=1000) 生成一个函数input_fn ,稍后将其传递给使用线性回归量估计器生成的估算对象的方法.fit 。 input_fn将提供batch_size=4功能和目标,最多1000次( num_epochs=1000 )。 batch_size指的是小批量大小。 关于Epoch是一个完整的训练示例。 ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)