Page Object Pattern Implementation with CasperJS

前端 未结 2 1288
闹比i
闹比i 2021-01-06 17:04

Is there anyone who have already implemented the famous \"Page Object Pattern\" with casperjs, it\'s very useful for test maintenability in the long term ?

It\'s ver

2条回答
  •  花落未央
    2021-01-06 17:36

    Using the example in your second link, you can convert this to a Javascript class-like object and encapsulate in its own module:

    var LoginPage = function(casper) {
        this.casper = casper;
    };
    
    LoginPage.prototype.typeUsername = function(username) {
    
        this.evaluate(function() {
            __utils__.findOne('input.username').value = username;
        });
    };
    
    exports = LoginPage;
    

    and then use it in your test:

    var LoginPage = require("./LoginPage.js");
    var login = new LoginPage(this);
    login.typeUsername("geoff");
    

提交回复
热议问题