0
votes

In my application, I want to set up some test data from the UI before running any Fixture. I want to do this set up only once and don't want to do this before each fixture. Can someone please help me on how to do this ?

I tried to use approach mentioned on below thread but I cannot use test controller - t inside before.

https://testcafe-discuss.devexpress.com/t/run-the-same-before-and-after-hook-for-all-fixtures-and-configure-a-baseurl/551

1
Since during the fixture hook of before or after it doesn't make sense to access to t controller. I don't know why do you need to access to it. What is your use case anyway? - tmhao2005
In my applications, I have to create some applications and import few files which usually takes around 5 minutes. Few of my tests in each fixture needs such applications which has few imported files. I don't want to do this activity for each fixture as this will increase my Test execution time so I want to do it once through UI before all fixtures so that I can use such applications in my tests. - Jn Neer
Personally, your setup is supposed to be done via your APIs though. I'm curious what would you do with t controller anyway? - tmhao2005
Actually, I wanted to do it through UI only (due to some restrictions at the API side) and wanted t controller inside before - Jn Neer
I think we just simply create a flag in the top module indicates your setup is done - tmhao2005

1 Answers

0
votes

I have an idea you can check if you feel it works for you as below, you will still use beforeEach in this case as you wish to access to t:

 let didSetup = false;

 fixture`yourFixture`

.beforeEach(async t => {
  if (!didSetup) {
    // You set up things here
    await yourSetup();
    didSetup = true;
  }
  // Otherwise won't do anything
})