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 が入力されていることがわかります。実際、以下のすべてのフィールドは、コントローラーの次の行によって「users」配列から入力されます。
$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>
======== users 配列の例 ========
[{"type":"child","firstname":"Jane","lastname":"Sparrow","email":"jane@sparrow.com","password":"","username":" adam","dob":"1995-01-25","gender":"female","parentId":0,"userId":"999999","userToken":"xx-xxxxx-xxxx-xxxxx- xxxxxx","createdDate":"2013-08-12","lastLoginDate":"2013-08-13","profilePictureUrl":" http://zzz.com/profilepic/me.png ","子供" :[]}]