我在登录页面使用ng-hide和ng-show。在测试时,我得到的元素不可见,我尝试了browser.wait(),但它说的是多个元素。
我的代码可在
找到 <div class="login-container">
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/c/c3/Python-logo-notext.svg/1024px-Python-logo-notext.svg.png" height="80px" width="80px">
<!-- Create customer Form -->
<div class="login-form" ng-show="signUp">
<form ng-submit="addUser()">
<input type="text" placeholder="Name" ng-model="name" required>
<input type="email" placeholder="Email" ng-model="email" required>
<input type="password" placeholder="Password" ng-model="password" required>
<button ng-disabled="loading" type="submit" class="button-primary">
<span ng-hide="loading">Create</span>
<span ng-show="loading">Loading....</span></button>
</form>
</div>
<div class="login-form" ng-show="login">
<form ng-submit="signIn()" >
<input type="email" placeholder="Email" ng-model="email" required>
<input type="password" placeholder="Password" ng-model="password" required>
<button ng-disabled="loading" type="submit" class="button-primary">
<span ng-hide="loading">Sign In</span>
<span ng-show="loading">Loading....</span></button>
</form>
</div>
<!-- Forgot password -->
<div class="login-form" ng-show="fp" id="fpass">
<form ng-submit="forgotPassword()" >
<input type="email" placeholder="Email" ng-model="email" required>
<button ng-disabled="loading" type="submit" class="button-primary">
<span ng-hide="loading">Resend</span>
<span ng-show="loading">Loading....</span></button>
</form>
</div>
<a href="" id="logIn" ng-click="loginClick()" style="margin-right:5px" ng-hide="login" >Login </a>
<a href="" id="signUp" ng-click="signUpClick()" ng-hide="signUp" style="margin-right:5px">Sign Up </a>
<a href="" id="forgotPassword" ng-click="fpClick()" style="margin-right:5px" ng-hide="fp">Forgot Password </a>
</div>
测试代码
<div class="login-container">
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/c/c3/Python-logo-notext.svg/1024px-Python-logo-notext.svg.png" height="80px" width="80px">
<!-- Create customer Form -->
<div class="login-form" ng-show="signUp">
<form ng-submit="addUser()">
<input type="text" placeholder="Name" ng-model="name" required>
<input type="email" placeholder="Email" ng-model="email" required>
<input type="password" placeholder="Password" ng-model="password" required>
<button ng-disabled="loading" type="submit" class="button-primary">
<span ng-hide="loading">Create</span>
<span ng-show="loading">Loading....</span></button>
</form>
</div>
<div class="login-form" ng-show="login">
<form ng-submit="signIn()" >
<input type="email" placeholder="Email" ng-model="email" required>
<input type="password" placeholder="Password" ng-model="password" required>
<button ng-disabled="loading" type="submit" class="button-primary">
<span ng-hide="loading">Sign In</span>
<span ng-show="loading">Loading....</span></button>
</form>
</div>
<!-- Forgot password -->
<div class="login-form" ng-show="fp" id="fpass">
<form ng-submit="forgotPassword()" >
<input type="email" id="fpass-email" placeholder="Email" ng-model="email" required>
<button ng-disabled="loading" type="submit" class="button-primary">
<span ng-hide="loading">Resend</span>
<span ng-show="loading">Loading....</span></button>
</form>
</div>
<a href="" id="logIn" ng-click="loginClick()" style="margin-right:5px" ng-hide="login" >Login </a>
<a href="" id="signUp" ng-click="signUpClick()" ng-hide="signUp" style="margin-right:5px">Sign Up </a>
<a href="" id="forgotPassword" ng-click="fpClick()" style="margin-right:5px" ng-hide="fp">Forgot Password </a>
</div>
堆栈跟踪
) Testing User Sign Up, Login and Logout, Forgot password Test Forgot password and Login
Message:
Failed: No element found using locator: By.cssSelector("div[ng-show='fp'].button-primary")
Stack:
NoSuchElementError: No element found using locator: By.cssSelector("div[ng-show='fp'].button-primary")
at process._tickCallback (node.js:368:9)
Error
at Object.<anonymous> (/home/leo/python-scripts/Flask-Scaffold/app/templates/users/spec.js:35:57)
From: Task: Run it(" Test Forgot password and Login") in control flow
From asynchronous test:
Error
at Suite.<anonymous> (/home/leo/python-scripts/Flask-Scaffold/app/templates/users/spec.js:27:1)
at Object.<anonymous> (/home/leo/python-scripts/Flask-Scaffold/app/templates/users/spec.js:2:1)
2 specs, 2 failures
Finished in 4.807 seconds
[launcher] 0 instance(s) of WebDriver still running
[launcher] chrome #1 failed 2 test(s)
[launcher] overall: 2 failed spec(s)
[launcher] Process exited with error code 1
https://github.com/Leo-G/Flask-Scaffold/blob/develop/app/templates/login.html