Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run all test scripts on a single browser instance

I am using Testcafe (free version) with Java Script. I want to run all my test cases (resides in multiple test scripts in __test__ directory) in a single browser instance (That way 1 time log in) per browser type.

  1. For example, 1 instance for chrome and 1 instance for safari but all tests will run before closing the browser.
  2. If a test fails, I want the screenshot is taken and count number of the test failures. But do want to continue.
  3. I'm doing all on Node 12 Docker image, so it is best if I don't need to install anything else.

How do I do this with Testcafe?

const createTestCafe = require('testcafe')

let testcafe = null
let runner = null

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

    const runner = testcafe.createRunner()

    return runner
      .src([ '__test__/*.js' ])
      .browsers([ 'chrome:headless --no-sandbox --disable-gpu', 'safari' ])
      .screenshots('./reports/screenshots/', true)
      .run({
        selectorTimeout: 10000,
        assertionTimeout: 10000,
      })
  })

runner
  .screenshots({
    path: 'reports/screenshots/',
    takeOnFails: true,
  })
  .then(failedCount => {
    console.log('Tests failed: ' + failedCount)

    testcafe.close()
  })
  .catch(error => {
    console.log("An ERROR detected:" + error)
  })

This is how you install chrome on Dockerfile. Can someone tell me how to install Firefox on Dockerfile?

RUN sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' && \
  http_proxy=${http_proxy} https_proxy=${https_proxy} apt-get update && \
  http_proxy=${http_proxy} https_proxy=${https_proxy} apt-get install -y --allow-unauthenticated google-chrome-stable && \
  apt clean && rm -rf /var/lib/apt/lists/*
like image 594
usustarr Avatar asked Nov 07 '19 22:11

usustarr


2 Answers

It's impossible to meet all requirements at once.

1) For example, 1 instance for chrome and 1 instance for safari but all tests will run before closing the browser.

You cannot install the Chrome and Safari web browsers on docker image. It's possible to install only Chromium and Firefox on it. See the Using TestCafe docker help topic for more information.

2) If a test fail, I want the screen shot taken and count number of test failed. But do want to continue.

TestCafe's Live mode works in the same way, but it's not available on docker.

like image 64
mlosev Avatar answered Oct 02 '22 06:10

mlosev


This case you need to use Session Handling

During test execution, the Selenium WebDriver has to interact with the browser all the time to execute given commands. At the time of execution, it is also possible that, before current execution completes, someone else starts execution of another script, in the same machine and in the same type of browser.

more details

like image 36
Mithila Eranda Avatar answered Oct 02 '22 04:10

Mithila Eranda