How to reuse code in Protractor / AngularJS Testing

前端 未结 2 727
心在旅途
心在旅途 2020-12-28 09:57

We have several Protractor end to end tests for our AngularJS app in several JS files and they work great. But, there is a lot of duplicated code throughout the tests and we

2条回答
  •  清歌不尽
    2020-12-28 10:27

    You can create nodejs modules and include them in protractor configuration

    login-helpers.js

    exports.loginToPage = function () {
        //nodejs code to login
    };
    

    protractor.conf.js

    exports.config = {
        //...
        onPrepare: function () {
            protractor.loginHelpers = require('./helpers/login-helpers.js');
        }
        //...
    };
    

    page.spec.js

    it('should do smth', () => {
        protractor.loginHelpers.loginToPage()
    
        //expect(...).toBe(...);
    });
    

提交回复
热议问题