Skip to content
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

Reset page #183

Merged
merged 7 commits into from
Jan 17, 2019
Merged

Reset page #183

merged 7 commits into from
Jan 17, 2019

Conversation

UziTech
Copy link
Contributor

@UziTech UziTech commented Jan 14, 2019

Summary

Add jestPuppeteer.resetPage() function to reset the global.page object according to the configuration.

global.page is is setup based on the configuration.

if (config && config.exitOnPageError) { 
  this.global.page.addListener('pageerror', handleError) 
} 

This will allow the page to be reset by the user and ensure the global.page object will be the same after this call as the when it was first setup.

Users can reset the global.page object before each test by calling jestPuppeteer.resetPage() in a beforeEach function easily.

beforeEach(async () => {
  await jestPuppeteer.resetPage()
})

fixes #75 (comment)

Test plan

describe('resetPage', () => {
  test('should reset page', async () => {
    const oldPage = page
    await jestPuppeteer.resetPage()
    expect(page).not.toBe(oldPage)
    expect(page.isClosed()).toBe(false)
    expect(oldPage.isClosed()).toBe(true)
  })
})

@UziTech UziTech changed the title Reset page [WIP] Reset page Jan 15, 2019
@UziTech UziTech changed the title [WIP] Reset page Reset page Jan 15, 2019
@UziTech
Copy link
Contributor Author

UziTech commented Jan 15, 2019

We could also reset global.browser and global.context but I'm not sure if we should.

@gregberge gregberge merged commit 3a5526c into argos-ci:master Jan 17, 2019
@gregberge
Copy link
Member

Thanks! Awesome!

@mkopeyka
Copy link

mkopeyka commented May 7, 2019

How to reset browser after each describe block? I have a problem with test of login page because session stays authenticated.

@UziTech UziTech mentioned this pull request May 7, 2019
@UziTech
Copy link
Contributor Author

UziTech commented May 7, 2019

I submitted a PR for a jestPuppeteer.resetBrowser() function #237

@gregberge
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Reset browser state between tests?
3 participants