admin管理员组

文章数量:1425894

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!

本文标签: javascriptPage object pattern with protractorStack Overflow