我正在对量角器进行测试,并且不知道它为什么会失败 - 而类似的测试通过了。 我正在测试注册窗口。当缺少名字或姓氏时,我希望看到验证警告。
这是标记:
<section class="form_field"> <input data-ng-model="userInfo.userFirstName" data-ng-maxlength="30" data-ng-minlength="2" name="first" type="text" class="form-control ng-pristine ng-animate ng-valid-remove ng-invalid-add ng-invalid-required-add ng-valid-maxlength-add ng-valid-remove-active ng-invalid ng-invalid-add-active ng-invalid-required ng-invalid-required-add-active ng-valid-maxlength ng-valid-maxlength-add-active ng-valid-minlength" placeholder="First Name*" required="" style=""> <div class="field_error" ng-show="registerForm.first.$invalid"> <span data-ng-show="registerForm.first.$error.required" class="ng-binding">Required</span> <span data-ng-show="registerForm.first.$error.minlength" class="ng-hide">Cannot be shorter than 2 letters</span> <span data-ng-show="registerForm.first.$error.maxlength" class="ng-hide">Cannot be longer than 30 letters</span> </div> </section>
<section class="form_field"> <input data-ng-model="userInfo.userLastName" data-ng-maxlength="30" data-ng-minlength="2" name="last" type="text" class="form-control ng-valid-maxlength was_focused ng-animate ng-dirty ng-valid-minlength ng-invalid ng-invalid-required" placeholder="Last Name*" required="" style=""> <div class="field_error" ng-show="registerForm.last.$invalid"> <span data-ng-show="registerForm.last.$error.required" class="ng-binding">Required</span> <span data-ng-show="registerForm.last.$error.minlength" class="ng-hide">Cannot be shorter than 2 letters</span> <span data-ng-show="registerForm.last.$error.maxlength" class="ng-hide">Cannot be longer than 30 letters</span> </div> </section>
现在,当尝试仅输入firstname并期望在lastname上发出警告时,它会通过:
browser.findElement(by.name('first')).sendKeys("first");
browser.driver.findElement(By.xpath("//button[text() = 'CONTINUE']")).click();
expect($('[data-ng-show="registerForm.last.$error.required"]').isDisplayed()).toBeTruthy();
在进行第二次测试时 - 只输入姓氏并期望使用firstname警告 - 它失败了:
browser.findElement(by.name('last')).sendKeys("last");
//pause for debug
//browser.pause();
browser.driver.findElement(By.xpath("//button[text() = 'CONTINUE']")).click();
browser.sleep(8000);
expect($('[data-ng-show="registerForm.first.$error.required"]').isDisplayed()).toBeTruthy();
我收到此错误:
ElementNotVisibleError: element not visible
任何帮助将不胜感激。
感谢。