• <bdo id='bHfke'></bdo><ul id='bHfke'></ul>
  1. <tfoot id='bHfke'></tfoot>

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

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

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

      在量角器中正确使用页面对象模式

      时间:2023-10-12

    1. <small id='MH9FX'></small><noframes id='MH9FX'>

              <bdo id='MH9FX'></bdo><ul id='MH9FX'></ul>

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

                  <tbody id='MH9FX'></tbody>
                <tfoot id='MH9FX'></tfoot>
                <legend id='MH9FX'><style id='MH9FX'><dir id='MH9FX'><q id='MH9FX'></q></dir></style></legend>
                本文介绍了在量角器中正确使用页面对象模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我有一个 Angular 应用程序,我正在使用 Protractor 对其进行测试.

                HTML

                 <div id="all" class="row text-center"><div class="col-lg-4 col-md-4 col-sm-6 col-xs-6"><div class="dashboard-stat block panel padder-v bg-primary"><div class="icon hidden-xs"><img src="../assets/images/icon-ppt-inv.png"></div>

                <div id="value" class="font-thin h1 block">{{summary.num |号码:0}}</div><div id="name" class="text-muted text-xs">阿尔伯特</div></div></div></div></div>

                这是页面对象的代码:

                 '使用严格';var history_page = function (){this.getStat = 函数(){return element.all(by.css('#all'));};this.getName = 函数(){return element(by.css('#name')).getText();};this.getValue = 函数(){return element(by.css('#value')).getText();};};module.exports = new history_page();

                测试代码

                 var historyPage = require('./history_page.js');它('测试',函数(){var history = historyPage.getStat().map(function (stat) {返回 {名称:stat.historyPage.getName()值:stat.historyPage.getValue(),}});history.then(函数(值){控制台.log(值);});});

                由于某种原因,我不断收到错误消息,提示 getName 未定义.如果我更改以下两行

                名称:stat.historyPage.getName()值:stat.historyPage.getValue(),

                作为

                name: stat.element(by.css('#name')).getText(),值:stat.element(by.css('#value')).getText()

                它工作正常.我不确定是什么原因.我真的想避免在我的测试页面上编写 css 定位器,因为它看起来不太好,而且这是一种不好的做法.我会感谢对我有帮助的建议.

                解决方案

                我会将完整的 map() 块移动到页面对象中:

                var history_page = function () {this.all = element.all(by.css('#all'));this.getStat = function() {返回 this.all.map(function (stat) {返回 {名称:stat.element(by.css('#name')).getText(),值:stat.element(by.css('#value')).getText()}});};};module.exports = new history_page();

                I have an Angular app and I am using Protractor to test it.

                HTML

                 <div id="all" class="row text-center">
                        <div class="col-lg-4 col-md-4 col-sm-6 col-xs-6">
                          <div class="dashboard-stat block panel padder-v bg-primary">
                            <div class="icon hidden-xs">
                              <img src="../assets/images/icon-ppt-inv.png">
                            </div>
                            <div>
                              <div id="value" class="font-thin h1 block">
                                {{summary.num | number:0}}
                              </div>
                              <div id="name" class="text-muted text-xs">
                                Albert
                              </div>
                            </div>
                          </div>
                        </div>
                        </div>
                

                Here is the code for the Page Object:

                    'use strict';
                
                        var history_page = function (){
                
                            this.getStat = function(){
                                return element.all(by.css('#all'));
                            };
                
                            this.getName = function(){
                                return element(by.css('#name')).getText();
                            };
                
                            this.getValue = function(){
                                return element(by.css('#value')).getText();
                            };
                
                
                        };
                
                        module.exports = new history_page();
                

                Test Code

                 var historyPage = require('./history_page.js');
                
                    it('Test', function(){
                
                
                     var history = historyPage.getStat().map(function (stat) {
                        return {
                            name: stat.historyPage.getName()
                            value: stat.historyPage.getValue(),
                        }
                    });
                
                     history.then(function (value) {
                        console.log(value);
                    });
                
                
                     });
                

                For some reason I keep getting an error saying getName is not defined. If I change the following two lines

                name: stat.historyPage.getName() 
                value: stat.historyPage.getValue(),
                

                as

                name: stat.element(by.css('#name')).getText(),
                value: stat.element(by.css('#value')).getText()
                

                It works fine. I am not sure what the reason is. I really want to avoid writing css locators on my test page as it does not look good and it is a bad practice. I will appreciate suggestions to help me.

                解决方案

                I would move the complete map() block into the Page Object:

                var history_page = function () {
                    this.all = element.all(by.css('#all'));
                
                    this.getStat = function() {
                        return this.all.map(function (stat) {
                            return {
                                name: stat.element(by.css('#name')).getText(),
                                value: stat.element(by.css('#value')).getText()
                            }
                        });
                    };
                };
                
                module.exports = new history_page();
                

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

                上一篇:如何使量角器中的自动化测试脚本等待,直到页 下一篇:将 UTC 日期时间转换为本地日期时间

                相关文章

                最新文章

              1. <legend id='owi0p'><style id='owi0p'><dir id='owi0p'><q id='owi0p'></q></dir></style></legend>
                  <bdo id='owi0p'></bdo><ul id='owi0p'></ul>
                  1. <small id='owi0p'></small><noframes id='owi0p'>

                  2. <tfoot id='owi0p'></tfoot>

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