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 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,
},
})
+13 -11
View File
@@ -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')