在Fixture中添加一个Login方法。在hook导致Testcafe错误之前,

问题描述 投票:1回答:1

议程:我想在所有测试之前运行登录方法,并在所有测试之后运行注销方法,这样,如果before挂钩失败,则不会执行测试。

我在hook.before中添加了登录逻辑,如下面的代码所示。但是它给出了以下错误,可以帮助我修复它。

enter image description here

测试文件

import { Selector } from "testcafe";
import LoginPage from '../page-objects/login.po';

const loginPage = new LoginPage();

fixture`Getting Started`
.page`https://ci360-dev.dynatracelabs.com/`
.before(async t => {
    await loginPage.login();
});

test("My First Test", async t => {
    const str = await Selector('.home-container h1').textContent;
    console.log(str);
});

Pageobjects类

import { Selector, t } from 'testcafe';
import CommonFunctions from '../commons/common-fns'

export default class LoginPage{


    constructor () {                 
        this.emailTxtBox = Selector('input[type="email"]');
        this.nextBttn = Selector('button[type="submit"]');
        this.microsoftNextBttn = Selector('input[type="submit"]');
        this.passwordTxtBox = Selector('input[type="password"]');
        this.signinBttn = Selector('input[type="submit"]');
        this.noBttn = Selector('#idBtn_Back');
    }

     async login() {
        await t
        .typeText(this.emailTxtBox, '[email protected]')
        .click(this.nextBttn)
        .typeText(this.emailTxtBox, '[email protected]')
        .click(this.microsoftNextBttn)
        .typeText(this.passwordTxtBox, 'Dynatrace2019')
        .click(this.signinBttn)
        .click(this.noBttn);
    }
}
automated-tests ui-automation testcafe ui-testing
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.