baseUrl in env and fix success user
This commit is contained in:
@@ -4,6 +4,5 @@ const { defineConfig } = require("cypress");
|
|||||||
module.exports = defineConfig({
|
module.exports = defineConfig({
|
||||||
e2e: {
|
e2e: {
|
||||||
specPattern: "cypress/e2e/**/*.{cy,spec}.{js,jsx,ts,tsx}",
|
specPattern: "cypress/e2e/**/*.{cy,spec}.{js,jsx,ts,tsx}",
|
||||||
// baseUrl: "" // 設定方式請看內部文件
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
// 之後要優化: 每一個測試步驟要分開寫,不寫在同一個 it 裡面、將測試寫成 report 輸出成 html(嘗試)
|
// 之後要優化: 每一個測試步驟要分開寫,不寫在同一個 it 裡面、將測試寫成 report 輸出成 html(嘗試)、功能模組化
|
||||||
|
const baseUrl = Cypress.env('baseUrl');
|
||||||
|
|
||||||
describe("Login to Logout", () => {
|
describe("Login to Logout", () => {
|
||||||
before(() => {
|
before(() => {
|
||||||
cy.visit("/"); // 測試可否進入網站
|
cy.visit(baseUrl); // 測試可否進入網站
|
||||||
cy.contains("h2", "LOGIN"); // 是否轉址到 /login 並顯示畫面
|
cy.contains("h2", "LOGIN"); // 是否轉址到 /login 並顯示畫面
|
||||||
cy.url().should('include', 'login') // url path 要有 'Login',確定進入 login page
|
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('#account').clear().type(` ${Cypress.env('user').username} `);
|
||||||
cy.get('#password').clear().type(Cypress.env('user').password);
|
cy.get('#password').clear().type(` ${Cypress.env('user').password} `);
|
||||||
cy.get('.btn-lg').click();
|
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 表單並發送
|
cy.get('form').submit(); // 選取 form 表單並發送
|
||||||
|
|
||||||
// 轉址到 files 頁
|
// 轉址到 files 頁
|
||||||
|
|||||||
@@ -15,6 +15,10 @@
|
|||||||
|
|
||||||
// Import commands.js using ES2015 syntax:
|
// Import commands.js using ES2015 syntax:
|
||||||
import "./commands";
|
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:
|
// Alternatively you can use CommonJS syntax:
|
||||||
// require('./commands')
|
// require('./commands')
|
||||||
|
|||||||
Reference in New Issue
Block a user