I am using the testcaferc.js file for congfiguration.
And I see the following error when I run the test:
An error has occurred while reading the ".....testcaferc.js" configuration file. ERROR Cannot find the browser. "./test1.js" is neither a known browser alias, nor a path to an executable file.
My project has the following folders/files:
- node modules folder
- .testcaferc.js
- package-lock.json
- package.json
- test1.js
1. The contents of .testcaferc.js
Note: I have tried all sorts of quotes to specify the browser, but none of the combination worked. some examples below:
module.exports = {
skipJsErrors: true,
"browsers": "chrome"
// other settings
}
or
module.exports = {
skipJsErrors: true,
browsers: "chrome"
}
or
module.exports = {
skipJsErrors: true,
browsers: 'chrome'
}
2. The contents of test1.js file
3. The contents of package.json
4. And lastly, the contents of the error log file:
CodePudding user response:
The npm test
script is missing the target browser. Docs recommend using all
as an alias to use locally installed browsers, which is what browsers
defines in the rc file.
"test": "testcafe all ./test1.js"
See Getting Started for more info.
Example .testcaferc.js (Docs):
let os = require("os");
module.exports = {
skipJsErrors: true,
hostname: os.hostname(),
// other settings
}
Note that browsers
can be a single browser String or an Array of multiple browsers, so that isn't the issue (Docs).
CodePudding user response:
So, finally, after a lot of confusions and revision of my code, I could get my test running with .testcaferc.js
I got to know that the type:"module" should not be there in the package.json to work with my test.js file
Also noticed that if we write any incorrect code in the .testcaferc.js file, it will keep showing the error similar to the following in the terminal:
An error has occurred while reading the "....testcaferc.js" configuration file. ERROR Cannot find the browser. "./test1.js" is neither a known browser alias, nor a path to an executable file.
Hope it would help someone, who stumbles across this issue. thnx.