在 Cucumber Scenario Outline 上的示例表上是否可以有一个空值?

2022-01-23 00:00:00 selenium cucumber java

Here is my example table on my scenario outline, some does not have value, is this possible?

Examples:

|ID   | UserName   | Password  | Contact1 | Number       |

|ID1  | username1  | password1 | Phone    | 111 222 4444 |

|ID2  | username2  | password2 |          |              |

|ID3  | username3  | password3 | Email    | a@a.com      |

|ID4  | username4  | password4 |          |              |

解决方案

The empty value will be considered a String if the feature step looks something like this:

Given ...
When I enter my "<Username>" and "<Password>"
And I enter my "<Contact>"
And I enter my "<Number>"
Then ...

You can manage the empty string inside the step definition:

@When("^I enter my "([^"]*)"$")
public void I_enter_my(String contact) throws Throwable {
    // Handle empty string as null
    throw new PendingException();
}

Just an exmple, not sure if the code will work. Hope it helps.

相关文章