[英]Page Objects in AngularJS Protractor E2E Testing
What is the right way to handle the Page Objects model for writing Protractor E2E testing for AngularJS? 处理用于为AngularJS编写Protractor E2E测试的Page Objects模型的正确方法是什么? I feel like I should write them in separate files (like homepage.js, page2.js, etc) then include somehow them into the specs like modules as need.
我觉得我应该把它们写在单独的文件中(比如homepage.js,page2.js等)然后以某种方式将它们包含在像模块这样的规范中。 However, I don't know how to inject them.
但是,我不知道如何注射它们。 Would appreciate any suggestions.
将不胜感激任何建议。 Thanks!
谢谢!
Keep them in separate files, and use Node's require
to pull in any helpers or page objects you need. 将它们保存在单独的文件中,并使用Node的
require
来引入您需要的任何帮助程序或页面对象。 Check out this super simple example: https://github.com/juliemr/ng-page-e2e/blob/master/test/angularsite_test.js#L2 看看这个超级简单的例子: https : //github.com/juliemr/ng-page-e2e/blob/master/test/angularsite_test.js#L2
Have you tried with astrolabe? 你试过过astrolabe吗? It's a PageObject implementation on top of Protractor that could guide your structure: https://github.com/stuplum/astrolabe
它是Protractor之上的一个PageObject实现,可以指导您的结构: https : //github.com/stuplum/astrolabe
There you can see that the recommended structure is one page object per file. 在那里,您可以看到推荐的结构是每个文件一个页面对象。
Eg: singInPage.js 例如:singInPage.js
var Page = require('astrolabe').Page;
module.exports = Page.create({
url: { value: 'http://<somesite>.com/signin' },
username: { get: function() { return this.findElement(this.by.input('username')); } }, // finds an input element with the name 'username'
submit: { get: function() { return this.findElement(this.by.id('submit')); } } // finds an element with the id 'submit'
});
it makes the writing of test cases and even page object very compact and readable. 它使得测试用例甚至页面对象的编写非常紧凑和可读。
You should keep them in separate files, yes. 您应该将它们保存在单独的文件中,是的。
And in your protractor referenceConf.js (config to launch protractor with) you should write: 在你的量角器referenceConf.js(配置启动量角器)你应该写:
specs: ['<your_path>/test/pages/*Test.js']
In this case< protractor will launch all files from dir "/test/pages" with mask *Test.js (loginPageTest.js, homePageTest.js) 在这种情况下,<protractor将使用掩码* Test.js (loginPageTest.js,homePageTest.js)从dir“/ test / pages”启动所有文件
I'm afraid that there's no common standards when it comes to testing with page objects. 在使用页面对象进行测试时,我担心没有通用的标准。 You could find several proposals among protractor's issues: https://github.com/angular/protractor/issues/401 and https://github.com/angular/protractor/issues/78
您可以在量角器的问题中找到几个建议: https : //github.com/angular/protractor/issues/401和https://github.com/angular/protractor/issues/78
For my needs I created very simple page objects in my open source project, see: https://github.com/9ci/angle-grinder/pull/124 根据我的需要,我在开源项目中创建了非常简单的页面对象,请参阅: https : //github.com/9ci/angle-grinder/pull/124
Also quite interesting implementation you could find in https://github.com/juliemr/ng-page-e2e/tree/master/test 您可以在https://github.com/juliemr/ng-page-e2e/tree/master/test中找到非常有趣的实现
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.