使用量角器测试一个angularjs应用程序,当我使用它时,如何在数组
发布时间:2020-12-17 18:09:44 所属栏目:安全 来源:网络整理
导读:我有一个ng-repeat,只要现有的“last”元素以任何方式被修改,它就会添加一个新元素.我的量角器测试看起来像这样: var emptyPerson = this.people.last() // this gets me the last row of the ng-repeatemptyPerson.element(by.css('.firstName')).sendKeys
我有一个ng-repeat,只要现有的“last”元素以任何方式被修改,它就会添加一个新元素.我的量角器测试看起来像这样:
var emptyPerson = this.people.last() // this gets me the last row of the ng-repeat emptyPerson.element(by.css('.firstName')).sendKeys('first'); // this sets the firstname correctly but then the app adds a new row to the ng-repeat because of the model change here. emptyPerson.element(by.css('.lastName')).sendKeys('last'); // this sets the lastname of the new row instead of the row that emptyPerson previously referenced 有没有办法告诉emptyPerson坚持使用相同的元素,直到我们完成它为止? 编辑firstname之前的HTML示例: <div ng-repeat="person in object.People" class="student ng-scope"> <div type="text" ng-model="person.FirstName" skip-label="true" placeholder="First" validator="svalidators[$index]" class="layout-default field field-FirstName type-text"> <input type="text" ng-focus="myFocus()" ng-blur="myBlur()" class="form-control" placeholder="First" ng-model="lModel.val" name="person-FirstName"> </div> <div type="text" ng-model="person.LastName" skip-label="true" placeholder="Last" validator="svalidators[$index]" class="layout-default field field-LastName type-text"> <input type="text" ng-focus="myFocus()" ng-blur="myBlur()" class="form-control" placeholder="Last" ng-model="lModel.val" name="person-LastName"> </div> 编辑firstname后的示例: <div ng-repeat="person in object.People" class="student ng-scope"> <div type="text" ng-model="person.FirstName" skip-label="true" placeholder="First" validator="svalidators[$index]" class="layout-default field field-FirstName type-text"> <input type="text" ng-focus="myFocus()" ng-blur="myBlur()" class="form-control" placeholder="First" ng-model="lModel.val" name="person-FirstName"> </div> <div type="text" ng-model="person.LastName" skip-label="true" placeholder="Last" validator="svalidators[$index]" class="layout-default field field-LastName type-text"> <input type="text" ng-focus="myFocus()" ng-blur="myBlur()" class="form-control" placeholder="Last" ng-model="lModel.val" name="person-LastName"> </div> <div ng-repeat="person in object.People" class="student ng-scope"> <div type="text" ng-model="person.FirstName" skip-label="true" placeholder="First" validator="svalidators[$index]" class="layout-default field field-FirstName type-text"> <input type="text" ng-focus="myFocus()" ng-blur="myBlur()" class="form-control" placeholder="First" ng-model="lModel.val" name="person-FirstName"> </div> <div type="text" ng-model="person.LastName" skip-label="true" placeholder="Last" validator="svalidators[$index]" class="layout-default field field-LastName type-text"> <input type="text" ng-focus="myFocus()" ng-blur="myBlur()" class="form-control" placeholder="Last" ng-model="lModel.val" name="person-LastName"> </div> 解决方法
这就是Protractor内部工作的方式.它在对元素应用操作时搜索元素.我担心你必须“手动”处理它并重新引用所需的转发器项目.
为了在编码方面做得更好,我会在函数中隐藏与转发器项目部分的第一次交互 – 基本上,触摸转发器的输入以再生一个项目,然后在最后一次之前返回该项目.一些事情: var MyPageObject = function () { this.people = element(by.repeater("person in object.People")); this.touch = function () { var emptyPerson = this.people.last(); emptyPerson.element(by.css('.firstName')).sendKeys('smth'); var newEmptyPerson = this.people.get(-2); // I think -1 would be the last emptyPerson.element(by.css('.firstName')).clear(); return newEmptyPerson; } this.fillForm = function () { var emptyPerson = this.touch(); emptyPerson.element(by.css('.firstName')).sendKeys('first'); emptyPerson.element(by.css('.lastName')).sendKeys('last'); } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |