简体   繁体   中英

Keep browser open while developing a test in Testcafe

How to keep the browser window open after a test executes in Testcafe?

There was a question on the forum here that brought me to a live Testcafe version, but it seems to be deprecated.

I wish to keep the browser window open to see the elements while I'm developing the test.

Update:

This is my config file:

{
  "name": "testcafe-demo",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "dependencies": {
    "testcafe": "^1.8.2"
  },
  "devDependencies": {},
  "scripts": {
    "test": "testcafe chrome tests/",
    "testcafe": "testcafe"
  },
  "author": "mmrse",
  "license": "ISC"
}

I tried starting the tests from the command line with

E:\testcafe-demo> npm run testcafe chrome demo.testcafe.ts --live

and with

E:\testcafe-demo> npm test chrome demo.testcafe.ts --live

but the result is always the same - after the test is finished, the browser is closed and there is no indication "live" mode was being activated.

Features from TestCafe Live were integrated into the main TestCafe product.

See Live Mode for more information.

Make sure to add the --live argument into your script:

  "scripts": {
    "test": "testcafe chrome tests/ --live",
    "testcafe": "testcafe"
  },

And run your tests using npm run test.

Here's another example:

screeshot.js

import { Selector } from 'testcafe';

fixture `My fixture`
    .page `http://devexpress.github.io/testcafe/example/`;

test('Take a screenshot of a fieldset', async t => {
    await t
        .typeText('#developer-name', 'Peter Parker')
        .click('#submit-button')
        .takeScreenshot({
            path:     'my-fixture/thank-you-page1.png',
            fullPage: true
        });
});

Command-line arguments:

testcafe chrome screenshot.js --live

Output:

Using locally installed version of TestCafe.

Live mode is enabled.
TestCafe now watches source files and reruns
the tests once the changes are saved.

You can use the following keys in the terminal:
'Ctrl+S' - stops the test run;
'Ctrl+R' - restarts the test run;
'Ctrl+W' - enables/disables watching files;
'Ctrl+C' - quits live mode and closes the browsers.


Watching the following files:
  c:\Temp\screenshot.js
 Running tests in:
 - Chrome 79.0.3945.130 / Windows 10

 My fixture
 √ Take a screenshot of a fieldset (screenshots: c:\Temp\screenshots\my-fixture\thank-you-page1.png)


 1 passed (5s)

Make changes to the source files or press Ctrl+R to restart the test run.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM