Selenium IDE: How do I create a script to be executed before/after every test case in a given test suite?
I'm looking for something equivalent to JUnit setUp()
and tearDown()
methods开发者_如何学Python. In other words: I have a test suite; I would like to write a setup test case and a teardown test case. The setup test case would be executed before each test in the suite. The teardown test case would be executed after each test in the suite.
How?
It sounds to me like you're at the point where you need to export your tests from Selenium IDE into another format/language. Selenium IDE is great for quick prototyping of tests or for showing off what Selenium can do, but when you actually begin to build a library of tests, you need to use a real programming language. Setup and Teardown are a part of every major testing suite (you mentioned JUnit but also TestNG, NUnit and MSTest for C#, etc) so use one! Using a real programming language also allows you to refactor your tests, extracting common functionality into classes and methods so that when your Application Under Test changes, you only need to change one method and not 100 tests. Most testing frameworks also support some sort of data driven testing which many Selenium users find useful.
Are you generating Java code to drive your test cases?
I ended up writing a custom format for C# to handle integrating Selenium test cases with MbUnit which are then just pulled to a Team City server and run after our nightly builds.
I suggest you check out Robot Framework. There is a Selenium library available for Robot Framework so you get almost all Selenium functionality plus you get a great framework to create your test suite.
In Robot Framework you can simply define Test Setup
in the initial settings and it will be executed before every test case. Similarly Test Teardown
will be executed after every test case in your test suite.
精彩评论