Skip to content
This repository was archived by the owner on Sep 11, 2025. It is now read-only.

Commit 27c77d8

Browse files
authored
feat: ability of access current device and browser inside test (#111)
* feat: ability of access current device inside test * feat: added browserName * feat: added simple test
1 parent 8ad11b9 commit 27c77d8

File tree

3 files changed

+5
-0
lines changed

3 files changed

+5
-0
lines changed

e2e/stub.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ describe('Example HTML file', () => {
55
await page.goto(`file:${path.join(__dirname, 'example.html')}`)
66
const browser = await page.$eval('h1', (el) => el.textContent)
77
expect(browser).toBe('Example')
8+
expect(browserName).toBe('chromium')
89
})
910
})

src/PlaywrightEnvironment.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ class PlaywrightEnvironment extends NodeEnvironment {
130130
const { viewport, userAgent } = playwright.devices[device]
131131
contextOptions = { viewport, userAgent, ...contextOptions }
132132
}
133+
this.global.browserName = config.browser
134+
this.global.deviceName = config.device
133135
this.global.browser = await getBrowserPerProcess(playwrightInstance, config)
134136
this.global.context = await this.global.browser.newContext(contextOptions)
135137
this.global.page = await this.global.context.newPage()

types/global.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ interface JestPlaywright {
1616
}
1717

1818
declare global {
19+
const browserName: string
20+
const deviceName: string
1921
const page: Page
2022
const browser: Browser
2123
const context: BrowserContext

0 commit comments

Comments
 (0)