功能文件示例表中的所有场景都不起作用

问题描述 投票:0回答:1

我是 Cucumber 和学习自动化测试的新手,这里我有一个示例表,但我无法运行所有表内容,它只显示 1 个场景(1 个通过)。请帮忙!!

演示.功能

Feature: Test login functionality

Scenario Outline: Check login is successful with valid credentials
Given browser is open
And user is on login page
When user enters <username> and <password>
And user clicks on login
Then user is navigated to the home page

Examples: 
  | username | password    |
  | student  | Password123 |
  | Raghav   | pass123     |
  | dil      | dill2       |

此表的数据仅使用第一个用户名和密码运行一次,而不是运行 3 次,整个程序仅执行一次而不是 3 次

步骤定义:演示步骤


import java.util.concurrent.TimeUnit;


import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

import io.cucumber.java.en.*;

public class LoginDemoSteps {
    
    WebDriver driver = null;
    
    @Given("browser is open")
    public void browser_is_open() {
        
        System.out.println("inside step - browser open");
        
        String projectPath = System.getProperty("user.dir");//will get the location of the current project folder
        
        System.out.println(projectPath);
        
        System.setProperty("webdriver.chrome.driver",projectPath+"/src/test/resources/drivers/chromedriver.exe");
        
        driver = new ChromeDriver();
        
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);//overall time to wait for all elements to load
        driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);//wait for the page to load
        //if page is loaded these 2 statements are skipped

    }

    @And("user is on login page")
    public void user_is_on_login_page() {
        driver.navigate().to("https://practicetestautomation.com/practice-test-login/");
    }

    @When("^user enters (.*) and (.*)$")
    public void user_enters_username_and_password(String username, String password) throws InterruptedException {
        driver.findElement(By.id("username")).sendKeys(username);
        driver.findElement(By.id("password")).sendKeys(password);
        
        Thread.sleep(2000);

    }
    
    @And("user clicks on login")
    public void user_clicks_on_login() {
        //id=submit
        driver.findElement(By.id("submit")).click();

    }

    @Then("user is navigated to the home page")
    public void user_is_navigated_to_the_home_page() throws InterruptedException {
        driver.getPageSource().contains("Logged In Successfully");//contains this text on the next page
        System.out.println("Test Successful");
        Thread.sleep(2000);
        driver.close();
        driver.quit();
    }

}

Runner类:TestRunner.java

package StepDefinitions;

import org.junit.runner.RunWith;

import io.cucumber.junit.CucumberOptions;
import io.cucumber.junit.Cucumber;

//This class is used to run all the automated steps

@RunWith(Cucumber.class)
@CucumberOptions(features = "src/test/resources/Features", glue = { "StepDefinitions" }, // Glue code
        monochrome = true, plugin = { "pretty", "html:target/HTMLReports/report.html",
                "json:target/JSONReports/report.json", "junit:target/JUNITReports/report.xml" } // reports
        )
public class TestRunner {

}

输出:

Feb 28, 2024 1:59:26 PM cucumber.api.cli.Main run
WARNING: You are using deprecated Main class. Please use io.cucumber.core.cli.Main

Scenario: Check login is successful with valid credentials # src/test/resources/Features/LoginDemo.feature:3
inside step - browser open
C:\Users\..\CucumberJava2
  Given browser is open                                    # StepDefinitions.LoginDemoSteps.browser_is_open()
  And user is on login page                                # StepDefinitions.LoginDemoSteps.user_is_on_login_page()
  When user enters username and password                   # StepDefinitions.LoginDemoSteps.user_enters_username_and_password()
  And user clicks on login                                 # StepDefinitions.LoginDemoSteps.user_clicks_on_login()
Test Successful
Feb 28, 2024 1:59:33 PM org.openqa.selenium.remote.http.WebSocket$Listener onError
WARNING: Connection reset
java.net.SocketException: Connection reset
    at java.base/sun.nio.ch.SocketChannelImpl.throwConnectionReset(SocketChannelImpl.java:394)
    at java.base/sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:426)
    at java.net.http/jdk.internal.net.http.SocketTube.readAvailable(SocketTube.java:1170)
    at java.net.http/jdk.internal.net.http.SocketTube$InternalReadPublisher$InternalReadSubscription.read(SocketTube.java:833)
    at java.net.http/jdk.internal.net.http.SocketTube$SocketFlowTask.run(SocketTube.java:181)
    at java.net.http/jdk.internal.net.http.common.SequentialScheduler$SchedulableTask.run(SequentialScheduler.java:230)
    at java.net.http/jdk.internal.net.http.common.SequentialScheduler.runOrSchedule(SequentialScheduler.java:303)
    at java.net.http/jdk.internal.net.http.common.SequentialScheduler.runOrSchedule(SequentialScheduler.java:256)
    at java.net.http/jdk.internal.net.http.SocketTube$InternalReadPublisher$InternalReadSubscription.signalReadable(SocketTube.java:774)
    at java.net.http/jdk.internal.net.http.SocketTube$InternalReadPublisher$ReadEvent.signalEvent(SocketTube.java:957)
    at java.net.http/jdk.internal.net.http.SocketTube$SocketFlowEvent.handle(SocketTube.java:253)
    at java.net.http/jdk.internal.net.http.HttpClientImpl$SelectorManager.handleEvent(HttpClientImpl.java:979)
    at java.net.http/jdk.internal.net.http.HttpClientImpl$SelectorManager.lambda$run$3(HttpClientImpl.java:934)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
    at java.net.http/jdk.internal.net.http.HttpClientImpl$SelectorManager.run(HttpClientImpl.java:934)

  Then user is navigated to the home page                  # StepDefinitions.LoginDemoSteps.user_is_navigated_to_the_home_page()

1 Scenarios (1 passed)
5 Steps (5 passed)
0m6.839s

已弃用的主类不是问题

cucumber cucumber-jvm cucumber-java cucumber-junit
1个回答
0
投票

问题解决了!!该文件不同,但它将从另一个文件夹运行该文件的另一个版本,通过重命名并将其作为 junit test 运行来修复它

© www.soinside.com 2019 - 2024. All rights reserved.