我正在尝试使用数据表循环多个场景,但我的步骤定义没有从数据表获取值
功能文件:
Scenario Outline: Try login with invalid <username> and <password> should throw an error <message>
Given I am on the login screen.
When I login with a <username> and <password>
Then the system should throw a relevant error <message>
Example:
| username | password | message |
| aminster | test@12 | Invalid Login. Try again. |
| s | 3 | Invalid Login. Try again. |
我想在多个场景下验证登录屏幕上的错误是否存在无效数据
以下是我的步骤定义
Given("I am on the login screen.", () => {
cy.visit("https://demotest.com/login#login");
cy.wait(1000);
});
When(/^I login with a (.+) and (.+)$/, (username, password) => {
cy.get('input[id="login_email"]').type(username);
cy.get('input[id="login_password"]').type(password);
cy.get('button[type="submit"]').eq(0).click();
cy.wait(5000);
});
Then(/^the system should throw a relevant error (.+)$/, (message) => {
cy.get('button[type="submit"]').eq(0).should('include', message)
})
但无法从数据表中获取用户名、密码和消息的值。
您的特征文件和步骤定义需要更新才能使场景大纲发挥作用。
功能文件:
Scenario Outline: Try login with invalid <username> and <password> should throw an error <message>
Given I am on the login screen.
When I login with a <username> and <password>
Then the system should throw a relevant error <message>
Examples:
| username | password | message |
| "aminster" | "test@12" | "Invalid Login. Try again." |
| "s" | "3" | "Invalid Login. Try again." |
步骤定义文件:
Given("I am on the login screen.", () => {
cy.visit("https://demotest.com/login#login");
cy.wait(1000);
});
When("I login with a {string} and {string}", (username, password) => {
cy.get('input[id="login_email"]').type(username);
cy.get('input[id="login_password"]').type(password);
cy.get('button[type="submit"]').eq(0).click();
cy.wait(5000);
});
Then("the system should throw a relevant error {string}", (message) => {
cy.get('button[type="submit"]').eq(0).should('include', message)
})