LuVu
LuVu

Reputation: 1088

How to click a button before running tests with testcafe

I want to test the pages of my website application. However, I have a disclaimer page that needs to be accepted before you can access the actual application. Is there a way to execute a task (click the accept button in my case) before doing the tests.

Currently, all my tasks fail because they can't pass the page.

Thanks.

Upvotes: 3

Views: 168

Answers (2)

LuVu
LuVu

Reputation: 1088

The code will look something like this:

fixture`testing BeforeEach functionality`
  .meta('fixtureID', 'fix-0001')
  .meta({ author: 'luka98v', creationDate: Date() })
  .page`${url}`
  .beforeEach(async t => {
    const acceptButton = Selector('#accept-disclaimer')
    await t
      .click(acceptButton)
  })

It works fine.

Upvotes: 1

hdorgeval
hdorgeval

Reputation: 3030

You can do this in a BeforeEach Step

Upvotes: 9

Related Questions