Skip to content

Commit

Permalink
Fix issue with adding env file during image build (#148)
Browse files Browse the repository at this point in the history
* fix: fixed the context path

* fix: updated hostname var to remove quotes

* fix: removing quotes on hostname and always executing upload results step

* fix: adding env file to docker run command

* fix: pass env file through volume

* fix: generating env file before build

* fix: updated logic to click on continue button

* fix: waiting before clicking on continue button

* fix: removed this reference

* fix: updated timeout function

* chore: add new env var for timeout setting

* fix: added waitfornavigation

* fix: clicking twice to make sure its clicked

* fix: using native function to click the button

* fix: using incognito browser for tests

* fix: using good practices

* fix: using timeout for initial goto website

* fix: using google chrome instead of chromium

* fix: removing screenshots code for testing

* fix: removed redundant code

* fix: running jobs parrallely and updated readme
  • Loading branch information
NithinKuruba authored Jul 27, 2022
1 parent 684d7ee commit f7f7a91
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 22 deletions.
15 changes: 9 additions & 6 deletions .github/workflows/siteminder-tests.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Run Siteminder Tests to Validate SAML Payload
name: Run siteminder tests to validate saml payload

on:
workflow_dispatch:
Expand Down Expand Up @@ -27,9 +27,9 @@ jobs:
id: set-matrix
run: |
datacenters=$(echo "${{ secrets.SITEMINDER_TESTS_DATACENTERS }}" | jq '."${{ github.event.inputs.environment }}".datacenters')
hostname=$(echo "${{ secrets.SITEMINDER_TESTS_DATACENTERS }}" | jq '."${{ github.event.inputs.environment }}".hostname')
hostname=$(echo "${{ secrets.SITEMINDER_TESTS_DATACENTERS }}" | jq -r '."${{ github.event.inputs.environment }}".hostname')
echo ::set-output name=datacenters::{\"include\":$(echo $datacenters)}
echo ::set-output name=hostname::$(echo $hostname)
echo ::set-output name=hostname::$(echo "$hostname")
run-siteminder-tests:
runs-on: ubuntu-20.04
Expand All @@ -42,6 +42,10 @@ jobs:
- uses: actions/setup-node@v3
with:
node-version: 16
- name: Generate env file
run: |
cd ${{ github.workspace }}/siteminder-tests
echo "${{ secrets.SITEMINDER_TESTS_ENV }}" | base64 --decode > .env
- name: Set up docker buildx
uses: docker/setup-buildx-action@v2
- name: Cache docker layers
Expand All @@ -53,11 +57,10 @@ jobs:
- name: Build docker image
uses: docker/build-push-action@v3
with:
context: ./siteminder-tests
context: siteminder-tests/
push: false
load: true
tags: siteminder-tests
file: Dockerfile
cache-from: type=local,src=/tmp/.buildx-test-cache
cache-to: type=local,dest=/tmp/.buildx-test-cache-new
- name: Move cache
Expand All @@ -67,13 +70,13 @@ jobs:
- name: Run siteminder tests
run: |
cd ${{ github.workspace }}/siteminder-tests
echo "${{ secrets.SITEMINDER_TESTS_ENV }}" | base64 --decode > .env
docker run --rm -e ENVIRONMENT=${{ github.event.inputs.environment }} \
-e CLUSTER=${{ github.event.inputs.cluster }} \
-v $(pwd)/results:/app/results \
--add-host=${{ needs.matrix-prep.outputs.hostname }}:${{ matrix.ip }} \
siteminder-tests
- name: Upload test results
if: always()
uses: actions/upload-artifact@v2
with:
name: ${{ github.event.inputs.cluster }}-${{ github.event.inputs.environment }}-${{ matrix.name }}-results
Expand Down
12 changes: 12 additions & 0 deletions siteminder-tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,18 @@ Executes all the tests and generates screenshots under `results/assets`

Executes all the tests and generates screenshots and html report under `results` directory

**Note**: To run the tests on browser visually, update `beforeEach` hook in `./tests/index.test.js` file as shown below

```js
beforeEach(async function () {
browser = await puppeteer.launch({
headless: false,
});
page = await browser.newPage();
await page.setViewport({ width: 800, height: 600 });
});
```

### Docker

- Create `.env`
Expand Down
7 changes: 3 additions & 4 deletions siteminder-tests/tests/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,24 @@ const { testsite, screenShotsDir } = require('../util');
const { idir_config, bceid_basic_config, bceid_business_config, fetchSsoUrl } = require('../config');
const assert = require('assert');
const { describe, it, beforeEach, afterEach } = require('mocha');
const timeout = process.env.TIMEOUTSETTING ?? 3000;
const addContext = require('mochawesome/addContext');

describe('siteminder test suite', function () {
let browser;
let page;

beforeEach(async function () {
browser = await puppeteer.launch({
headless: true,
args: ['--disable-gpu', '--disable-dev-shm-usage', '--disable-setuid-sandbox', '--no-sandbox'],
});
page = await browser.newPage();
await page.setViewport({ width: 800, height: 600 });
});

afterEach(async function () {
await page.waitForTimeout(timeout);
await page.waitForTimeout(process.env.TIMEOUTSETTING);
await page.screenshot({ path: `${screenShotsDir}/${this.currentTest.title}.png` });
await page.waitForTimeout(timeout);
await page.waitForTimeout(process.env.TIMEOUTSETTING);
await page.close();
await browser.close();
addContext(this, `assets/${this.currentTest.title}.png`);
Expand Down
21 changes: 9 additions & 12 deletions siteminder-tests/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,27 +34,24 @@ module.exports = {
screenShotsDir,
testsite: async function (website, idp_username, idp_password, test_name, page) {
const siteminder_values = {};
await page.goto(website, { timeout: 0, waitUntil: 'domcontentloaded' });
await page.waitForSelector('title');
await page.waitForSelector('input[name=user]');
await page.type('#user', idp_username);
await page.type('#password', idp_password);
await page.keyboard.press('Enter');

await page.waitForTimeout(1000);
await page.goto(website);
await page.waitForNavigation();
await page.waitForSelector('title');

await page.waitForSelector('input[name=user]');
await page.type('#user', idp_username);
await page.type('#password', idp_password);

await page.keyboard.press('Enter');

const isIDIR = test_name.indexOf('IDIR') > -1;

if (!isIDIR) {
await page.waitForSelector('input[type=submit]');
const continueButton = await page.$('input[type=submit]');
await continueButton.evaluate((continueButton) => continueButton.click());
await page.waitForTimeout(1000);
await page.waitForSelector('input[value=Continue]');
await page.evaluate(() => {
const $button = document.querySelector('input[value=Continue]');
$button.click();
});
}

return new Promise((resolve) => {
Expand Down

0 comments on commit f7f7a91

Please sign in to comment.