How do I detect a test has failed in Selenium html test?
We have a bank of tests that all start by logging in. They're recorded by QA so are html tests.
However occasionally something goes wrong and the tests fails. When that happens the logout at the end of the test doesn't get called, so the next test tries to login again - using open ./Login
If you're logged out that works fine. However if you didn't log out because the test fails, that command puts you in a different path and then the rest of the tests开发者_开发技巧 in that suite all fail.
How do I tell Selenium to log out if the test fails?
Or how do I tell Selenium if LogOut link is available logout else continue?
From My point of view i would prefer Following steps
create lib with all test cases. create Suite which will call the required function from libraries. In Suite use following flow
Call login
if login function returns zero call required function to execute.
If the called function returns zero call logout.
::::::::::::::::::::::::::::::::::::::::::::::::
If one of the function returns non zero store it in some variable or array with function name and error.
If want more details let me know.
e.g. if function gives error returns non zero value call errorLogout
You can used below approach: Approach 1: TestNg annotation. Approach 2. Use try catch block in catch block call logout function and then throw exception
Let me know if you need more explanation.
精彩评论