How to reuse code in Protractor / AngularJS Testing

前端 未结 2 726
心在旅途
心在旅途 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:15

    Our team uses Orchid-js with Jasmine and Protractor, it's designed to do exactly this.

    Your test

    Describe('Login user',require('../login.js'))("username","password");
    

    login.js

    module.exports = function(username,password){ 
        describe('login the user',function(){
            it('should login the user',function(){
                element(by.id('usernameField')).sendKeys(username);
                element(by.id('passwordField')).sendKeys(password);
                element(by.id('loginButton')).click();
            });
        });
    }
    

提交回复
热议问题