I am running some frontend tests on a project that I am working on using testcafe. The tests work great when I run them from the command line however when I put the same command into a python subprocess, the testcafe loading icon spins for about 2 minutes before giving me the error: "Cannot establish one or more browser conenctions". Is there something that the python subprocess is changing for testcafe to not run in a subprocess vs the command line?
The command I am trying to execute is "testcafe firefox tests/unit/customTest.js --testName EspEmpty --testNum 0".
customTest.js:
var argv = require('minimist')(process.argv.slice(2));
const testName = argv.testName;
const testNum = argv.testNum;
import { Selector } from 'testcafe';
const dataSet = require('../../src/testData.json');
fixture("Custom Test").page('http://localhost:8080/Modules');
switch(testName) {
case "EspEmpty":
test('Esp Empty Unit Test', async t=> {
...
});
break;
}
runTest.py
cmd = subprocess.run(["testcafe", "firefox", "tests/unit/customTest.js", "--testName", f"{testName}", "--testNum", f"{testNum}"], text = True)
In the command line, I tried testcafe firefox tests/unit/customTest.js --testName EspEmpty --testNum 0
and the test ran perfectly fine.
In the python file, I tried subprocess.run(["testcafe", "firefox", "tests/unit/customTest.js", "--testName", f"{testName}", "--testNum", f"{testNum}"], text = True)
expecting the same result as the command line, but the testcafe loading icon spins for about 2 minutes before giving me the error:
ERROR Cannot establish one or more browser conenctions.
1 of 1 browser connections have not been established:
- firefox
Hints:
- Increase the value of the "browserInitTimeout" option if it is too low (currently: 2 minutes for local browsers and 6 minutes for remote browsers). This option determines how long TestCafe waits for browsers to be ready.
- The error can also be caused by network issues or remote device failure. Make sure that your network connection is stable and you can reach the remote device.
Type "testcafe -h" for help.
I am running the python code as sudo too. Is this a problem with python subprocess or testcafe?
python version: 3.9.2 testcafe version: 1.18.6 nodeJS version: 12.12.0
I was running the python file as sudo python3 instead of just python3 and that seemed to be the issue. Running the file with just python3 fixes the issue