Jest&Playwright类型的页面对象模型不起作用

问题描述

我正在尝试使用Jest和Playwrigt构建基于POM的框架。附加示例代码以供linkedin使用,而发送键处于连线状态时,它将在电子邮件字段中输入很少的字符,而在电子邮件字段中输入剩余的电子邮件字符和密码字符。即使我尝试过slowMo arg。下面是代码段。

const { chromium } = require('playwright');

class browserSession {
    async startTest(domain,headlessstatus) {
        this.browser = await chromium.launch({ headless: headlessstatus,args: ['--start-maximized'] })
        let context = await this.browser.newContext({ viewport: null });
        this.page = await context.newPage();
        this.navigationPromise = this.page.waitForNavigation()
        await this.page.goto(domain,{ waitUntil: 'networkidle' });
    }
    
    async endtest() {
        await this.browser.close();
    }

    async pageOperation(){
        return this.page
    }

    async pageNavigationPromise(){
        return await this.navigationPromise
    }

}
module.exports = new browserSession
const browserSession = require("./browser.session")

class PageActions {

    async setValue(element,value) {
        (await browserSession.pageOperation()).type(element,value)
    }

    async clickOnElement(element) {
        (await browserSession.pageOperation()).click(element)
    }
    async navigatePromise() {
        (await browserSession.pageNavigationPromise())
    }
}

module.exports = new PageActions
const linkedInLocator = require('../locators/linkedIn.locator');
const PageActions = require('../util/page.action')

class LinkedInPage {
   
    async joinLinkedIn(email,password) {
        console.log('----email-----',email,password)
        await PageActions.clickOnElement(linkedInLocator.JOIN)
        await PageActions.navigatePromise()
        await PageActions.setValue(linkedInLocator.EMAIL,email)
        await PageActions.setValue(linkedInLocator.PASSWORD,password)
        await PageActions.clickOnElement(linkedInLocator.AGREE)
    }
}

module.exports = new LinkedInPage
const browserSession = require('../util/browser.session')
const LinkedInPage = require('../pages/linkedIn.page')

describe('E2E test as an end-user,perform the tests below:',() => {
    it("As an end-user,I will Agree & Join Linked in",async () => {
            await browserSession.startTest('https://www.linkedin.com/',false)
            await LinkedInPage.joinLinkedIn('[email protected]','stackover')
        }
    );
},);
exports.JOIN = '//a[text()="Join Now"]';
exports.EMAIL = '#email-or-phone';
exports.PASSWORD = '#password';
exports.AGREE = '#join-form-submit';

在LinkedInPage.class中,我试图设置电子邮件(例如:[email protected])和密码(例如:test123)的值。该脚本在电子邮件字段中输入了几个字符(例如:test),在密码字段中输入了其余字符(例如:@gmail.com123)。我不知道为什么会这样。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)