testcafe-cucumber-demo
testcafe-cucumber-demo copied to clipboard
Multiple browsers not working
Hello Helen.
First of all, thank you for providing the cucumber testcafe demo, it was of great help for me.
I would like to ask you if you had any problems running the tests in multiple browsers?
My code snippet from hooks.js:
return runner .src('./test.js') .browsers('chrome', 'firefox') .run() .catch(function (error) { console.log(error); });
The problem is:
Running the test in chrome and firefox -> both browsers open but tests start and run only on the first browser listed in "run". In this example, test run only in chrome.
Also, the second browser does not close after the test.
Did you have any similar issues or could you provide some clarification?
Thanks!
Renato
This is working for me now. So you can close the issue...
Hi @csrenato do you mind sharing as to how you got this working within a cucumber context? Thanks in advance.
Hi @bhreinb
I've followed another path for this problem.
First, I have created a npm task in package.json for each browser/device I am testing on (npm run Chrome, npm run Firefox ...). Each of the tasks will run the test on a predefined port. Example:
"Chrome": "cucumber-js --world-parameters {\"port1\":\"1111\"\,\"port2\":\"1112\"\,\"skipJsErrors\":[\"true\"]\,\"browsers\":[\"chrome\"]\"\} --format json:reports/report.json"
Code from hooks:
function runTest(browsers, tcOptions) { PORT = tcOptions.port1;
createTestCafe('localhost', tcOptions.port1, tcOptions.port2) .then(function (tc) ........
After that I have created a Jenkins job for each of those npm tasks (for example: npm run Chrome). The job name would then be "Chrome", the other job would be Firefox and so on.
When I launch that particular job, I use the Jenkins job name variable to pass it in the npm task. Example from Jenkinsfile:
def NPM_TASK = sh (script: "echo $JOB_NAME ",returnStdout: true).trim()
sh "npm run $NPM_TASK"
This way, you can use only 1 Jenkinsfile for all of your tests and save yourself the trouble of maintaining multiple repositories and you can run all your tests in parallel.