Skip to content

Commit

Permalink
sample tests with and without camera permissions enabled; classic int…
Browse files Browse the repository at this point in the history
…egration (#6)
  • Loading branch information
sergiomartins8 authored Mar 26, 2024
1 parent 2978682 commit c7ace4b
Show file tree
Hide file tree
Showing 11 changed files with 2,859 additions and 750 deletions.
38 changes: 32 additions & 6 deletions .github/workflows/integration_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,52 @@ on:
push:

jobs:
test:
timeout-minutes: 30
studio-integration:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 18
- name: Create env file
env:
IS_CLASSIC_INTEGRATION: 'false'
API_TOKEN: ${{secrets.API_TOKEN}}
WORKFLOW_ID: ${{secrets.WORKFLOW_ID}}
SDK_TARGET_VERSION: ${{github.event.inputs.SDK_TARGET_VERSION}}
run: |
touch .env
echo IS_CLASSIC_INTEGRATION="$IS_CLASSIC_INTEGRATION" >> .env
echo API_TOKEN="$API_TOKEN" >> .env
echo WORKFLOW_ID="$WORKFLOW_ID" >> .env
- name: Install dependencies and build
run: npm ci && npm run build
- name: Install Playwright Browsers
run: npx playwright install --with-deps
- name: Install Playwright Chromium
run: npx playwright install --with-deps chromium
- name: Run Playwright tests
run: npm run e2e

classic-integration:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 18
- name: Create env file
env:
IS_CLASSIC_INTEGRATION: 'true'
API_TOKEN: ${{secrets.API_TOKEN}}
WORKFLOW_ID: ${{secrets.WORKFLOW_ID}}
SDK_TARGET_VERSION: ${{github.event.inputs.SDK_TARGET_VERSION}}
run: |
touch .env
echo IS_CLASSIC_INTEGRATION="$IS_CLASSIC_INTEGRATION" >> .env
echo API_TOKEN="$API_TOKEN" >> .env
echo WORKFLOW_ID="$WORKFLOW_ID" >> .env
- name: Install dependencies and build
run: npm ci && npm run build
- name: Install Playwright Chromium
run: npx playwright install --with-deps chromium
- name: Run Playwright tests
run: npm run e2e
5 changes: 2 additions & 3 deletions Onfido.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const fs = require('fs')
const { Onfido, Region } = require('@onfido/api')
const { config: configDotenv } = require('dotenv')
const fs = require('fs')

configDotenv()

Expand Down Expand Up @@ -34,8 +34,7 @@ async function createWorkflowRun(applicantId: string) {
}

async function writeEnvFile(sdkToken: string, workflowRunId: string) {
const envContent = `SDK_TOKEN=${sdkToken}\nWORKFLOW_RUN_ID=${workflowRunId}
`
const envContent = `SDK_TOKEN=${sdkToken}\nWORKFLOW_RUN_ID=${workflowRunId}`

fs.appendFileSync('.env', envContent, 'utf-8')
}
Expand Down
20 changes: 15 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
# WebViewAngular
A sample Angular native app integration with Onfido’s [Web SDK](https://documentation.onfido.com/sdk/web/), using webviews.

##
## Instructions

Create a `.env` file on the root of the project and set the following environment variables:

```
IS_CLASSIC_INTEGRATION=<true-or-false>
API_TOKEN=<your-api-token>
WORKFLOW_ID=<your-workflow-id>,
```

> Check other possible environment variables under [environment.ts](src/app/environments/environment.ts).
```shell
npm i
npm build
npm run start
npm run e2e
npm i # install dependencies
npm build # set other required environment variables on .env file
npm run start # start the web sdk
npm run e2e # run the e2e tests
```
105 changes: 105 additions & 0 deletions e2e/classic_integration.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import { chromium, expect, test } from '@playwright/test'

const getPage = async ({ withCameraPermissions = true }) => {
const args = []
const permissions = []

if (withCameraPermissions) {
args.push('--use-fake-ui-for-media-stream')
args.push('--use-fake-device-for-media-stream')
permissions.push('camera')
}

const browser = await chromium.launch({
args,
})
const page = await browser.newPage()

await page.context().grantPermissions(permissions)

// Mocking consents being given
await page.route('**/applicants/*/consents', async (route) => {
return route.fulfill({
body: JSON.stringify([]),
})
})

return page
}

test.describe('Classic integration', () => {
test.skip(
process.env.IS_CLASSIC_INTEGRATION === 'false',
'Skipping tests if not a classic integration'
)

test('without camera permissions', async () => {
const page = await getPage({ withCameraPermissions: false })

await page.goto('/')

await page
.frameLocator('iframe[name="onfido-document"]')
.locator('[data-qa="country-selector"]')
.click()

await page
.frameLocator('iframe[name="onfido-document"]')
.locator('span[role="option"]')
.first()
.click()

await page
.frameLocator('iframe[name="onfido-document"]')
.locator('[data-qa="passport"]')
.click()

await page
.frameLocator('iframe[name="onfido-document"]')
.locator('[data-qa="passport-guide-next-btn"]')
.click()

await page
.frameLocator('iframe[name="onfido-document"]')
.locator('[data-qa="enable-camera-btn"]')
.click()

await page
.frameLocator('iframe[name="onfido-document"]')
.locator('[data-screen="Recover"]')
.isVisible()
})

test('with camera permissions', async () => {
const page = await getPage({})

await page.goto('/')

await page
.frameLocator('iframe[name="onfido-document"]')
.locator('[data-qa="country-selector"]')
.click()

await page
.frameLocator('iframe[name="onfido-document"]')
.locator('span[role="option"]')
.first()
.click()

await page
.frameLocator('iframe[name="onfido-document"]')
.locator('[data-qa="passport"]')
.click()

await page
.frameLocator('iframe[name="onfido-document"]')
.locator('[data-qa="passport-guide-next-btn"]')
.click()

await expect(
page
.frameLocator('iframe[name="onfido-document"]')
.locator('[data-qa="enable-camera-btn"]')
).not.toBeVisible()
})
})
10 changes: 0 additions & 10 deletions e2e/smoke.spec.ts

This file was deleted.

17 changes: 17 additions & 0 deletions e2e/studio_integration.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { test, expect } from '@playwright/test'

test.describe('Studio integration', () => {
test.skip(
process.env.IS_CLASSIC_INTEGRATION === 'true',
'Skipping tests if not a Studio integration'
)

test('has title', async ({ page }) => {
await page.goto('/')
expect(
page
.frameLocator('iframe[name="onfido-welcome"]')
.getByText('Verify your identity')
).toBeTruthy()
})
})
Loading

0 comments on commit c7ace4b

Please sign in to comment.