【问题标题】:Run setup before each fixture using before在使用之前的每个夹具之前运行设置
【发布时间】:2021-03-26 15:04:39
【问题描述】:

我想使用 testcafe 的 before 函数在每个夹具之前运行一个夹具或一组 testController 方法

我想在每个夹具提取到单独的函数之前运行夹具

// testSetup.ts
export async function initialiseTestEnv(t: testController) {

    console.log("Initialise working env");
    
    const docNameInput =  Selector('input#documentName');
    const createBtn =  Selector('button.ui.primary.button');

    await t
        .useRole(roles.adminUser)
        .maximizeWindow()
        .navigateTo(testConfig.standardListPage)
        .typeText(docNameInput, testConfig.repoName)
        .click(createBtn);

我想在每个夹具之前运行它:

// tests.ts
// Tests that rely on env init
fixture `Tests that rely on init event`

    .before(async t => {
        
            await initialiseTestEnv(t)
    })
    .requestHooks(logger)
    .beforeEach(async t => {
        cookies.setCookies;
        await t
            .useRole(roles.adminUser)
        })

    test('Test that relies on test env init', async t => {...}

问题是之前没有我可以解析到 init 函数的测试控制器。是否有另一种方法可以在我运行的每个夹具之前运行这个初始化事件(我不想在每次测试之前运行,就在夹具之前)

【问题讨论】:

    标签: typescript testing integration-testing e2e-testing testcafe


    【解决方案1】:

    你可以这样做:

    let alreadyRun = false;
    fixture `Tests that rely on init event`
        .beforeEach(async t => {
            if (!alreadyRun) {
                await initialiseTestEnv(t);
                alreadyRun = true;
            }
        })
    

    我认为这个问题已经发布在 TestCafe GitHub 页面的某个地方,因此在未来的版本中可能会提供更好的解决方案。但是您可以使用变量和beforeEach 挂钩轻松实现。

    【讨论】:

      猜你喜欢
      • 2014-11-24
      • 1970-01-01
      • 2017-05-02
      • 2011-05-02
      • 1970-01-01
      • 2018-07-21
      • 1970-01-01
      • 2017-01-02
      • 1970-01-01
      相关资源
      最近更新 更多