最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Page object pattern with protractor - Stack Overflow

programmeradmin2浏览0评论

I am trying to creat to page object files with protractor.

My app has the following layout. and page object files..

navbar_po.js

var NavBar = function() {
    // define navbar elements and operations
    //  .
    //  .   
};
module.exports = NavBar;

subNavbar_po.js

var SubNavBar = function() {
    // define subnavbar elements and operations
    //  .
    //  .   
};
module.exports = SubNavBar;

page1_po.js

var Page1 = function() {

    this.navbar = function(){
        var navbar = require('./navbar_po.js');
        return new navbar();
    }
    this.subnavbar = function(){
        var subnavbar = require('./subNavbar_po.js');
        return new subnavbar();
    }

    // define Page1 particular elements and operations
    //  .
    //  .
};
module.exports = Page1;

and I access the navbar elements as follows in test script..

var page1 = new require('./page1_po.js');   

page1.navbar.something_method();
page1.subnavbar.something_method();

Is this the best way?

I don't want to define the same navbar elements for each page object file.

Is there any other good way?

I am trying to creat to page object files with protractor.

My app has the following layout. and page object files..

navbar_po.js

var NavBar = function() {
    // define navbar elements and operations
    //  .
    //  .   
};
module.exports = NavBar;

subNavbar_po.js

var SubNavBar = function() {
    // define subnavbar elements and operations
    //  .
    //  .   
};
module.exports = SubNavBar;

page1_po.js

var Page1 = function() {

    this.navbar = function(){
        var navbar = require('./navbar_po.js');
        return new navbar();
    }
    this.subnavbar = function(){
        var subnavbar = require('./subNavbar_po.js');
        return new subnavbar();
    }

    // define Page1 particular elements and operations
    //  .
    //  .
};
module.exports = Page1;

and I access the navbar elements as follows in test script..

var page1 = new require('./page1_po.js');   

page1.navbar.something_method();
page1.subnavbar.something_method();

Is this the best way?

I don't want to define the same navbar elements for each page object file.

Is there any other good way?

Share Improve this question asked Nov 17, 2016 at 15:07 dafunkdafunk 1114 bronze badges 1
  • If your code is working and objective of this question is improvements/optimisations please post it on CodeReviews. – Rajesh Commented Nov 17, 2016 at 15:10
Add a ment  | 

2 Answers 2

Reset to default 6

Ok, great question, super detailed information too!

发布评论

评论列表(0)

  1. 暂无评论