【问题标题】:TestCafe Default vs Named ClassesTestCafe 默认与命名类
【发布时间】:2019-03-28 23:48:26
【问题描述】:

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

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

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

TestCafe 允许您避免将测试控制器显式传递给方法。相反,您可以将 t 导入页面模型文件。 link

我想避免使用 this article 建议的默认类,但我想知道 TestCafe 特有的权衡取舍。谢谢。

【问题讨论】:

    标签: typescript automated-tests e2e-testing testcafe


    【解决方案1】:

    TestCafe 不需要使用default 关键字。此外,它不影响测试通过或浏览器的操作。这只是一种从具有一个类的模块中导出/导入类的方法。如果你想写自己的page model,你可以使用一个模块和两个类:

    页面模型:

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

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

    【讨论】:

      猜你喜欢
      • 2019-09-07
      • 2019-07-21
      • 1970-01-01
      • 2019-12-02
      • 1970-01-01
      • 1970-01-01
      • 2020-12-11
      • 1970-01-01
      • 2020-03-21
      相关资源
      最近更新 更多