• <bdo id='5F1Ll'></bdo><ul id='5F1Ll'></ul>
    <tfoot id='5F1Ll'></tfoot>

      1. <legend id='5F1Ll'><style id='5F1Ll'><dir id='5F1Ll'><q id='5F1Ll'></q></dir></style></legend>
        <i id='5F1Ll'><tr id='5F1Ll'><dt id='5F1Ll'><q id='5F1Ll'><span id='5F1Ll'><b id='5F1Ll'><form id='5F1Ll'><ins id='5F1Ll'></ins><ul id='5F1Ll'></ul><sub id='5F1Ll'></sub></form><legend id='5F1Ll'></legend><bdo id='5F1Ll'><pre id='5F1Ll'><center id='5F1Ll'></center></pre></bdo></b><th id='5F1Ll'></th></span></q></dt></tr></i><div id='5F1Ll'><tfoot id='5F1Ll'></tfoot><dl id='5F1Ll'><fieldset id='5F1Ll'></fieldset></dl></div>

      2. <small id='5F1Ll'></small><noframes id='5F1Ll'>

        在量角器中定义页面对象的规范方法

        时间:2023-10-12
        • <bdo id='TIKvE'></bdo><ul id='TIKvE'></ul>
            <tbody id='TIKvE'></tbody>

            <legend id='TIKvE'><style id='TIKvE'><dir id='TIKvE'><q id='TIKvE'></q></dir></style></legend>

                  <small id='TIKvE'></small><noframes id='TIKvE'>

                  <tfoot id='TIKvE'></tfoot>
                • <i id='TIKvE'><tr id='TIKvE'><dt id='TIKvE'><q id='TIKvE'><span id='TIKvE'><b id='TIKvE'><form id='TIKvE'><ins id='TIKvE'></ins><ul id='TIKvE'></ul><sub id='TIKvE'></sub></form><legend id='TIKvE'></legend><bdo id='TIKvE'><pre id='TIKvE'><center id='TIKvE'></center></pre></bdo></b><th id='TIKvE'></th></span></q></dt></tr></i><div id='TIKvE'><tfoot id='TIKvE'></tfoot><dl id='TIKvE'><fieldset id='TIKvE'></fieldset></dl></div>
                  本文介绍了在量角器中定义页面对象的规范方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我们使用 页面对象模式 已经有一段时间了.它绝对有助于组织端到端测试并使测试更具可读性和简洁性.

                  We've been using the Page Object pattern for quite a while. It definitely helps to organize the end-to-end tests and makes tests more readable and clean.

                  正如 使用页面对象组织测试 Protractor 文档页面向我们展示的那样,我们将每个页面对象定义为一个函数并使用 new 来实例化"它:

                  As Using Page Objects to Organize Tests Protractor documentation page shows us, we are defining every page object as a function and use new to "instantiate" it:

                  "use strict";
                  
                  var HeaderPage = function () {
                      this.logo = element(by.css("div.navbar-header img"));
                  }
                  
                  module.exports = HeaderPage;
                  

                  用法:

                  "use strict";
                  
                  var HeaderPage = require("./../po/header.po.js");
                  
                  describe("Header Look and Feel", function () {
                      var header;
                  
                      beforeEach(function () {
                          browser.get("/#login");
                          header = new HeaderPage();
                      });
                  
                      it("should show logo", function () {
                          expect(header.logo.isDisplayed()).toBe(true);
                      });
                  
                  });
                  

                  但是,最近在 Protractor:Angular 测试变得容易谷歌测试博客文章,我注意到一个页面对象被定义为一个对象:

                  But, recently in the Protractor: Angular testing made easy Google Testing Blog post, I've noticed that a page object is defined as an object:

                  var angularHomepage = {
                      nameInput : element(by.model('yourName')),
                      greeting : element(by.binding('yourName')),
                      get : function() {
                          browser.get('index.html');
                      },
                      setName : function(name) {
                          this.nameInput.sendKeys(name);
                      }
                  };
                  

                  这两种引入Page Objects的方式有什么区别?我应该更喜欢一个吗?

                  What is the difference between these two ways to introduce Page Objects? Should I prefer one against the other?

                  推荐答案

                  归根结底,我觉得还是个人喜好问题.

                  Ultimately, I think it is a question of personal preference.

                  是的,您可以使用构造函数模式并在每个测试套件中实例化一个单例...是的,您可以使用上面的简单对象文字...是的,您可以使用工厂函数...

                  Yes, you can use the constructor pattern and instantiate a singleton in each test suite... yes you could use a simple object literal as above... yes you could use a factory function...

                  通过类"(无论是伪语法还是 ES2015 语法)使用继承来构建代码与通过 mixins 扩展的对象在一般应用程序开发中是一个更广泛的争论,更不用说 e2e 测试了!

                  Structuring code using inheritance via "classes" (whether pseudo- or ES2015 syntax) vs objects extended via mixins is a much wider debate within application development in general, never mind e2e tests!

                  主要是在您的测试套件中进行清晰、一致的实践,并尽可能提高代码的可重用性.

                  The main thing is clear, consistent practice across your test suites and promoting code reusability wherever possible.

                  这篇关于在量角器中定义页面对象的规范方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:AngularJs量角器:滑出菜单中的元素不可见 下一篇:如何在量角器中截取整个页面的屏幕截图?

                  相关文章

                  最新文章

                    <i id='Zsns6'><tr id='Zsns6'><dt id='Zsns6'><q id='Zsns6'><span id='Zsns6'><b id='Zsns6'><form id='Zsns6'><ins id='Zsns6'></ins><ul id='Zsns6'></ul><sub id='Zsns6'></sub></form><legend id='Zsns6'></legend><bdo id='Zsns6'><pre id='Zsns6'><center id='Zsns6'></center></pre></bdo></b><th id='Zsns6'></th></span></q></dt></tr></i><div id='Zsns6'><tfoot id='Zsns6'></tfoot><dl id='Zsns6'><fieldset id='Zsns6'></fieldset></dl></div>

                      • <bdo id='Zsns6'></bdo><ul id='Zsns6'></ul>
                      <legend id='Zsns6'><style id='Zsns6'><dir id='Zsns6'><q id='Zsns6'></q></dir></style></legend>

                      <tfoot id='Zsns6'></tfoot>

                      <small id='Zsns6'></small><noframes id='Zsns6'>