在Testcafe中开发测试时保持浏览器打开

时间:2020-02-19 15:08:36

标签: debugging browser automated-tests e2e-testing testcafe

在Testcafe中执行测试后,如何保持浏览器窗口打开?

论坛here上有一个问题,使我进入a live Testcafe版本,但似乎已弃用。

我希望在开发测试时保持浏览器窗口打开以查看元素。

更新

这是我的配置文件:

{
  "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"
}

我尝试从命令行开始测试,

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

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

但是结果始终是相同的-测试完成后,浏览器已关闭,并且没有任何迹象表明正在激活“实时”模式。

1 个答案:

答案 0 :(得分:4)

TestCafe Live的功能已集成到主要TestCafe产品中。

有关更多信息,请参见Live Mode

确保在脚本中添加--live参数:

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

然后使用npm run test运行测试。

这是另一个例子:

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
        });
});

命令行参数:

testcafe chrome screenshot.js --live

输出:

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.
相关问题