谁能解释我,我在做什么错?
PageObject
(commonPO
)中的定义:
var mainNavDashboard = element(by.css("mat-toolbar[class=mat-toolbar]")).element(by.css("mat-icon[svgicon=dashboard]"));
规格:
var common = require('./pages/commonPO');
expect(common.mainNavDashboard.isDisplayed()).toBeTruthy();
编辑: HTML片段:
<mat-toolbar _ngcontent-c12="" class="mat-toolbar mat-primary mat-toolbar-single-row" color="primary" ng-reflect-color="primary" style="flex-direction: row; box-sizing: border-box; display: flex;"><div _ngcontent-c12="" class="main-nav" ng-reflect-ng-class="main-nav"><a _ngcontent-c12="" class="nav-button mat-button" mat-button="" tabindex="0" aria-disabled="false"><span class="mat-button-wrapper"><div _ngcontent-c12="" class="arrow"></div><mat-icon _ngcontent-c12="" class="mat-icon" role="img" svgicon="dashboard" aria-hidden="true" ng-reflect-svg-icon="dashboard"><svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" fit="" height="100%" width="100%" preserveAspectRatio="xMidYMid meet" focusable="false">
<path d="M0 0h24v24H0z" fill="none"></path>
<path d="M3 13h8V3H3v10zm0 8h8v-6H3v6zm10 0h8V11h-8v10zm0-18v6h8V3h-8z"></path>
</svg></mat-icon><span _ngcontent-c12="">Pulpit</span></span><div class="mat-button-ripple mat-ripple" matripple="" ng-reflect-centered="false" ng-reflect-disabled="false" ng-reflect-trigger=""></div><div class="mat-button-focus-overlay"></div></a></mat-toolbar>
答案 0 :(得分:1)
根据您提供的代码,mainNavDashboard
不是commonPO
的成员/财产。
您可以定义commonPO
如下:
var CommonPO = function() {};
CommonPO.prototype.mainNavDashboard = element(by.css("mat-toolbar[class=mat-toolbar]"))
.element(by.css("mat-icon[svgicon=dashboard]"));
module.exports = new CommonPO();
答案 1 :(得分:0)
var common = require('./pages/commonPO');
//creating oject for the class
var common1 = new common();
expect(common1.mainNavDashboard.isDisplayed()).toBeTruthy();
希望它对您有帮助
有关更多信息,请参阅https://www.typescriptlang.org/docs/handbook/modules.html