如何重用量角器/ AngularJS测试code [英] How to reuse code in Protractor / AngularJS Testing

查看:138
本文介绍了如何重用量角器/ AngularJS测试code的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有几个量角器端到端我们AngularJS应用程序的测试在几个JS文件,他们的工作很好。但是,有很多重复的code的整个测试过程中,我们愿干这件事。

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 would like to DRY that up.

例如,我们每次登录时,我们不得不单击文本元素,输入用户名和密码,然后点击进入。而现在每一个JS文件有它自己是每次测试之前调用登录功能的副本。

For instance, every time we log in, we have to click on the text elements, type in the username and password, and then click enter. And right now every single JS file has its own copy of the login function which is called before every test.

这将是很好的重构出成模块,我们可以再导入。我一直在寻找了几个小时,却没有找到一个好的解决办法。

It would be nice to refactor those out into modules that we can then import. I have been searching for hours, but not found a good solution.

我们应该怎么做呢?

推荐答案

您可以创建模块的NodeJS,包括他们量角器配置

You can create nodejs modules and include them in protractor configuration

登录-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(...);
});

这篇关于如何重用量角器/ AngularJS测试code的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆