diff --git a/cypress.config.js b/cypress.config.js index 10fbd84..d5c3e80 100644 --- a/cypress.config.js +++ b/cypress.config.js @@ -4,6 +4,5 @@ const { defineConfig } = require("cypress"); module.exports = defineConfig({ e2e: { specPattern: "cypress/e2e/**/*.{cy,spec}.{js,jsx,ts,tsx}", - // baseUrl: "" // 設定方式請看內部文件 }, }); diff --git a/cypress/e2e/loginToLogout.cy.js b/cypress/e2e/loginToLogout.cy.js index ca4da0e..36addb9 100644 --- a/cypress/e2e/loginToLogout.cy.js +++ b/cypress/e2e/loginToLogout.cy.js @@ -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 頁 diff --git a/cypress/support/e2e.js b/cypress/support/e2e.js index d076cec..5c4fdfb 100644 --- a/cypress/support/e2e.js +++ b/cypress/support/e2e.js @@ -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')