• [Protractor] Testing With Protractor Page Objects


    Protractor Page Objects are a recommended for testing your AngularJS applications. Page Objects abstract the interaction between the browser and your functional tests, resulting in much cleaner tests.

    We don't want use 'browser' and element directly in the test, so we wrap those into a page object:

    function IndexPage(){
        this.button = element(by.id('button1'));
        this.message = element(by.binding('vm.messageText'));
    
        this.getPageTitle = function(){
            return browser.getTitle();
        }
    
        this.get = function(){
            browser.get('http://127.0.0.1:8080');
        }
    
        this.clickButton = function (){
            this.button.click();
        }
    
        this.getMessageText = function (){
            return this.message.getText();
        }
    }
    
    module.exports = IndexPage;

    Then in the test, we need to call get() method beforeEach.

        var page = new IndexPage();
    
        beforeEach(function (){
            page.get();
        });

    -------------

    var IndexPage = require('./indexPage');
    
    describe('Simple page test', function() {
    
        var page = new IndexPage();
    
        beforeEach(function (){
            page.get();
        });
    
        it('Should get title of the page', function() {
    
            expect(page.getPageTitle()).toBe('E2E Testing');
        });
    
        it('should update the button text when click the button', function(){
    
                page.clickButton();
                expect(page.getMessageText()).toBe('button 1 clicked');
        })
    });
  • 相关阅读:
    纯CSS打造好看的按钮样式
    jQuery手机端触摸卡片切换效果
    CSS手动改变DIV高宽
    Windows 10 的音频和 MIDI API将统一
    美食网站响应式精美模板
    三道Javascript的练习题
    html5手机端遮罩弹出菜单代码
    CSS的::selection使用方法
    Html5绘制饼图统计图
    JQuery实现一个简单的鼠标跟随提示效果
  • 原文地址:https://www.cnblogs.com/Answer1215/p/4987312.html
Copyright © 2020-2023  润新知