app.spec.ts 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import { Page, _electron as electron } from 'playwright'
  2. import { ElectronApplication } from 'playwright-core'
  3. import { test, expect } from '@playwright/test'
  4. let appWindow: Page
  5. let appElectron: ElectronApplication
  6. function waiting(milliseconds: number) {
  7. return new Promise((resolve) => setTimeout(resolve, milliseconds))
  8. }
  9. function isElementVisible(selector: string, waitingMilliseconds = 100) {
  10. return new Promise((resolve) => {
  11. setTimeout(async () => {
  12. expect(await appWindow.isVisible(selector), `Confirm selector '${selector}' is visible`).toBe(
  13. true
  14. )
  15. resolve(true)
  16. }, waitingMilliseconds)
  17. })
  18. }
  19. test.beforeAll(async () => {
  20. // Open Electron app from build directory
  21. appElectron = await electron.launch({ args: ['dist/main/index.js'] })
  22. appWindow = await appElectron.firstWindow()
  23. await appWindow.waitForEvent('load')
  24. })
  25. test('Environment check', async () => {
  26. const isPackaged = await appElectron.evaluate(async ({ app }) => {
  27. return app.isPackaged
  28. })
  29. expect(isPackaged, 'Confirm that is in development mode').toBe(false)
  30. })
  31. test('Document element check', async () => {
  32. await isElementVisible('.v-toolbar__content')
  33. await isElementVisible('#main-logo')
  34. await isElementVisible('#select-language')
  35. })
  36. test('Counter button click check', async () => {
  37. await appWindow.click('#btn-counter', { clickCount: 10, delay: 50 })
  38. const counterValueElement = await appWindow.$('#counter-badge .v-badge__badge')
  39. expect(
  40. await appWindow.evaluate((element) => element.innerHTML, counterValueElement),
  41. 'Confirm counter value is same'
  42. ).toBe('10')
  43. })
  44. test.afterAll(async () => {
  45. await waiting(2000)
  46. await appElectron.close()
  47. })