尝试从资源包运行功能时出错。使用黄瓜测试

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

两个特征文件之间重复步骤定义。

第一个注册功能文件:

@smoke
Feature: Register | User enter his data in Registration Form
  Scenario: User Enter Valid Data in Registration Form
    Given Navigate To Registration Form
    When Fill Required Fields With Valid Data
    And Click Register Button
    Then Verify Success Registration

  Scenario: User Enter Invalid Data in Registration Form
      Given Navigate To Registration Form
      When Fill Required Fields With Invalid Data
      And Click Register Button
      Then Verify Unsuccessful Registration

用于登录的第二个功能文件:

@smoke
Feature: Login  |  User enter his data in Login Form
  Scenario: User Enter Valid Data in Login Form
    Given Navigate To Login Form
    When Fill Required Fields With Valid Data
    And Click Login Button
    Then Verify Success Login

  Scenario: User Enter Data in Login Form
    Given Navigate To Login Form
    When Fill Required Fields With Valid Email & Invalid Password
    And Click Login Button
    Then Verify Unsuccessful Login

  Scenario: User Enter Data in Login Form
    Given Navigate To Login Form
    When Fill Required Fields With Invalid Email & Valid Password
    And Click Login Button
    Then Verify Unsuccessful Login

  Scenario: User Enter Data in Login Form
    Given Navigate To Login Form
    When Leave Email & Password Field Empty
    And Click Login Button
    Then Verify Unsuccessful Login Empty

Runner 包中名为 TestRunner 的类是运行的主类:

@CucumberOptions(
        features ="src/main/resources",
        glue={"org/example/Step_Definition"},
        tags = "@smoke",
        monochrome = true,
        plugin = {"pretty",                    
                "html:target/cucumber.html",
                "json:target/cucumber.json",
                "junit:target/cukes.xml",
                "rerun:target/rerun.txt"},
        dryRun = false
)

    //extends Object. [AbstractTestNGCucumberTests] Runs cucumber every detected feature as separated test.
public class TestRunner extends AbstractTestNGCucumberTests {
}

注册和登录测试用例位于名为 Step_Definition 的包中

注册测试用例:

P01_nopRegister Register = new P01_nopRegister();


    //First Scenario

    @Given("Navigate To Registration Form")
    public void RegisterForm(){
        Register.Registerform().click();
    }

    @When("Fill Required Fields With Valid Data")
    public void Valid_Register(){
        Register.GenderMale().click();
        Register.FirstName().sendKeys("Youssef");
        Register.LastName().sendKeys("Benyameen");
        Select DayDrpList = new Select(Register.DayDropDownList());
        DayDrpList.selectByIndex(23);
        Select MonthDrpList = new Select(Register.MonthDropDownList());
        MonthDrpList.selectByVisibleText("October");
        Select YearDrpList = new Select(Register.YearDropDownList());
        YearDrpList.selectByValue("1999");
        Register.Email().sendKeys("[email protected]");
        Register.Password().sendKeys("Beny/000");
        Register.ConfirmPassword().sendKeys("Beny/000");
    }

    @And("Click Register Button")
    public void Register_button(){
        Register.RegisterButton().click();
    }

    @Then("Verify Success Registration")
    public void SuccessRegister(){
        Assert.assertTrue(Register.ContinueButton().isDisplayed());
    }

    //Second Scenario

    @When("Fill Required Fields With Invalid Data")
    public void InvalidData(){
        Register.GenderMale().click();
        Register.FirstName().sendKeys("Youssef");
        Register.LastName().sendKeys("Benyameen");
        Select DayDrpList = new Select(Register.DayDropDownList());
        DayDrpList.selectByIndex(23);
        Select MonthDrpList = new Select(Register.MonthDropDownList());
        MonthDrpList.selectByVisibleText("October");
        Select YearDrpList = new Select(Register.YearDropDownList());
        YearDrpList.selectByValue("1999");
        Register.Email().sendKeys("[email protected]");
        Register.Password().sendKeys("Beny/000");
        Register.ConfirmPassword().sendKeys("Beny/020");
    }

    @Then("Verify Unsuccessful Registration")
    public void Unsuccessful_Register(){
        String PasswordError = Register.ErrorMessage().getText();
        Assert.assertEquals(PasswordError,"The password and confirmation password do not match.");
    }

登录测试用例:

  P02_nopLogin Login = new P02_nopLogin();


    //First Scenario
    @Given("Navigate To Login Form")
    public void Login_form(){
        Login.LoginForm().click();
    }

    @When("Fill Required Fields With Valid Data")
    public void ValidLogin(){
        Login.Email().sendKeys("[email protected]");
        Login.Password().sendKeys("Beny/000");
    }

    @And("Click Login Button")
            public void Loginbutton(){
        Login.LoginButton().click();
    }

   @Then("Verify Success Login")
           public void SuccessLogin(){
       String LogoutText = Login.LogoutButton().getText();
       Assert.assertTrue(LogoutText.contains("Log out"));
   }

        //Second Scenario
    @When("Fill Required Fields With Valid Email & Invalid Password")
    public void Invalid_login_1(){
        Login.Email().sendKeys("[email protected]");
        Login.Password().sendKeys("Beny/77");
    }

    @Then("Verify Unsuccessful Login")
    public void UnsuccessLogin(){
        String ErrorMsg = Login.ErrorMessage().getText();
        Assert.assertTrue(ErrorMsg.contains("Login was unsuccessful."));
    }

    //Third Scenario

   @Then("Fill Required Fields With Invalid Email & Valid Password")
   public void Unsuccess_Login_2(){
       Login.Email().sendKeys("[email protected]");
       Login.Password().sendKeys("Beny/000");
   }


   //Fourth Scenario
    @When("Leave Email & Password Field Empty")
    public void Empty_Login(){
        Login.Email().sendKeys(" ");
        Login.Email().sendKeys(Keys.ENTER);
        Login.Password().sendKeys("");
    }

    @Then("Verify Unsuccessful Login Empty")
    public void AssertEmptyLogin(){
        String errMessage = Login.emptyErrorMessage().getText();
        Assert.assertEquals(errMessage,"Please enter your email");

    }

我已经更改了两个测试用例中sendkeys中使用的方法名称和数据,但错误仍然出现。

有人对这个问题有建议或建议吗?

这个问题可能是由于使用的 Cucumber testng 版本或类似的原因造成的吗?

testing automated-tests cucumber testng intellij-13
© www.soinside.com 2019 - 2024. All rights reserved.