Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use dynamic url's with testcafe fixture/tests

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?

like image 565
Andrew Avatar asked May 01 '18 14:05

Andrew


2 Answers

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

like image 136
Marion Avatar answered Oct 01 '22 01:10

Marion


You can do in this way:

const TEST_URL = "www.someurl.com"
fixture`jtc-b2c.testcafe`.page(TEST_URL)
like image 30
Phoenix Avatar answered Oct 01 '22 01:10

Phoenix