Optional oAuth activation in Cypress

This commit is contained in:
Annie Huang committed 2024-02-23 11:34:47 +08:00
1 parent ed142ab27b
commit b1a9a6102c
2 files changed
+19 -13

No files matched your search

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