Home > Blockchain >  Browser not specified error when using testcaferc.js file
Browser not specified error when using testcaferc.js file

Time:09-08

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.

enter image description here

My project has the following folders/files:

  1. node modules folder
  2. .testcaferc.js
  3. package-lock.json
  4. package.json
  5. test1.js

1. The contents of .testcaferc.js

enter image description here

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 enter image description here

3. The contents of package.json enter image description here

4. And lastly, the contents of the error log file: enter image description here

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.

  • Related