我正在研究Cucumber Java项目,该项目还处于初期阶段。在步骤定义文件中编写代码时。我发现在步骤N中需要的数据仅在步骤N-1中存在,即在黄瓜测试步骤之间共享数据。由于该项目处于初始阶段。我认为实现setter()和getter()方法将对我有用,即是setter()我将设置变量的值并在需要此数据时调用getter()方法 请找到实际的实现。
StepDefinition:
@Given("^recent destination list$")
public void list_of_recent_destinations_is_non_empty() throws Throwable {
gm.appLaucher();
gm.setValue_searchAddressOrName_HomeScreen("Wemmel");
gm.click_selectAddress_HomeScreen();
gm.click_driveButton_OnMapScreen();
gm.click_clearRouteButton_OnMapScreen();
gm.setValue_searchAddressOrName_HomeScreen("Ukkel, Beersel,1180");
gm.click_selectAddress_HomeScreen();
gm.click_driveButton_OnMapScreen();
gm.click_clearRouteButton_OnMapScreen();
gm.setValue_searchAddressOrName_HomeScreen("Sint-Jansplein Brussel, 1000");
gm.click_selectAddress_HomeScreen();
gm.click_driveButton_OnMapScreen();
gm.click_clearRouteButton_OnMapScreen();
gm.click_mainMenuButton_OnMapScreen();
gm.tap_recentDestinationButton_OnMainMenuScreen();
gm.tap_editListButton_RecentDestinationScreen();
List<MobileElement> em1= gm.get_recentDestinaList_EditListScreen();
System.out.println("____________________________________________"+em1.size());
int numOfElement=em1.size()-2;
boolean status =em1.size()>0;
Assert.assertEquals(true,status);
}
@When("^user selects one or more $")
public void user_selects_one_or_more_recent_destinations() throws Exception {
List<MobileElement> em1= gm.get_recentDestinaList_EditListScreen();
System.out.println("____________________________________________"+em1.size());
Iterator<MobileElement> it=em1.iterator();
while(it.hasNext())
{
System.out.println(it.next().getText());
}
String str= gm.getIndividualElement_recentDestinationList_EditListScreen(2);
System.out.println(str+"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%");
}
@When("^user deletes address$")
public void user_deletes_selected_addresses() throws Exception {
gm.setValueForOtherSteps(gm.get_recentDestinaList_EditListScreen().size());
gm.deleteIndividualElememnt_recentDestinationList_EditListScreen(2);
}
@Then("^recent\\(s\\) is\\(are\\) removed from list$")
public void recent_destination_s_is_are_removed_from_list() throws Exception {
// Write code here that turns the phrase above into concrete actions
System.out.println(gm.getValueFromOtherStep()+"Intermidiate value from Step definition class");
int x=gm.getSize_recentDestinationList_EditListScreen();
System.out.println(x+"+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
String strLastElement=gm.getIndividualElement_recentDestinationList_EditListScreen(3);
String strSecondLast=gm.getIndividualElement_recentDestinationList_EditListScreen(2);
int y=gm.getSize_recentDestinationList_EditListScreen();
Assert.assertEquals(x, y);
// Assert.assertEquals(strLastElement, strSecondLast);
// gm.tap_editListButton_RecentDestinationScreen();
//
// gm.deleteAllElement_recentDestinationList_EditListScreen();
}
@Then("^recent desorted in temporal order$")
public void recent_destinations_list_is_sorted_in_temporal_order() throws Exception {
// Write code here that turns the phrase above into concrete actions
}
在上述gm是GMain类的对象,请找到以下实现
class GMain{
public void setValueForOtherSteps(Object obj) throws IOException {
System.out.println(obj+"Intermediate values to verify +++++++++++++++++++++++++++++++++++++++");
getValueFromOtherStep();
}
public Object getValueFromOtherStep()
{
if(getValue() instanceof Integer) {
System.out.println((Integer)getValue()+" test");
return (Integer) getValue();
}
else if (getValue() instanceof String)
{
return (String) getValue();
}
else if (getValue() instanceof Boolean)
{
return (Boolean) getValue();
}
else {
System.out.print(getValue());
return "";
}
}
因此,当我们从stepDefinition调用setValueForOtherSteps()时,控件进入GMain类方法public void setValueForOtherSteps(Object obj),但是为什么传输返回到调用方而不调用getValueFromOtherStep()方法
我知道这可能很愚蠢,但是可以提供任何帮助
谢谢