Cucumber / JUnit - 当测试在循环内失败时如何继续?
Cucumber / JUnit - How to proceed when test failed inside a loop?
晚上好,
我调查了几个小时来找到以下问题的解决方案:
我正在使用 Eclipse、Cucumber、JUnit 和 Maven。
怎么可能得到一个单一的测试步骤将被标记为失败。我有可能使用 try-catch 和 Assert.fail() 使整个场景失败,但在循环中没有一个案例。
附上我的部分代码:
场景:
然后在页面执行登录
|455xxxxxx10|4xx0|
|455xxxxxx10|4xx0|
|455xxxxxx10|4xx0|
|455xxxxxx10|4xx0|
|455xxxxxx10|4xx0|
很有可能一个数字错了,整个场景就失败了?将这个单一案例标记为错误并再次执行循环会很棒。
List<String> credentials = dataTable.asList(String.class);
driver.get("URL");
sessionID = driver.manage().getCookieNamed("CookieName").toString();
for (int a=0, b=1; a<credentials.size() & b<=credentials.size(); a+=2, b+=2)
{
driver.findElement(By.linkText("LOGIN")).click();
wait = new WebDriverWait(driver, 60);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("/html/body/div[1]/header/nav/div/div/div/ul/li[2]/a/span")));```
我觉得你应该使用场景大纲。
Scenario Outline: Then Execute Login on Page
Given: "<User>" logs into the page
|User |
|455xxxxxxxxx|
|4xx0 |
|4xx0 |
这将 运行 任何用户(或您用来登录的任何用户)的每个测试场景作为单独的测试。因此,如果其中一种情况失败。您将能够看到哪个。
你应该使用情景大纲。尝试以下操作:
Feature: Login Feature - Verify if user is able to Login into the site.
Scenario Outline: Login as a authenticated user
Given user is on homepage
When user navigates to Login Page
Then I enter Username as "<username>" and Password as "<password>"
Examples:
|username |password|
|455xxxxx10|4xx0 |
|455xxxxx10|4xx0 |
P.S.: 注意关键词。你不能写
Feature: Login Feature
Verify if user is able to Login into the site
因为"Verify if user...."前没有关键字
晚上好,
我调查了几个小时来找到以下问题的解决方案: 我正在使用 Eclipse、Cucumber、JUnit 和 Maven。 怎么可能得到一个单一的测试步骤将被标记为失败。我有可能使用 try-catch 和 Assert.fail() 使整个场景失败,但在循环中没有一个案例。
附上我的部分代码:
场景: 然后在页面执行登录 |455xxxxxx10|4xx0| |455xxxxxx10|4xx0| |455xxxxxx10|4xx0| |455xxxxxx10|4xx0| |455xxxxxx10|4xx0|
很有可能一个数字错了,整个场景就失败了?将这个单一案例标记为错误并再次执行循环会很棒。
List<String> credentials = dataTable.asList(String.class);
driver.get("URL");
sessionID = driver.manage().getCookieNamed("CookieName").toString();
for (int a=0, b=1; a<credentials.size() & b<=credentials.size(); a+=2, b+=2)
{
driver.findElement(By.linkText("LOGIN")).click();
wait = new WebDriverWait(driver, 60);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("/html/body/div[1]/header/nav/div/div/div/ul/li[2]/a/span")));```
我觉得你应该使用场景大纲。
Scenario Outline: Then Execute Login on Page
Given: "<User>" logs into the page
|User |
|455xxxxxxxxx|
|4xx0 |
|4xx0 |
这将 运行 任何用户(或您用来登录的任何用户)的每个测试场景作为单独的测试。因此,如果其中一种情况失败。您将能够看到哪个。
你应该使用情景大纲。尝试以下操作:
Feature: Login Feature - Verify if user is able to Login into the site.
Scenario Outline: Login as a authenticated user
Given user is on homepage
When user navigates to Login Page
Then I enter Username as "<username>" and Password as "<password>"
Examples:
|username |password|
|455xxxxx10|4xx0 |
|455xxxxx10|4xx0 |
P.S.: 注意关键词。你不能写
Feature: Login Feature
Verify if user is able to Login into the site
因为"Verify if user...."前没有关键字