baseUrl in env and fix success user

This commit is contained in:
chiayin
2023-02-04 11:35:26 +08:00
parent e3bd32383e
commit 9dc25b9b99
3 changed files with 11 additions and 5 deletions

View File

@@ -4,6 +4,5 @@ const { defineConfig } = require("cypress");
module.exports = defineConfig({
e2e: {
specPattern: "cypress/e2e/**/*.{cy,spec}.{js,jsx,ts,tsx}",
// baseUrl: "" // 設定方式請看內部文件
},
});

View File

@@ -1,8 +1,9 @@
// 之後要優化: 每一個測試步驟要分開寫,不寫在同一個 it 裡面、將測試寫成 report 輸出成 html(嘗試)
// 之後要優化: 每一個測試步驟要分開寫,不寫在同一個 it 裡面、將測試寫成 report 輸出成 html(嘗試)、功能模組化
const baseUrl = Cypress.env('baseUrl');
describe("Login to Logout", () => {
before(() => {
cy.visit("/"); // 測試可否進入網站
cy.visit(baseUrl); // 測試可否進入網站
cy.contains("h2", "LOGIN"); // 是否轉址到 /login 並顯示畫面
cy.url().should('include', 'login') // url path 要有 'Login',確定進入 login page
})
@@ -23,9 +24,11 @@ describe("Login to Logout", () => {
});
// 正確帳密登入
cy.get('#account').clear().type(Cypress.env('user').username);
cy.get('#password').clear().type(Cypress.env('user').password);
cy.get('#account').clear().type(` ${Cypress.env('user').username} `);
cy.get('#password').clear().type(` ${Cypress.env('user').password} `);
cy.get('.btn-lg').click();
cy.get('#account').should('have.value', Cypress.env('user').username);
cy.get('#password').should('have.value', Cypress.env('user').password);
cy.get('form').submit(); // 選取 form 表單並發送
// 轉址到 files 頁

View File

@@ -15,6 +15,10 @@
// Import commands.js using ES2015 syntax:
import "./commands";
Cypress.on('uncaught:exception', (err, runnable) => {
// returning false here prevents Cypress from failing the test
return false
})
// Alternatively you can use CommonJS syntax:
// require('./commands')