在spec.js中,我使用全名,电子邮件和联系电话编写了注册量角器测试。如果用户注册成功,则ng-show值为true,div将显示注册成功消息。
signup.html div显示成功消息:
<div class="form-success-forgot" ng-show="isSignedUp">
<h5>
<strong><span ng-bind="signedUpSuccessMessage"></span></strong>
</h5>
</div>
Spec.js
describe('Test signup ', function() {
var fullname=element(by.model('fullName'));
var email= element(by.model('email'));
var cntNo= element(by.model('contactNo'));
var signup= element(by.css("button[type='submit']"));
var isSignup=element(by.css('.form-success-forgot'));
beforeEach(function() {
});
it('signup success', function() {
browser.get('http://localhost/signup');
fullname.sendKeys('test user');
email.sendKeys('testuser_01@yopmail.com');
cntNo.sendKeys('123-456-7890');
expect(isSignup.isEnabled()).toBe(true);
signup.click();
expect(isSignup.isEnabled()).toBe(false);
element(by.binding('signedUpSuccessMessage')).sendKeys('Thanks for signing up');
//element(by.css("form-success-forgot")).sendKeys(true);
});
});
但是将错误堆栈作为
Message:
Expected true to be false.
Stack:
Error: Failed expectation
at Object.<anonymous> (C:\Users\AppData\Roaming\npm\node_modules
\protractor\example\example_spec.js:20:31)
at C:\Users\AppData\Roaming\npm\node_modules\protractor\node_mod
ules\jasminewd2\index.js:112:25
at new ManagedPromise (C:\Users\AppData\Roaming\npm\node_modules
\protractor\node_modules\selenium-webdriver\lib\promise.js:1067:7)
at ControlFlow.promise (C:\Users\AppData\Roaming\npm\node_module
s\protractor\node_modules\selenium-webdriver\lib\promise.js:2396:12)
at schedulerExecute (C:\Users\AppData\Roaming\npm\node_modules\p
rotractor\node_modules\jasminewd2\index.js:95:18)
at TaskQueue.execute_ (C:\Users\AppData\Roaming\npm\node_modules
\protractor\node_modules\selenium-webdriver\lib\promise.js:2970:14)
at TaskQueue.executeNext_ (C:\Users\AppData\Roaming\npm\node_mod
ules\protractor\node_modules\selenium-webdriver\lib\promise.js:2953:27)
at asyncRun (C:\Users\AppData\Roaming\npm\node_modules\protracto
r\node_modules\selenium-webdriver\lib\promise.js:2860:25)
at C:\Users\AppData\Roaming\npm\node_modules\protractor\node_mod
ules\selenium-webdriver\lib\promise.js:676:7
Message:
Failed: element not visible
(Session info: chrome=58.0.3029.110)
(Driver info: chromedriver=2.29.461591 (62ebf098771772160f391d75e589dc5679
15b233),platform=Windows NT 6.3.9600 x86_64)
如何为ng-show值启用或设置true以使div元素可见?
答案 0 :(得分:1)
据我所知,您在代码中使用了错误的检查。 isEnabled仅用于检查是否已启用input
,具体取决于已禁用的属性。
我认为您需要的是isDisplayed或isPresent。
请注意 希望这有帮助isPresent()
检查DOM中是否存在该元素(不是显示该元素)的区别,isDisplayed()
检查该元素是否