2

I've got a little sandbox project I've been playing around with for the last few weeks to learn the in's and out's of implementing a TestCafe runner.

I've managed to solve all my problems except one and at this point I've tried everything I can think of. Reviewed the following similar questions:

How to close testcafe runner

How to get the testCafe exit code

But still my problem remains.

  • I've toyed around with my argv.json file.
  • I've toyed around with my CICDtestBranches.json file.
  • I've toyed around with my package.json file.
  • I've tested the same branch that has the problem on multiple machines.
  • I've tested with multiple browsers (Firefox & Chrome) - both produce the same problem.
  • I've tried to re-arrange the code, see below
  • I've tried add multiple tests in a fixture and added a page navigation to each one.
  • I've tried to remove code that is processing irrelevant options like video logs & concurrency (parallel execution)
  • I also talked with some coworkers around the office who have done similar projects and asked them what they did to fix the problem. I tried their recommendations, and even re-arranging things according to what they tried and still no joy.
  • I've read through the TestCafe documentation on how to implement a test runner several times and still I haven't been able to find any specific information about how to solve a problem with the browser not closing at the end of the test/fixture/script run.
  • I did find a few bugs that describe similar behavior, but all of those bugs have been fixed and the remaining bugs are specific to either Firefox or Safari. In my case the problem is with both Chrome & Firefox. I am running TestCafe 1.4.2. I don't want to file a bug with TestCafe unless it really is a confirmed bug and there is nothing else that can be done to solve it.

So I know others have had this same problem since my coworker said he faced the same problem with his implementation.

Since I know I am out of options at this point, I'm posting the question here in the hopes that someone will have a solution. Thank you for taking the time to look over my problem.

When executing the below code, after the return returnData; is executed, the .then statement is never executed so the TestCafe command and browser window are never terminated.

FYI the following code is CommonJS implemented with pure NodeJS NOT ES6 since this is the code that starts TestCafe (app.js) and not the script code.

    ...**Boiler Plate testcafe.createRunner() Code**...
    console.log('Starting test');
    var returnData = tcRunner.run(runOptions);
    console.log('Done running tests');
    return returnData;
})
.then(failed => {
     console.log(`Test finished with ${failed} failures`);
     exitCode = failed;
     if (argv.upload) return upload(jsonReporterName);
     else return 0;
     testcafe.close();
     process.exit(exitCode);
})
.then(() => {
     console.log('Killing TestCafe');
     testcafe.close();
     process.exit(exitCode);
});
  • I've tried to swap around the two final .then statements to try and see if having one before the other will cause it to close. I copied the testcafe.close() and process.exit() and put them after the if-else statement in the then-failed block, although I know they might-should not get called because of the if-else return statements just before that.
  • I've tried moving those close and exit statements before the if-else returns just to see if that might solve it.

I know there are a lot of other factors that could play into this scenario, like I said I played around with the runOptions:

const runOptions = {
// Testcafe run options, see: https://devexpress.github.io/testcafe/documentation/using-testcafe/programming-interface/runner.html#run
skipJSErrors: true,
quarantineMode: true,
selectorTimeout: 50000,
assertionTimeout: 7000,
speed: 0.01
};

Best way I can say to access this problem and project and all of the code would be to clone the git lab repo:

> git clone "https://github.com/SethEden/CAFfeinated.git"

Then checkout the branch that I have been working this problem with: master You will need to create an environment variable on your system to tell the framework what sub-path it should work with for the test site configuration system.

CAFFEINATED_TEST_SITE_NAME value: SethEden

You'll need to do a few other commands:

> npm install
> npm link

Then execute the command to run all the tests (just 1 for now)

> CAFfeinated

The output should look something like this:

$ CAFfeinated
Starting test
Done running tests
 Running tests in:
 - Chrome 76.0.3809 / Windows 10.0.0

 LodPage
Got into the setup Test
Got to the end of the test1, see if it gets here and then the test is still running?
 √ LodPage

At this point the browser will still be spinning, and the command line is still busy. You can see from the console output above that the "Done running tests" console log has been output and the test/fixture should be done since the "Got to the end of the test1,..." console log has also been executed, that is run as part of the test.after(...). So the next thing to execute should be in the app.js with the .then(()) call.....but it's not. What gives? Any ideas?

I'm looking for what specifically will solve this problem, not just so that I can solve it, but so others don't run into the same pitfall in the future. There must be some magic sauce that I am missing that is probably very obvious to others, but not so obvious to me or others who are relatively new to JavaScript & NodeJS & ES6 & TestCafe.

Seth Eden
  • 1,142
  • 2
  • 20
  • 42
  • Following this implementation in my app.js: https://devexpress.github.io/testcafe/documentation/using-testcafe/programming-interface/runner.html – Seth Eden Sep 12 '19 at 18:19
  • Unfortunately, I was not able to get access to your repo. Could you make it public or post your code here? – Arseniy Rubtsov Sep 13 '19 at 15:03
  • I had to make it private this morning due to copyright concerns. I am doing some refactor and I'll have to delete the repo and re-create it. I'll be done with that this weekend some time, perhaps even today and should be able to update when its back up. Thanks! :-D – Seth Eden Sep 13 '19 at 21:11
  • Maybe tomorrow night. I ran out of time tonight. :-D – Seth Eden Sep 14 '19 at 00:40
  • Ok I got all the potential copyright issues resolved and update the post with instructions for creating an environment variable. The repository has been re-posted and is public again. – Seth Eden Sep 15 '19 at 19:03
  • Closing as it is irrelevant now. I've wiped out the app.js file and I'm starting from scratch. Also the repo is going private again. Sorry guys. – Seth Eden Sep 17 '19 at 15:34
  • how was this resolved? – Shweta Valunj Jul 26 '22 at 20:25

2 Answers2

1

The problem occurs because you specified the wrong value for the runner.src() method.

enter image description here

mlosev
  • 5,130
  • 1
  • 19
  • 31
  • You will not have this problem if you set the environment variable: CAFFEINATED_TEST_SITE_NAME value: SethEden – Seth Eden Sep 16 '19 at 18:04
1

The cause of the issue is in your custom reporter. I removed your reporter and now it works correctly. Please try this approach and recheck your reporter.

Alex Kamaev
  • 6,198
  • 1
  • 14
  • 29