testcafe-cucumber-demo icon indicating copy to clipboard operation
testcafe-cucumber-demo copied to clipboard

Multiple browsers not working

Open csrenato opened this issue 6 years ago • 3 comments

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

csrenato avatar Mar 20 '18 10:03 csrenato

This is working for me now. So you can close the issue...

csrenato avatar Jun 19 '18 08:06 csrenato

Hi @csrenato do you mind sharing as to how you got this working within a cucumber context? Thanks in advance.

bhreinb avatar Aug 27 '18 16:08 bhreinb

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.

csrenato avatar Aug 28 '18 13:08 csrenato