简体   繁体   English

AngularJS量角器E2E测试中的页面对象

[英]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/401https://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.

相关问题 AngularJS:使用量角器进行e2e测试 - AngularJS: e2e testing with protractor e2e用量角器测量角度(量角器交互式制动器) - e2e testing angularjs with protractor (protractor interactive mode brakes) 使用量角器和远程api进行AngularJS e2e测试 - AngularJS e2e Testing with Protractor and remote api 如何使用量角器将不同方法从不同文件导入另一个javascript文件进行页面对象E2E测试 - how to import different methods from different files to another javascript file for page objects E2E testing using protractor &#39;.then&#39;函数在angularjs的量角器E2E测试中如何工作? - How exactly does '.then' function work in the Protractor E2E testing of an angularjs? angularJS量角器e2e测试TypeError:对象[object Object]没有方法&#39;input&#39; - angularJS Protractor e2e Testing TypeError: Object [object Object] has no method 'input' E2E 测试:Karma+JQuery 与量角器 - E2E testing: Karma+JQuery vs Protractor 使用Angular JS上传文件-量角器E2E测试 - Uploading a file using Angular js - protractor e2e testing 在Protractor中对多个/并行浏览器进行E2E测试? - E2E testing on multiple/parallel browsers in Protractor? 在量角器/端到端测试(AngularJS)中访问$ http数据 - Accessing $http data in Protractor / E2E tests (AngularJS)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM