栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

多个浏览器和页面对象模式

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

多个浏览器和页面对象模式

看我的解决方案。我简化了示例,但是我们在当前项目中使用了这种方法。我的应用程序具有两种用户权限类型的页面,并且我需要在两种浏览器中同时执行一些复杂的操作。我希望这可以向您展示一些新的更好的方法!

"use strict";//In config, you should declare global browser roles. I only have 2 roles - so i make 2 global instances//Somewhere in onPrepare() functionglobal.admin = browser;admin.admin = true;global.guest = browser.forkNewDriverInstance();guest.guest = true;//Notice that default browser will be 'admin' example:// let someElement = $('someElement'); // this will be tried to be found in admin browser.class basePage {    //Other shared logic also can be added here.    constructor (browser = admin) {        //Simplified example        this._browser = browser    }}class HomePage extends basePage {    //You will not directly create this object. Instead you should use .getPageFor(browser)    constructor(browser) {        super(browser);        this.rightToolbar = ToolbarFragment.getFragmentFor(this._browser);        this.chat = ChatFragment.getFragmentFor(this._browser);        this.someOtherNiceButton = this._browser.$('button.menu');    }    //This function relies on params that we have patched for browser instances in onPrepare();    static getPageFor(browser) {        if (browser.guest) return new GuestHomePage(browser);        else if (browser.admin) return new AdminHomePage(browser);    }    openProfileMenu() {        let menu = ProfileMenuFragment.getFragmentFor(this._browser);        this.someOtherNiceButton.click();        return menu;    }}class GuestHomePage extends RoomPage {    constructor(browser) {        super(browser);    }    //Some feature that is only available for guest    login() {        // will be 'guest' browser in this case.        this._browser.$('input.login').sendKeys('sdkfj'); //blabla        this._browser.$('input.pass').sendKeys('2345'); //blabla        this._browser.$('button.login').click();    }}class AdminHomePage extends RoomPage {    constructor(browser) {        super(browser);    }    acceptGuest() {        let acceptGuestButton = this._browser.$('.request-admission .control-btn.admit-user');        this._browser.wait(EC.elementToBeClickable(acceptGuestButton), 10000,     'Admin should be able to see and click accept guest button. ' +     'Make sure that guest is currently trying to connect to the page');        acceptGuestButton.click();        //Calling browser directly since we need to do complex action. Just example.        guest.wait(EC.visibilityOf(guest.$('.central-content')), 10000, 'Guest should be dropped to the page');    }}//Then in your testslet guestHomePage = HomePage.getPageFor(guest);guestHomePage.login();let adminHomePage = HomePage.getPageFor(admin);adminHomePage.acceptGuest();adminHomePage.openProfileMenu();guestHomePage.openProfileMenu();


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/447877.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号