对于赛普拉斯黄瓜项目,我有 1 个功能文件 login.feature,其中有 2 个场景大纲
- 有效登录
- 登录无效
当我运行 login.feature 文件时。有效登录场景有一个检查点来验证我在主页上。这需要时间来验证,并且在几秒钟内,它会移动到下一个场景,导致第一个场景失败。
如果我一个一个地运行它们,没有什么是失败的。Cypress 使用自己的功能等待特定元素检查,然后移动到下一个元素。但在这里,它正在等待某个时间,并逐渐转向下一个场景。
登录功能
Feature: Login to Application
As a valid user I want to log in to the Application
@login
Scenario Outline: Valid Login
Given user open the login Page
When user enter a username "<userName>"
And user enter a password "<password>"
And user click the sign-in button
Then user should be able to login
Examples:
| userName | password |
| abc | ########### |
@login
Scenario Outline: Invalid Login
Given user open the login Page
When user enter a username "<userName>"
And user enter a password "<password>"
And user click the sign-in button
Then error should displayed as "<error_message>"
Examples:
| userName | password | error_message |
| admin | sd444-fdf-ffr | Unable to sign in |
login_steps.js
import { Given, When, And, Then } from "cypress-cucumber-preprocessor/steps";
import loginPage from "../pageObjects/pages/login_page";
before(() => {
cy.log("I will only run before the first scenario of login.feature");
});
beforeEach(() => {
cy.log("I will run before each Scenario of login.feature");
});
Given("user will run before all the scenarios", () => {
cy.log("Scenario - Started");
});
Given("user open the login Page", () => {
loginPage.visitLoginPage();
});
When("user enter a username {string}", (username) => {
loginPage.fillUsername(username);
});
And("user enter a password {string}", (password) => {
loginPage.fillPassword(password);
});
And("user click the sign-in button", () => {
loginPage.submitLoginDetails();
});
Then("user should be able to login", () => {
loginPage.checkLoginSuccess();
});
Then("error should displayed as {string}", (error_message) => {
loginPage.checkErrorMessage(error_message);
});
login_page.js
class loginPage {
static visitLoginPage() {
cy.visit('/');
cy.url().should('include', 'login');
}
static fillUsername(username) {
cy.get('#abc').type(username);
}
static fillPassword(password) {
cy.get('#def').type(password);
}
static submitLoginDetails() {
cy.get('[type="submit"]').click();
}
static checkLoginSuccess() {
cy.get('#large-device').should('be.visible');
}
static checkErrorMessage(error_message) {
cy.get('#form1').should('contain.text', error_message);
}
static loginWithValidCredentials(username, password) {
cy.visit('/');
cy.url().should('include', 'login')
cy.get('#abc').type(username);
cy.get('#def').type(password);
cy.get('[type="submit"]').click();
}
}
export default loginPage
让我知道更多信息。我是柏树黄瓜的新手。请帮帮我。