1

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

6
  • I tried to reproduce the error you mentioned, but I did not succeed. It looks like we need more information. Is the shared content of .testcaferc.js the entire content? How do you run tests: from the console or with TestRun? Please share all the information we need to reproduce the bug. If possible, please create a reproducible example as shown here: testcafe.io/402636/…. Commented Aug 29, 2022 at 8:35
  • Hi @IlyaAfanasenko, i have now edited my question to give more information. hope this could help. Commented Aug 31, 2022 at 23:36
  • 1
    The configuration file name must start with a dot. Please check this. Commented Sep 1, 2022 at 6:26
  • @msilori did you have a chance to see my updated answer? Commented Sep 5, 2022 at 18:09
  • 1
    hey @IlyaAfanasenko, you were correct in saying that i was missing the dot before the name of the testcaferc.json file. Testcafe now seems to work with json type of config file. But, the problem in using the .testcaferc.js still persists. thanks. Commented Sep 8, 2022 at 6:45

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Removing type from package.json resulted in npm test not having an error, despite omitting the required browsers arg in your testcafe command?
An alternative may be to keep type as is, and change the export in testcaferc to be export default {...} (assuming testcafe supports it).
0

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).

16 Comments

I guess it should work without it being specified as an array as it is only a single browser. I tried with and without the array, and same results :(
Hey @JBallin thanks for the response. I dont want to use the npm script to specify the browsers. I wish to use the config file to let testcafe decide which browser to use.
@msilori correct, that's what my answer does. "all" will use the config file. Did you try it? It's a required argument to the CLI, you can't omit it.
Hey @JBallin, as per the documentation, the "all" is an alias, which could be used when someone wants to run tests in all of the locally installed browsers. It is not a mandatory thing and can very well be omitted. For example, if someone wants to run the tests in just one of the browsers, using "all" would be incorrect.
@msilori Agree that it doesn't make much sense, but I'm hoping it will either work or the output will guide as. Have you tried it? Where do you see that browsers arg in CLI isn't mandatory? These docs say it is.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.