0

我使用 ng-pattern 进行验证,使用 ng-show 显示错误消息。这在浏览器上运行良好,但我如何在 e2e 中对其进行编码以测试是否出现错误消息?

这是我的 HTML:

<input type="text" ng-model="test.pname" name="pname"  ng-maxlength="30" ng-pattern="/^[a-zA-Z0-9 ]*$/"/>
<span class="custom-error" id="pnameValidate" ng-show="addProviderForm.pname.$error.pattern">
PName can be Alpha-Numeric up to 30 characters – spaces allowed, but no special characters</span>

这是我的 e2e 脚本:

  input('test.pname').enter('cakes`');
  expect(element('#pnameValidate:visible').text()).toMatch(/up to 30 characters/);
  input('test.pname').enter('cakes are good');
  expect(element('#pnameValidate:visible').text()).toBe('');

这是测试运行器的结果:

expected "" but was "\n          PName can be Alpha-Numeric up to 30 characters – spaces allowed, but no special characters"

似乎在测试运行程序中,无论我在 e2e 中指定什么,#pnameValidate 总是显示。

4

2 回答 2

0

你的问题是“.enter”

将其更改为“.sendKeys”

于 2015-02-14T18:41:53.240 回答
0

您是否尝试过在测试中添加等待时间以允许 UI 赶上脚本?

input('test.pname').enter('cakes`');
expect(element('#pnameValidate:visible').count()).toBe(1);
expect(element('#pnameValidate:visible').text()).toMatch(/up to 30 characters/);
input('test.pname').enter('cakes are good');

setTimeout(function() {
expect(element('#pnameValidate:visible').count()).toBe(0);
  expect(element('#pnameValidate:visible').text()).toBe('');
}, 500);
于 2013-10-17T12:00:52.550 回答