New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(electron): fix the directory app path #19601
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
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,2 @@ | ||
const { protocol } = require('electron'); | ||
protocol.registerSchemesAsPrivileged([]); |
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 |
---|---|---|
|
@@ -19,10 +19,8 @@ import path from 'path'; | |
import fs from 'fs'; | ||
import { electronTest as test, expect } from './electronTest'; | ||
|
||
test('should fire close event', async ({ playwright }) => { | ||
const electronApp = await playwright._electron.launch({ | ||
args: [path.join(__dirname, 'electron-app.js')], | ||
}); | ||
test('should fire close event', async ({ launchElectronApp }) => { | ||
const electronApp = await launchElectronApp('electron-app.js'); | ||
const events = []; | ||
electronApp.on('close', () => events.push('application')); | ||
electronApp.context().on('close', () => events.push('context')); | ||
|
@@ -33,22 +31,16 @@ test('should fire close event', async ({ playwright }) => { | |
expect(events.join('|')).toBe('context|application'); | ||
}); | ||
|
||
test('should dispatch ready event', async ({ playwright }) => { | ||
const electronApp = await playwright._electron.launch({ | ||
args: [path.join(__dirname, 'electron-app-ready-event.js')], | ||
}); | ||
try { | ||
const events = await electronApp.evaluate(() => globalThis.__playwrightLog); | ||
expect(events).toEqual([ | ||
'isReady == false', | ||
'will-finish-launching fired', | ||
'ready fired', | ||
'whenReady resolved', | ||
'isReady == true', | ||
]); | ||
} finally { | ||
await electronApp.close(); | ||
} | ||
test('should dispatch ready event', async ({ launchElectronApp }) => { | ||
const electronApp = await launchElectronApp('electron-app-ready-event.js'); | ||
const events = await electronApp.evaluate(() => globalThis.__playwrightLog); | ||
expect(events).toEqual([ | ||
'isReady == false', | ||
'will-finish-launching fired', | ||
'ready fired', | ||
'whenReady resolved', | ||
'isReady == true', | ||
]); | ||
}); | ||
|
||
test('should script application', async ({ electronApp }) => { | ||
|
@@ -114,28 +106,19 @@ test('should have a clipboard instance', async ({ electronApp }) => { | |
expect(clipboardContentRead).toEqual(clipboardContentToWrite); | ||
}); | ||
|
||
test('should test app that opens window fast', async ({ playwright }) => { | ||
const electronApp = await playwright._electron.launch({ | ||
args: [path.join(__dirname, 'electron-window-app.js')], | ||
}); | ||
await electronApp.close(); | ||
test('should test app that opens window fast', async ({ launchElectronApp }) => { | ||
await launchElectronApp('electron-window-app.js'); | ||
}); | ||
|
||
test('should return browser window', async ({ playwright }) => { | ||
const electronApp = await playwright._electron.launch({ | ||
args: [path.join(__dirname, 'electron-window-app.js')], | ||
}); | ||
test('should return browser window', async ({ launchElectronApp }) => { | ||
const electronApp = await launchElectronApp('electron-window-app.js'); | ||
const page = await electronApp.firstWindow(); | ||
const bwHandle = await electronApp.browserWindow(page); | ||
expect(await bwHandle.evaluate((bw: BrowserWindow) => bw.title)).toBe('Electron'); | ||
await electronApp.close(); | ||
}); | ||
|
||
test('should bypass csp', async ({ playwright, server }) => { | ||
const app = await playwright._electron.launch({ | ||
args: [require('path').join(__dirname, 'electron-app.js')], | ||
bypassCSP: true, | ||
}); | ||
test('should bypass csp', async ({ launchElectronApp, server }) => { | ||
const app = await launchElectronApp('electron-app.js', { bypassCSP: true }); | ||
await app.evaluate(electron => { | ||
const window = new electron.BrowserWindow({ | ||
width: 800, | ||
|
@@ -147,13 +130,10 @@ test('should bypass csp', async ({ playwright, server }) => { | |
await page.goto(server.PREFIX + '/csp.html'); | ||
await page.addScriptTag({ content: 'window["__injected"] = 42;' }); | ||
expect(await page.evaluate('window["__injected"]')).toBe(42); | ||
await app.close(); | ||
}); | ||
|
||
test('should create page for browser view', async ({ playwright }) => { | ||
const app = await playwright._electron.launch({ | ||
args: [path.join(__dirname, 'electron-window-app.js')], | ||
}); | ||
test('should create page for browser view', async ({ launchElectronApp }) => { | ||
const app = await launchElectronApp('electron-window-app.js'); | ||
await app.firstWindow(); | ||
await app.evaluate(async electron => { | ||
const window = electron.BrowserWindow.getAllWindows()[0]; | ||
|
@@ -163,13 +143,10 @@ test('should create page for browser view', async ({ playwright }) => { | |
view.setBounds({ x: 0, y: 0, width: 256, height: 256 }); | ||
}); | ||
await expect.poll(() => app.windows().length).toBe(2); | ||
await app.close(); | ||
}); | ||
|
||
test('should return same browser window for browser view pages', async ({ playwright }) => { | ||
const app = await playwright._electron.launch({ | ||
args: [path.join(__dirname, 'electron-window-app.js')], | ||
}); | ||
test('should return same browser window for browser view pages', async ({ launchElectronApp }) => { | ||
const app = await launchElectronApp('electron-window-app.js'); | ||
await app.firstWindow(); | ||
await app.evaluate(async electron => { | ||
const window = electron.BrowserWindow.getAllWindows()[0]; | ||
|
@@ -187,12 +164,10 @@ test('should return same browser window for browser view pages', async ({ playwr | |
}) | ||
); | ||
expect(firstWindowId).toEqual(secondWindowId); | ||
await app.close(); | ||
}); | ||
|
||
test('should record video', async ({ playwright }, testInfo) => { | ||
const app = await playwright._electron.launch({ | ||
args: [path.join(__dirname, 'electron-window-app.js')], | ||
test('should record video', async ({ launchElectronApp }, testInfo) => { | ||
const app = await launchElectronApp('electron-window-app.js', { | ||
recordVideo: { dir: testInfo.outputPath('video') } | ||
}); | ||
const page = await app.firstWindow(); | ||
|
@@ -203,25 +178,31 @@ test('should record video', async ({ playwright }, testInfo) => { | |
expect(fs.statSync(videoPath).size).toBeGreaterThan(0); | ||
}); | ||
|
||
test('should be able to get the first window when with a delayed navigation', async ({ playwright }) => { | ||
test('should be able to get the first window when with a delayed navigation', async ({ launchElectronApp }) => { | ||
test.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/17765' }); | ||
|
||
const app = await playwright._electron.launch({ | ||
args: [path.join(__dirname, 'electron-window-app-delayed-loadURL.js')], | ||
}); | ||
const app = await launchElectronApp('electron-window-app-delayed-loadURL.js'); | ||
const page = await app.firstWindow(); | ||
await expect(page).toHaveURL('data:text/html,<h1>Foobar</h1>'); | ||
await expect(page.locator('h1')).toHaveText('Foobar'); | ||
await app.close(); | ||
}); | ||
|
||
test('should detach debugger on app-initiated exit', async ({ playwright }) => { | ||
const electronApp = await playwright._electron.launch({ | ||
args: [path.join(__dirname, 'electron-app.js')], | ||
}); | ||
test('should detach debugger on app-initiated exit', async ({ launchElectronApp }) => { | ||
const electronApp = await launchElectronApp('electron-app.js'); | ||
const closePromise = new Promise(f => electronApp.process().on('close', f)); | ||
await electronApp.evaluate(({ app }) => { | ||
app.quit(); | ||
}); | ||
await closePromise; | ||
}); | ||
|
||
test('should run pre-ready apis', async ({ launchElectronApp }) => { | ||
await launchElectronApp('electron-pre-ready-app.js'); | ||
}); | ||
|
||
test('should resolve app path for folder apps', async ({ launchElectronApp }) => { | ||
const electronApp = await launchElectronApp('.'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here? |
||
const appPath = await electronApp.evaluate(async ({ app }) => app.getAppPath()); | ||
expect(appPath).toBe(path.resolve(__dirname)); | ||
await electronApp.close(); | ||
}); |
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 @@ | ||
require('electron'); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing this file from the PR?