TestCafe 默认与命名 类

TestCafe Default vs Named Classes

查看 TestCafe 的页面对象模型,我注意到所有 类 都标记有 default 而不是典型的命名 类.

http://devexpress.github.io/testcafe/documentation/recipes/using-page-model.html

我想知道这背后的原因是什么,它是否以某种方式帮助测试控制器的通过和浏览器操作的排队?

TestCafe allows you to avoid passing the test controller to the method explicitly. Instead, you can import t to the page model file. link

我想避免使用默认 类 作为 建议,但我想知道 TestCafe 特有的权衡。谢谢。

TestCafe 不需要使用 default 关键字。此外,它不会影响测试通过或浏览器的操作。这只是从一个 class 的模块中 exporting/importing 一个 class 的一种方式。如果你想自己编写 page model,你可以使用一个模块和两个 classes:

页面模型:

import { Selector } from 'testcafe';

export class PageModel1 {
    constructor () {
        this.h1  = Selector('h1');
        this.div = Selector('div');
    }
}

export class PageModel2 {
    constructor () {
        this.body = Selector('body');
        this.span = Selector('span');
    }
}

测试代码:

import { PageModel1, PageModel2 } from './models';

const pm1 = new PageModel1();
const pm2 = new PageModel2();

test(`Recreate invisible element and click`, async t => {
    await t.click(pm1.div);
    await t.click(pm1.h1);

    await t.click(pm2.body);
    await t.click(pm2.span);
});

这只是组织代码的问题,因此您可以按照适合自己的方式编写代码。