Cucumber 步骤暂停并将控制权移交给用户

发布于 2024-10-18 01:48:01 字数 356 浏览 3 评论 0原文

由于测试环境的独特条件,我在调试黄瓜步骤时遇到了麻烦。我希望有一个步骤可以暂停硒测试并让我接管。

例如

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

别念他 2024-10-25 01:48:01

您可以将 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).

以歌曲疗慰 2024-10-25 01:48:01

我想出了转储数据库的想法。它不允许您从同一页面继续工作,但如果您在测试期间运行应用程序,您可以立即在另一个浏览器(不是由 Selenium 控制的浏览器)中对当前状态进行操作。

步骤如下:

When /I want to take control/i do
  exec "mysqldump -u root --password=* test > #{Rails.root}/support/snapshot.sql"
end

因为它是由 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:

When /I want to take control/i do
  exec "mysqldump -u root --password=* test > #{Rails.root}/support/snapshot.sql"
end

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.

翻了热茶 2024-10-25 01:48:01

我的队友已经使用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/

酒与心事 2024-10-25 01:48:01

步骤

And show me the page

添加您想要与之交互的

Scenario: I want to take over here
  Given: A bunch of steps have already run
  When: I'm stuck on an error
  Then show me the page

Add the step

And show me the page

Where you want to interact with it

Scenario: I want to take over here
  Given: A bunch of steps have already run
  When: I'm stuck on an error
  Then show me the page
行至春深 2024-10-25 01:48:01

非常感谢 @Reed G. Law 提出转储数据库的想法。然后将其加载到开发中,使我能够准确确定为什么我的 Cucumber 功能没有像我预期的那样影响数据库状态。这是我对他的建议的一些小调整:

When /Dump the database/i do
  `MYSQL_PWD=password mysqldump -u root my_test > #{Rails.root}/snapshot.sql`
  # To replicate state in development run:
  # `MYSQL_PWD=password mysql -u root my_development < snapshot.sql`
end

您还可以在 feature/support/debugging.rb 中使用以下内容,让您一次一步地逐步完成该功能:

# `STEP=1 cucumber` to pause after each step
AfterStep do |scenario|
  next unless ENV['STEP']
  unless defined?(@counter)
    puts "Stepping through #{scenario.title}"
    @counter = 0
  end
  @counter += 1
  print "At step ##{@counter} of #{scenario.steps.count}. Press Return to"\
        ' execute...'
  STDIN.getc
end

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:

When /Dump the database/i do
  `MYSQL_PWD=password mysqldump -u root my_test > #{Rails.root}/snapshot.sql`
  # To replicate state in development run:
  # `MYSQL_PWD=password mysql -u root my_development < snapshot.sql`
end

You can also use the following in feature/support/debugging.rb to let you step through the feature one step at a time:

# `STEP=1 cucumber` to pause after each step
AfterStep do |scenario|
  next unless ENV['STEP']
  unless defined?(@counter)
    puts "Stepping through #{scenario.title}"
    @counter = 0
  end
  @counter += 1
  print "At step ##{@counter} of #{scenario.steps.count}. Press Return to"\
        ' execute...'
  STDIN.getc
end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文