-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9ccb99e
commit 127a9ca
Showing
8 changed files
with
787 additions
and
575 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
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
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,75 @@ | ||
import type { ElectronApplication, Locator, Page } from "@playwright/test"; | ||
import { _electron as electron } from "@playwright/test"; | ||
import path from "path"; | ||
|
||
let electronApp: ElectronApplication, win: Page; | ||
/** | ||
* Starts the electron application | ||
*/ | ||
export const startApp = async (): Promise< | ||
[app: ElectronApplication, win: Page] | ||
> => { | ||
const main = path.resolve( | ||
__dirname, | ||
"..", | ||
"..", | ||
"..", | ||
"dist", | ||
"main", | ||
"main.js" | ||
); | ||
electronApp = await electron.launch({ | ||
args: [main], | ||
env: { | ||
DISPLAY: ":0", | ||
E2E: "true", | ||
NODE_ENV: "test-e2e", | ||
}, | ||
timeout: 120000, | ||
}); | ||
await electronApp.evaluate(({ app }) => { | ||
return app.getAppPath(); | ||
}); | ||
|
||
win = await electronApp.firstWindow(); | ||
// eslint-disable-next-line no-console | ||
win.on("console", console.log); | ||
await win.waitForLoadState(); | ||
|
||
return [electronApp, win]; | ||
}; | ||
|
||
export const closeApp = async (app = electronApp): Promise<void> => { | ||
await app.close(); | ||
}; | ||
|
||
/** | ||
* Wait for the given time. (like sleep) | ||
*/ | ||
export const wait = async (time: number): Promise<void> => | ||
new Promise((resolve) => setTimeout(resolve, time)); | ||
|
||
/** | ||
* Types the text as keyboard input. Handles unicode characters for non text keys. | ||
*/ | ||
export const typeText = async (text: string, w = win): Promise<void> => { | ||
const letters = text.split(""); | ||
for (const letter of letters) { | ||
await w.keyboard.type(letter); | ||
} | ||
}; | ||
|
||
/** | ||
* Clicks over the element locator | ||
*/ | ||
export const clickOverElement = async ( | ||
locator: Locator, | ||
w = win | ||
): Promise<void> => { | ||
const box = await locator.boundingBox(); | ||
if (!box) { | ||
return; | ||
} | ||
const { x, y } = box; | ||
await w.mouse.click(x, y); | ||
}; |
Oops, something went wrong.