Reputation: 856
I use TestCafe for testing a website. I use the testcafe inside my node module. Users can start the test out of the node presented website. I start it with:
createTestCafe('localhost', 1337, 1338)
.then(tc => {
testcafe = tc;
const runner = testcafe.createRunner();
inputStore.clLogin = req.body.name;
inputStore.clPassword = req.body.pass;
inputStore.metaFolder = '19233456';
inputStore.metaUrl = req.body.channel;
return runner
.src(['tests/temp.js'])
.browsers(myBrowser)
//.browsers('browserstack:Chrome')
.screenshots('allure/screenshots/', true)
.reporter('allure')
.run();
})
.then(failedCount => {
console.log('Tests failed: ' + failedCount);
testcafe.close();
startReportGenerator();
res.sendStatus(201);
});
Is it possible to check, if there is a testcafe instance running? I want to avoid that another user who connects to the node server can start another instance of testcafe.
Upvotes: 1
Views: 347
Reputation: 35
I came up with a simple solution but works well for me:
in package.json
...
"testcafe:test": "E2E='true' testcafe ..."
...
Then simply
Use process.env.E2E
anywhere
Upvotes: 0
Reputation: 6318
The runner.run
method returns a promise. This means that Testcafe is running until this promise is resolved. You can add some custom static flags to your code:
if (isTestCafeRunning)
createTestCafe()
...
.then(() => {
isTestCafeRunning = true;
runner.run()
})
.then(() => {
isTestCafeRunning = false;
})
Please note that it's just a pseudo-code that demonstrates my idea.
Upvotes: 1