我想在AngularJS / Karma e2e测试中检查字段值的字符串长度。我在scenario.js中尝试以下内容。错误消息指向第178行(见下文),第52列(其中' toBeGreaterThan'开始):
expect(element('#userId').text().length).toBeGreaterThan(5);
TypeError: Cannot read property 'name' of undefined
at Object.angular.scenario.matcher.(anonymous function) (http://web.loc/myApp/test/lib/angular/angular-scenario.js:24310:41)
at Object.executeStatement (http://web.loc/myApp/test/lib/angular/angular-scenario.js:24276:30)
at Object.chain.(anonymous function) [as toBeGreaterThan] (http://web.loc/myApp/test/lib/angular/angular-scenario.js:24284:37)
at Object.<anonymous> (http://web.loc/myApp/test/e2e/scenarios.js:178:52)
如果我加载页面,我可以看到该字段填充了userId。事实上,下面的所有字段都来自&#34;用户&#34;数组由控制器中的以下行组成:
$scope.users = response.data;
======== HTML ==========
<div ng-repeat="user in users" class="users">
<div class="inline pull-left">
<label>Firstname: </label><span id="firstname">{{user.firstname}}</span><br/>
<label>Lastname: </label><span id="lastname">{{user.lastname}}</span><br/>
<label>Username: </label><span id="username">{{user.username}}</span><br/>
<label>userEmail: </label><span id="email">{{user.email}}</span><br/>
<label>Birthdate: </label><span id="dob">{{user.dob}}</span><br/>
<label>User ID: </label><span id="userId">{{user.userId}}</span><br/>
<label>Parent ID: </label><span id="parentId">{{user.parentId}}</span><br/>
<label>Children: </label><span id="children">{{user.children}}</span><br/>
<label>Type: </label><span id="type">{{user.type}}</span><br/>
<label>Gender: </label><span id="gender">{{user.gender}}</span><br/>
<label>Created Date: </label><span id="createdDate">{{user.createdDate}}</span><br/>
<label>Last LoginDate: </label><span id="lastLoginDate">{{user.lastLoginDate}}</span><br/>
<label>Token: </label><span id="token">{{token}}</span><br/>
</div>
<div class="inline pull-right">
<img ng-src="{{user.profilePictureUrl}}" class="profile-picture"/>
</div>
</div>
========用户数组示例========
[{&#34;类型&#34;:&#34;子&#34;&#34;姓名&#34;:&#34;简&#34;&#34;姓&#34 ;: &#34;麻雀&#34;&#34;电子邮件&#34;:&#34; jane@sparrow.com",&#34;密码&#34;:&#34;&#34;,& #34;用户名&#34;:&#34;亚当&#34;&#34; DOB&#34;:&#34; 1995年1月25日&#34;&#34;两性&#34;:&# 34;女性&#34;&#34; parentId的&#34;:0,&#34;用户id&#34;:&#34; 999999&#34;&#34; userToken&#34;:&#34; XX -xxxxx-XXXX-XXXXX-XXXXXX&#34;&#34; createdDate&#34;:&#34; 2013年8月12日&#34;&#34; lastLoginDate&#34;:&#34; 2013-08 -13&#34;&#34; profilePictureUrl&#34;:&#34; http://zzz.com/profilepic/me.png&#34;&#34;的子&#34;:[]}]