-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initialize e2e tests with playwright
- Loading branch information
Showing
9 changed files
with
179 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ node_modules | |
dist | ||
out | ||
.gitignore | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ dist | |
out | ||
.DS_Store | ||
*.log* | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ pnpm-lock.yaml | |
LICENSE.md | ||
tsconfig.json | ||
tsconfig.*.json | ||
.env |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// playwright.config.js | ||
module.exports = { | ||
use: { | ||
headless: false | ||
}, | ||
projects: [ | ||
{ | ||
name: 'electron', | ||
use: { | ||
browserName: 'chromium', | ||
channel: 'chrome', | ||
launchOptions: { | ||
args: ['--no-sandbox'] | ||
} | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"status": "passed", | ||
"failedTests": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { _electron as electron } from 'playwright' | ||
import { test, expect } from '@playwright/test' | ||
import path from 'path' | ||
import { execSync } from 'child_process' | ||
import dotenv from 'dotenv' | ||
|
||
dotenv.config() | ||
|
||
test.describe('Electron app', () => { | ||
let electronApp | ||
|
||
test.beforeAll(async () => { | ||
// Build the application before running the tests | ||
execSync('npm run build', { stdio: 'inherit' }) | ||
|
||
// Path to the built Electron app | ||
const appPath = path.join( | ||
__dirname, | ||
'..', | ||
'dist', | ||
'mac-arm64', | ||
'DHIS2 Downloader.app', | ||
'Contents', | ||
'MacOS', | ||
'DHIS2 Downloader' | ||
) | ||
electronApp = await electron.launch({ | ||
executablePath: appPath | ||
}) | ||
}) | ||
|
||
// Remove the test.afterAll hook to prevent the app from closing | ||
test.afterAll(async () => { | ||
await electronApp.close() | ||
}) | ||
|
||
test.beforeEach(async () => { | ||
const window = await electronApp.firstWindow() | ||
// Clear all local storage before each test | ||
await window.evaluate(() => localStorage.clear()) | ||
}) | ||
|
||
test('should have a navbar with clickable elements', async () => { | ||
const window = await electronApp.firstWindow() | ||
const navLinks = await window.$$('xpath=//navbar//a') | ||
|
||
// Check that each link is clickable | ||
for (const link of navLinks) { | ||
const isClickable = await link.isClickable() | ||
expect(isClickable).toBe(true) | ||
} | ||
}) | ||
|
||
test('Could fill in Login Form', async () => { | ||
const window = await electronApp.firstWindow() | ||
const dhis2UrlInput = await window.locator('xpath=//form//input[@placeholder="DHIS2 URL"]') | ||
await dhis2UrlInput.fill(process.env.TEST_DHIS2_URL) | ||
|
||
// Fill in other input fields (example) | ||
const usernameInput = await window.locator('xpath=//form//input[@placeholder="Username"]') | ||
await usernameInput.fill(process.env.TEST_USERNAME) | ||
|
||
const passwordInput = await window.locator('xpath=//form//input[@placeholder="Password"]') | ||
await passwordInput.fill(process.env.TEST_PASSWORD) | ||
|
||
// Optionally, click the submit button | ||
const submitButton = await window.locator('xpath=//form//button[@type="submit"]') | ||
await submitButton.click() | ||
}) | ||
}) |