Ruby Cucumber:暂停套件进行演示和调试,具有恢复能力

时间:2017-10-03 19:28:01

标签: ruby cucumber

作为软件测试人员,我希望能够在测试执行期间的任何阶段暂停黄瓜的测试执行,以便调试失败的测试并在演示期间向客户端显示更多详细信息。

Scenario: Pause suite mid demo, then resume
 Given I am in a meeting to show off a new feature our team has developed
 And a client asks us a question about the page we are currently on
 When I press the 'p' key in the terminal
 Then I should have enough time to answer the question in detail to the client
 And I should be able to resume test execution by pressing the 'enter' key in the terminal

Scenario: Pause suite at a known point for debugging
 Given there is a failed test
 When I add the "pause" method to the step definition
 Then the test should pause execution until pressing the 'enter' key in the terminal

2 个答案:

答案 0 :(得分:1)

这两个功能在Windows上运行,因此应该适用于大多数其他操作系统。

# Checks for a pause command in the command line and if it has been pressed, will pause
def paused?
    if STDIN.ready?
      last_input = STDIN.gets
      while last_input == 'p'
        sleep 1
      end
    end
end

# Pauses for debugging, will continue when enter is pressed
def pause
  print 'p'
  last_input = STDIN.gets
  while last_input == 'p'
    sleep 1
  end
end

第一个,当在每个步骤定义的开头放置一次时,可以通过按下' p'来完成步骤后直接暂停。在终端。

或者,创建抽象库可能会产生更好的结果,因为在整个过程中可以使用paused?方法在执行期间暂停其他点而不是新步骤的开始。当除了' p'之外的任何标准密钥时,这将恢复。按下,但我会推荐一个新的。

第二个,只需暂停测试,直到按下任何键,此时执行可以恢复 - 非常适合调试。

快乐暂停!

答案 1 :(得分:1)

您可以尝试使用AfterStep hook

AfterStep('@pauseable') do
  answer = 'n'
  begin
    Timeout.timeout 1 do # wait for a second for user to press 'p'
      answer = STDIN.getch
    end
  rescue Timeout::Error  # answer is 'n' when no key is pressed during 1 second
  end

  STDIN.getch if answer == 'p' # wait until user presses any key
end

现在,您可以将自己的功能标记为@pauseable。运行它并按p暂停它。然后按任意键继续