2014-10-08 51 views
1

我在葫蘆裏面使用了AfterStep鉤子/ ios/cucumber。我如何從葫蘆黃瓜裏面的AfterStep中提取步驟名稱

我想知道我的鉤子裏面最後執行的步驟。

AfterStep do |scenario| 
    puts "Step: #{scenario.name} #{scenario.title} #{scenario.gherkin_statement}"                 
end 

我可以看到該場景已經傳入,但是如何訪問當前正在運行的步驟?我在scenario docs裏看不到有關這方面的任何信息。

我會假設該步驟將被傳遞到AfterStep掛鉤。任何線索?

+0

http://stackoverflow.com/questions/20912864/how-can-i-figure-out-which-step-ive-just-executed-in-cucumbers-afterstep-hook將有所幫助。 – Purus 2016-02-08 14:53:47

回答

1

您可能會參考this example code,它與AfterStep掛鉤內的步驟索引配合使用。

實施例:

CALABASH_COUNT = {:step_index => 0, :step_line => nil} 

#TODO change this approach as it breaks scenario outlines 
Before do |scenario| 
    begin 
    CALABASH_COUNT[:step_index] = 0 
    CALABASH_COUNT[:step_line] = scenario.raw_steps[CALABASH_COUNT[:step_index]].line 
    rescue Exception => e 
    puts "#{Time.now} - Exception:#{e}" 
    end 
end 

AfterStep do |scenario| 
    CALABASH_COUNT[:step_index] = CALABASH_COUNT[:step_index] + 1 
    raw = scenario.raw_steps[CALABASH_COUNT[:step_index]] 
    CALABASH_COUNT[:step_line] = raw.line unless raw.nil? 
end 

Behave BDD framework,在Python允許更簡單step.name類型存取器,但其他人似乎更困難,要求計算當前步,然後使用索引來查找的上述技術來自原始步驟文本的名稱。

+1

適合我。傷心的是,鉤不會給你,但這是一個很好的工作。 – xrd 2014-10-10 19:34:49