zoukankan      html  css  js  c++  java
  • [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');
        })
    });
  • 相关阅读:
    每日总结
    每日总结
    每周总结
    全球覆盖(哈希+思维)
    DP搬运工2
    DP搬运工1 [来自yyy--mengbier的预设型dp]
    团队开发day06
    团队开发day05
    团队开发day04
    团队开发day03
  • 原文地址:https://www.cnblogs.com/Answer1215/p/4987312.html
Copyright © 2011-2022 走看看