Closed niteshbalusu11 closed 2 years ago
You need to pass the app/background.js
inside the compiled folder.
/* eslint-disable import/no-extraneous-dependencies */
const {test, expect} = require('@playwright/test')
const path = require('path')
const { _electron: electron } = require('playwright');
let window let electronApp
test.beforeAll(async () => { // Launch Electron app. electronApp = await electron.launch({ args: [path.join(__dirname, '../app/background.js')], })
// Evaluation expression in the Electron context. const isPackaged = await electronApp.evaluate(async ({app}) => { return app.isPackaged })
expect(isPackaged).toBe(false)
// Get the first window that the app opens, wait if necessary. window = await electronApp.firstWindow()
// Capture a screenshot. await window.screenshot({ path: path.join(__dirname, './screenshots/screenshot.png'), }) })
let page test('renders the first page', async () => { page = await electronApp.firstWindow() const title = await page.title() expect(title).toBe('') })
test.afterAll(async () => { // Exit app. await electronApp.close() })
Interesting, I'm pretty sure I tried that and it didn't work. Will look into it again.
The app opens but the screen is only white.
Right yeah, I got it to work by just launching localhost dev url (with also the dev server running) but that won't work very well because all the IPC communication testing will fail.
One thing you could do is replace how Nextron serves the app.
I tried this and it works much better.
@niteshbalusu11 Hey men! thanks for the help but I was able to fix e2e testing with playwright + nextron + electron-serve I just change this line
electronApp = await electron.launch({args: ['../../app/background.js']})
Because that way the app just opens with white screen
for
electronApp = await electron.launch({args: ['.']})
I think that way it takes the "main": "app/background.js", from package json and the static files are loaded without any issues
This is how my testing files looks like now:
/* eslint-disable import/no-extraneous-dependencies */
import {test, expect, ElectronApplication, Page} from '@playwright/test'
import {_electron as electron} from 'playwright'
let electronApp: ElectronApplication
let page: Page
test.beforeAll(async () => {
/***/
electronApp = await electron.launch({args: ['.']})
// Evaluation expression in the Electron context.
const isPackaged = await electronApp.evaluate(async ({app}) => {
return app.isPackaged
})
expect(isPackaged).toBe(false)
})
test.afterAll(async () => {
// Exit app.
await electronApp.close()
})
test('Renders the first page', async () => {
page = await electronApp.firstWindow()
/**
* We need to wait for the load event because the first page
* is the splash screen, So when the splash screen is loaded,
* we can check for the title of the main page.
*/
page.once('load', async () => {
const title = await page.title()
expect(title).toBe('Streamline')
// The title of the main page should be Icons
const text = await page.$eval('h1', (el) => el.textContent)
expect(text).toBe('Icons')
})
})
Nice! Thank you!
I have had other issues with electron serve though, i think it serves static files or something, I am unable to establish a connection between two windows and pass data between them in production so I had to move away from it.
Can you please post an e2e testing example with playwright? Playwright expects a main file to start the electron app from, I tried passing
background.js
but it did not work. Can you please help?https://github.com/saltyshiomix/nextron/issues/250