2013-12-16 45 views
2

我想寫如下的jBehave步驟;寫jBehave示例步驟

@When("I perform <someAction> on $panel") 

所以我可以有步驟,像

i. When I perform Action1 on Panel1 
ii. When I perform Action2 on Panel2 

現在你可以看到,這一步有佔位

1. someAction which actually comes via meta 
2. $panel which is taken from the step text in the story 

的混合但這不是由我的工作和我空指針異常

它的工作原理如果我寫

@When("I perform <someAction> on Panel1") 

即我不能在同一步驟中使用2個佔位符。

但由於這是一個通用步驟,我不想硬編碼任何值。

回答

0

是的,你可以

@When("I perform <someAction> on *panel*") 
public void perform(@Named("panel") String panelId){ 

} 

,並從現在開始,我建議按名稱識別的所有元素,使用jemmy您可以使用new NameComponentChooser(panelId)

+0

其實我需要2個參數的方法; panelId和someAction – testndtv

+0

@Named參數沒有限制,請檢查http://jbehave.org/reference/stable/parameter-injection.html – RamonBoza

0

請您都參數之前使用$符號。然後,將處理示例參數以及正常參數。

@When("I perform $action on $panel") 
public void performAction(String action, String panel){ 
}