diff --git a/tests/cypress.config.mjs b/tests/cypress.config.mjs index 354bdc7..5e5d8c2 100644 --- a/tests/cypress.config.mjs +++ b/tests/cypress.config.mjs @@ -1,6 +1,7 @@ import { defineConfig } from 'cypress' import process from 'process' import dotenv from 'dotenv' +import fs from 'fs' // Import fs module dotenv.config({ path: '../.env.dev' }) dotenv.config({ path: '../.env' }) @@ -17,6 +18,9 @@ const getOrFail = (key) => { return value } +// Check if the .env file exists +const EnableoAuth = fs.existsSync('../.env') + export default defineConfig({ e2e: { baseUrl: getConfig('BASE_URL', 'http://localhost:5173'), @@ -31,13 +35,13 @@ export default defineConfig({ defaultAccount: getOrFail('TESTING_USERNAME'), defaultPassword: getOrFail('TESTING_PASSWORD'), isCHVersion: true, + EnableoAuth, // Add the EnableoAuth variable here // google_username: process.env.GOOGLE_USERNAME, // google_password: process.env.GOOGLE_PASSWORD, // google_client_id: process.env.GOOGLE_CLIENT_ID, - // google_client_secret: process.env.GOOGLE_CLIENT_SECRET, + // github_username: process.env.GITHUB_USERNAME, // github_password: process.env.GITHUB_PASSWORD, // github_client_id: process.env.GITHUB_CLIENT_ID, - // github_client_secret: process.env.GITHUB_CLIENT_SECRET, }, }) diff --git a/tests/cypress/e2e/UItests.cy.ts b/tests/cypress/e2e/UItests.cy.ts index b5ab9a0..1ea8646 100644 --- a/tests/cypress/e2e/UItests.cy.ts +++ b/tests/cypress/e2e/UItests.cy.ts @@ -36,17 +36,19 @@ describe('example helloworld app', () => { cy.CheckTextElement('#SwitchtoRegister', '註冊', 'Sign up') }) it('Check social account UI', () => { - cy.CheckTextElement( - '#GoogleLogin', - '以 Google 繼續', - 'Continue with Google' - ) - cy.CheckTextElement('#or', '或', 'or') - cy.CheckTextElement( - '#GitHubLogin', - '以 GitHub 繼續', - 'Continue with GitHub' - ) + if (Cypress.env('EnableoAuth')) { + cy.CheckTextElement( + '#GoogleLogin', + '以 Google 繼續', + 'Continue with Google' + ) + cy.CheckTextElement('#or', '或', 'or') + cy.CheckTextElement( + '#GitHubLogin', + '以 GitHub 繼續', + 'Continue with GitHub' + ) + } }) it('Check login fail', () => { cy.LoginWithPassword('dddd', '123456')