Cucumber 步骤暂停并将控制权移交给用户
由于测试环境的独特条件,我在调试黄瓜步骤时遇到了麻烦。我希望有一个步骤可以暂停硒测试并让我接管。
例如
Scenario: I want to take over here
Given: A bunch of steps have already run
When: I'm stuck on an error
Then: I want to take control of the mouse
,那时我可以与应用程序进行交互,就像我在运行 rails server -e test
后自己完成了所有前面的步骤一样,
是否存在这样的步骤,或者是否有办法实现它?
I'm having trouble debugging cucumber steps due to unique conditions of the testing environment. I wish there was a step that could pause a selenium test and let me take over.
E.g.
Scenario: I want to take over here
Given: A bunch of steps have already run
When: I'm stuck on an error
Then: I want to take control of the mouse
At that point I could interact with the application exactly as if I had done all the previous steps myself after running rails server -e test
Does such a step exist, or is there a way to make it happen?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您可以将 ruby-debug 集成到 Cucumber 测试中。 Nathaniel Ritmeyer 在此处提供了说明,并且这里对我有用。您本质上需要 ruby-debug,在环境文件中启动调试器,然后在您想要查看发生情况的位置放置“断点”。您可以与浏览器/应用程序交互,并在测试中查看 ruby 变量的值。 (我不确定它是否会让您看到 Rails 应用程序本身中的变量 - 我不会针对 Rails 应用程序进行测试来检查这一点)。
You can integrate ruby-debug into your Cucumber tests. Nathaniel Ritmeyer has directions here and here which worked for me. You essentially require ruby-debug, start the debugger in your environment file, and then put "breakpoint" where ever you want to see what's going on. You can both interact with the browser/application and see the values of your ruby variables in the test. (I'm not sure whether it'll let you see the variables in your rails application itself - I'm not testing against a rails app to check that).
我想出了转储数据库的想法。它不允许您从同一页面继续工作,但如果您在测试期间运行应用程序,您可以立即在另一个浏览器(不是由 Selenium 控制的浏览器)中对当前状态进行操作。
步骤如下:
因为它是由
exec
调用的,DatabaseCleaner 没有机会截断表,所以实际上该命令是数据库转储是无关紧要的。您不必导入 sql 即可在当前状态下使用该应用程序,但如果您需要它,它就在那里。I came up with the idea to dump the database. It doesn't let you continue work from the same page, but if you have the app running during the test, you can immediately act on the current state of things in another browser (not the one controlled by Selenium).
Here is the step:
Because it is called by
exec
, DatabaseCleaner has no chance to truncate tables, so actually it's irrelevant that the command is a database dump. You don't have to import the sql to use the app in its current state, but it's there if you need it.我的队友已经使用selenium、firebug a hook (@selenium_with_firebug) 完成了此操作,
他学到的所有内容都来自此博文:
http://www.allenwei.cn/tips-add-firebug-extension-to-capybara/
My teammate has done this using selenium, firebug a hook (@selenium_with_firebug)
Everything he learned came from this blogpost:
http://www.allenwei.cn/tips-add-firebug-extension-to-capybara/
步骤
添加您想要与之交互的
Add the step
Where you want to interact with it
使用 http://www.natontesting.com /2009/11/09/调试-黄瓜-测试-with-ruby-debug/
use http://www.natontesting.com/2009/11/09/debugging-cucumber-tests-with-ruby-debug/
非常感谢 @Reed G. Law 提出转储数据库的想法。然后将其加载到开发中,使我能够准确确定为什么我的 Cucumber 功能没有像我预期的那样影响数据库状态。这是我对他的建议的一些小调整:
您还可以在 feature/support/debugging.rb 中使用以下内容,让您一次一步地逐步完成该功能:
Big thank you to @Reed G. Law for the idea of dumping the database. Then loading it into development allowed me to determine exactly why my cucumber feature was not impacting database state as I had expected. Here's my minor tweak to his suggestion:
You can also use the following in feature/support/debugging.rb to let you step through the feature one step at a time: