2013-08-01 63 views
0

我使用ng-pattern进行验证,使用ng-show显示错误消息。这在浏览器上工作正常,但我如何在e2e中编码以测试错误消息是否显示?Angular e2e测试ng-show

这里是我的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总是显示。

回答

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); 
0

你的问题 “进入”

更改为 “.sendKeys”