데이터를 기반으로 동적 테스트의 모든 측면을 구성하는것
우선 로그인 양식을 예로 테스트를 할때
cy.get("username").type("jdoe")
cy.get("password").type("password123")
이런 형태로 유저네임과 패스워드를 입력한다.
const users = [
{
username: "John",
password: "password123",
},
{
username: "Jane",
password: "password123",
},
]
cy.get("username").type(users[0].username)
cy.get("password").type(users[0].password)
.fixture() 를 사용해서도 사용한다.
cy.fixture("users.json").as("usersData")
cy.get("username").type(usersData[0].username)
cy.get("password").type(usersData[0].password)
아래는 API, DB 등 데이터를 사용하는 테스트 코드이다.
describe("Notifications", () => {
const ctx = {}
beforeEach(() => {
// ...
cy.database("filter", "users").then((users) => {
ctx.userA = users[0]
ctx.userB = users[1]
ctx.userC = users[2]
})
})
it("allows users to login", () => {
cy.get("username").type(ctx.userA.userName)
cy.get("password").type(ctx.userA.password)
})
})
여기서 사용된 .database() 는 커스텀 명령어이며, 예제 템플릿에서는 확인이 가능하다.
여기서는 직접 DB에 연결하는 부분 같은데, 필요할때 자세히 찾아보고 정리가 필요한 부분이다.