Here’s the situation that I’m working with:
- Build tests in Selenium
- Get all the tests running correctly (in Firefox)
- Export all the tests to MSTest (so that each test can be run in IE, Chrome and FF)
- If any test needs to be modified, do that editing in Selenium IDE
So it’s a very one-way workflow. However, I’d now like to do a bit more automation. For instance, I’d like every test to run under each of two accounts. I’m getting into a maintenance issue. If I have 6 tests that I want to run under two accounts, suddenly I’d need 12 tests in the Selenium IDE tests. That’s too much editing. But a ton of that code is exactly the same.
How can I share chunks of Selenium tests among tests? Should I use Selenium IDE to develop the test first time then never use it again (only doing edits in VS after that)?
Selenium code is very linear after you export it from the IDE.
For example (ignore syntax):
This is the login page. Every single one of your tests will have to use it. You should refactor it into a method.
The
performLogin()method does not have to be in the same file as your test code itself. You can create a separate class for it with your methods and share it between your tests.We have classes that correspond to certain functionalities on our UI. For example, we have many ways to search in our app. All methods that helps you with search functionality will be in the SearchUtil class.
Structuring your tests similarly will give you the following advantages:
This website is an excellent resource on what you are trying to accomplish.
Good Luck!