6

Taking this fixture I would like to set the checkoutId based on the result from the API call in the before fixture hook so I can use it to set the page on my tests

let checkoutId;
fixture`Check out as guest user`
  .page`localhost:3001/checkout/start/${checkoutId}`
  .before(async () => {
      await checkout.getCheckoutId(sampleData.cart)
      .then(id => (checkoutId = id));
});

// and here the rest of my tests based on the page

I tried fixture hooks, sharing variables but I can't get it to work, checkoutId is undefined when requesting the page.

Is this scenario even possible?

Alex Skorkin
  • 4,264
  • 3
  • 25
  • 47
Andrew
  • 5,395
  • 1
  • 27
  • 47

2 Answers2

5

While TestCafe does not support dynamic URLs, you can call the t.navigateTo(url) action inside "before" based on your condition.

Marion
  • 1,074
  • 5
  • 10
  • This answer is now a year old. Has there been any change to this yet? I'm not seeing an option to `page` that passes the context that would allow this to happen. – icfantv Aug 12 '19 at 16:06
1

You can do in this way:

const TEST_URL = "www.someurl.com"
fixture`jtc-b2c.testcafe`.page(TEST_URL)
Phoenix
  • 437
  • 3
  • 6
  • 15