L J
L J

Reputation: 111

How to point testCafe to executable startup file

I can't figure out why (or if it's not allowed) testcafe won't run my runner class file. Current setup

package.json:

{
...
 "test:integration": "testcafe ./bin/integration.js",
...
  "devDependencies": {
    ...
    "testcafe": "^1.5.0",
    "testcafe-react-selectors": "^3.2.0",
    ...
}

bin/integration.js (bin on level of package.json)

const createTestCafe = require('testcafe')
let runner = null
let testcafe = null

createTestCafe('localhost', 1337, 1338)
  .then(tc => {
    testcafe = tc
    runner = testcafe.createRunner()

    return testcafe.createBrowserConnection()
  })
  .then(remoteConnection => {
    // Outputs remoteConnection.url so that it can be visited from the remote browser.
    console.log('remote url:', remoteConnection.url)
    remoteConnection.once('ready', () => {
      runner
        .src('../integration-tests/*test.js*')
        .browsers(['chrome'])
        .run({
          selectorTimeout: 50000,
          assertionTimeout: 7000,
          pageLoadTimeout: 8000
        })
        .then(failed => {
          console.log('failed tests:', failed)
          testcafe.close()
        })
        .catch(error => {
          console.log(error)
        })
    })
  })

Error received: ERROR Unable to find the browser. "./bin/integration.js" is not a browser alias or path to an executable file.

What am I doing wrong?

Thanks in advance

Upvotes: 2

Views: 424

Answers (1)

Alex Kamaev
Alex Kamaev

Reputation: 6318

As far as I understand, you want to use the testcafe API to run your tests. In this case, you do not need to start tests using the testcafe command.

The testcafe command usually expects at least two arguments: browsers and sources. When you use the testcafe ./bin/integration.js command, the CLI arguments parser processes the argument as a browser alias, so you see the error.

I suppose that you need to run your script with the following command: node ./bin/integration.js

Upvotes: 2

Related Questions