From c0a1f5608326314e3a97f0298adb54715b2a64da Mon Sep 17 00:00:00 2001 From: heshan Date: Sun, 5 Jan 2025 09:27:42 +0530 Subject: [PATCH] add env --- .github/workflows/cypress.yml | 27 +++++++++++++++++---------- cypress.config.js | 11 +++++++---- package-lock.json | 15 ++++++++++++++- package.json | 3 ++- 4 files changed, 40 insertions(+), 16 deletions(-) diff --git a/.github/workflows/cypress.yml b/.github/workflows/cypress.yml index 1d1f8bb..62cd046 100644 --- a/.github/workflows/cypress.yml +++ b/.github/workflows/cypress.yml @@ -24,39 +24,46 @@ jobs: with: node-version: '20' - # Step 3: Install dependencies + # Step 3: Inject environment variables from GitHub Secrets + - name: Set environment variables from GitHub Secrets + run: | + echo "CYPRESS_baseUrl=${{ secrets.CYPRESS_baseUrl }}" >> $GITHUB_ENV + echo "CYPRESS_baseUrlAPI=${{ secrets.CYPRESS_baseUrlAPI }}" >> $GITHUB_ENV + echo "CYPRESS_allureResultsPath=${{ secrets.CYPRESS_allureResultsPath }}" >> $GITHUB_ENV + + # Step 4: Install dependencies - name: Install dependencies run: | npm ci npx cypress install # Ensure Cypress is installed - # Step 4: Set up Allure commandline + # Step 5: Set up Allure commandline - name: Set up Allure commandline run: npm install -g allure-commandline - # Step 5: Install additional dependencies for Allure and Cypress + # Step 6: Install additional dependencies for Allure and Cypress - name: Install additional dependencies run: | npm install mocha-allure-reporter allure-cypress --save-dev npm install @bahmutov/cypress-esbuild-preprocessor @badeball/cypress-cucumber-preprocessor cypress-file-upload --save-dev - # Step 6: Run Cypress tests and generate Allure results (ensure it doesn't fail the workflow) + # Step 7: Run Cypress tests and generate Allure results - name: Run Cypress tests run: | npx cypress run --reporter mocha-allure-reporter --reporter-options allureResults=allure-results || true echo "Cypress tests completed (even with failures)" - - # Step 7: Always generate Allure report, even if tests failed + + # Step 8: Generate Allure report (even if tests fail) - name: Generate Allure report run: | allure generate allure-results --clean - if: always() # Ensures it runs even if the previous step fails + if: always() # Ensures this step runs even if the previous step fails - # Step 8: Deploy Allure Report to GitHub Pages + # Step 9: Deploy Allure Report to GitHub Pages - name: Deploy Allure Report to GitHub Pages uses: peaceiris/actions-gh-pages@v3 with: personal_token: ${{ secrets.GITHUB_TOKEN }} - publish_dir: ./allure-report # Folder where the Allure report is generated - publish_branch: gh-pages # Deploy to gh-pages branch + publish_dir: ./allure-report # Folder where the Allure report is generated + publish_branch: gh-pages # Deploy to gh-pages branch if: always() # Ensures this step runs even if tests fail diff --git a/cypress.config.js b/cypress.config.js index 0248369..6866db3 100644 --- a/cypress.config.js +++ b/cypress.config.js @@ -1,3 +1,6 @@ +// cypress.config.js +require("dotenv").config(); // Load environment variables from .env + const { defineConfig } = require("cypress"); const createBundler = require("@bahmutov/cypress-esbuild-preprocessor"); const { @@ -27,11 +30,11 @@ module.exports = defineConfig({ e2e: { specPattern: "**/*.feature", setupNodeEvents, - baseUrl: "https://opensource-demo.orangehrmlive.com/", - baseUrlAPI: "http://localhost:7081", + baseUrl: process.env.CYPRESS_baseUrl, + baseUrlAPI: process.env.CYPRESS_baseUrlAPI, chromeWebSecurity: false, env: { - allureResultsPath: "cypress/results/allure", + allureResultsPath: process.env.CYPRESS_allureResultsPath, }, }, -}); +}); diff --git a/package-lock.json b/package-lock.json index bc3582e..b4268ca 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,8 @@ "version": "1.0.0", "license": "ISC", "dependencies": { - "cypress-xpath": "^2.0.1" + "cypress-xpath": "^2.0.1", + "dotenv": "^16.4.7" }, "devDependencies": { "@badeball/cypress-cucumber-preprocessor": "^21.0.3", @@ -2977,6 +2978,18 @@ "node": ">=8" } }, + "node_modules/dotenv": { + "version": "16.4.7", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.4.7.tgz", + "integrity": "sha512-47qPchRCykZC03FhkYAhrvwU4xDBFIj1QPqaarj6mdM/hgUzfPHcpkHJOn3mJAufFeeAxAzeGsr5X0M4k6fLZQ==", + "license": "BSD-2-Clause", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://dotenvx.com" + } + }, "node_modules/dunder-proto": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz", diff --git a/package.json b/package.json index 4deee51..d6ff3e7 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ "mocha-allure-reporter": "^1.4.0" }, "dependencies": { - "cypress-xpath": "^2.0.1" + "cypress-xpath": "^2.0.1", + "dotenv": "^16.4.7" } }