混合Angular&非角度到页面对象模式

时间:2016-08-05 13:14:03

标签: javascript angularjs selenium protractor pageobjects

我有一个与以下链接相关的问题

PageObjects + non-angular page - how to join them?

然而,我使用量角器 - 黄瓜 - 框架而不是茉莉花。登录过程如下

  1. 导航至主页&输入凭证[angular]
  2. 等待iFrame弹出[非角度]
  3. 继续在iFrame [非角度]
  4. 上登录
  5. iFrame消失,用户返回主页[angular]
  6. 由于列出的四个步骤是登录过程的一部分,理想情况下我想存储角度和角度的字段。单页对象模式中的非角度元素

    我的步骤如下:

    this.Given(/^A User Navigates To The (.+)$/, {timeout: 60 * 1000}, function (AcaExternalLoginPage)
    {
    
        //1. Navigate To Webpage
        return Page = new Page();
    
    });
    
    this.When(/^Employer Code (.+) Is Entered And User Logs On$/, {timeout: 20 * 1000}, function (EmployerCode)
    {
    
        //1. Enter <EmployerCode> & Press Login In Button
        return Page.EmployerEnterCodeAndLogin(EmployerCode);
    
    });
    
    this.Then(/^The Browser Title Should Equal (.+) And The Popup Frame Should Display (.+)$/, {timeout: 20 * 1000}, function (BrowserTitle, PopupFrameGreeting)
    {
    
        var World = this;
    
        //1. Expect Browser Title To Equal Passed In Value
        expect(browser.getTitle()).to.eventually.equal(BrowserTitle);
    
        return this.RunNonAngular(function()
        {
    
            expect(browser.isElementPresent(Page.EmployerSssiFrame)).to.eventually.equal(true);
    
            Page.SwitchToEmployerSssiFrame;
    
            expect(Page.EmployerSssDynamicPromptLabel).to.eventually.equal(true);
    
            //2. Pop up Frame To Equal Passed In Value
            /expect(Page.TextEmployerSssDynamicPromptLabel).to.eventually.equal(PopupFrameGreeting);
    
        })
    
    });
    

    我的页面对象模式是

    'use strict';
    
    var Page = function ()
    {
    
        var baseUrl = 'http://172.16.87.185:54810/';
    
        browser.get(baseUrl + 'login');
    
    };
    
    Page.prototype = Object.create({},
    {
    
        //1: Element Locators
    
        EmployerNameCodeTextBox:
        {
    
            get: function ()
            {
    
                return element(by.id('employee-code'));
    
            }
    
        },
    
        EmployerLoginButton:
        {
    
            get: function ()
            {
    
                return element(by.buttonText('Login'));
    
            }
    
        },
    
        EmployerSssiFrame:
        {
    
            get: function ()
            {
    
                return element(by.id('fbContent'));
    
            }
    
        },
    
        EmployerSssDynamicPromptLabel:
        {
    
            get: function ()
            {
    
                return element(by.id('lblRequestActionText'));
    
            }
    
        },
    
        //2. Actions|Events
    
        EmployerEnterCodeAndLogin:
        { 
    
            value: function (EmployerNameCode)
            {
    
                this.EmployerNameCodeTextBox.sendKeys(EmployerNameCode);
    
                this.EmployerLoginButton.click();
    
            }
    
        },
    
        SwitchToEmployerSssiFrame:
        {
    
            value: function ()
            {
    
                //Need to switch this way because of issue https://github.com/angular/protractor/issues/1846
                browser.switchTo().frame(this.EmployerSssiFrame.getWebElement());
    
            }
    
        },
    
        //3. Static Text Retrieval
    
        TextEmployerSssDynamicPromptLabel:
        {
    
            get: function ()
            {
    
                return this.EmployerSssDynamicPromptLabel.getText();
    
            }
    
        }
    
    });
    
    module.exports = Page;
    

    理想情况下,我希望将页面对象保留在一个页面上,因为它们都是登录过程的一部分。什么时候阻止

    return this.RunNonAngular(function()
    

    它超时,因为它无法找到iframe。关于如何绕过这个的任何建议?也许将iFrame元素存储在另一个页面中(虽然这不是理想的)&amp;稍后初始化?提前谢谢。

0 个答案:

没有答案