What is the workflow for using Selenium in Java?
I'm really confused by the Selenium web site. At first they go to great lengths to explain Selenium IDE, but it outputs HTML test cases. But when you go to the Java documentation, it uses WebDriver which is pure java and your HTML test cases are useless. I found an export to JUnit feature from Selenium IDE but it doesn't use the WebDriver api, it wraps it inside the Selenium api, which doesn't even work. I get errors that I can only have one session at a time. I had only one test, made sure using netstat that I didn't have any other software listening on the port and disconnected the selenium instance. It just wouldn't work. Additionally the testcase extended from a dep开发者_如何学Gorecated class.
You cannot get back your test case to Selenium IDE from Java code so you can at that point throw the Selenium IDE away.
I converted the test case to pure WebDriver and I got it to work. So what is the recommended workflow for working with selenium and JUnit? Should I forget about Selenium IDE and recording actions in browser and just write everything in Java? Or is it still possible to use Selenium IDE somehow?
Having recently completed a project that used Selenium 2.0, I could find that the Selenium IDE is good only for prototying tests.
There are several drawbacks with the IDE that prevent it from being used to run Selenium tests. I could recall the following:
- Typically you would want to run tests in a Suite. While the IDE does have this feature, I found that the IDE lacks a more important feature of running test setup and tear down scripts. This is trivial to achieve in JUnit/TestNG, but quite a pain with the recorded scripts in HTML. In short, the recorded tests aren't maintainable until you use a unit-testing library to run the tests from Java.
- Data within the tests cannot be shared across tests; you will need to duplicate data in each test that requires it. This is expected when the tests are stored in a presentation language like HTML.
- The default format of the exported tests does not use the page-object design pattern (which works very well for organizing Selenium tests). I didn't attempt creating my own format template for this, but this only convinced me that the best tests involving WebDriver and JUnit/TestNG are written by hand.
The optimal way of using the Selenium IDE is to create recordings of failed tests (by functional testers), instead of directly exporting the tests into your test suite. You could use the IDE to record the preliminary test so that the important aspects of the test (the assert/verify calls) are captured, and then rewrite it in your suite.
I use the IDE to create a "Work Flow Script", convert it into java code. Then I write everything from scratch in Java but with the info from the converted IDE script. That will have all ID's and so on but also in what order you have planned to "click" around, even some parts of it might be copied right off. Anyway it does speed things up a bit, but if you are using the webdriver it will complicate things a bit more and I have not yet moved over to the latest version.
Cheers Stefan
The point is you can use either one, depending on your goal. In your case, WebDriver sounds like the way to go.
Selenium IDE is useful if you want to generate the HTML test cases.
Selenium WebDriver is useful for writing unit tests in Java (or other languages).
For a clear indication of this from the source, see the SeleniumHQ home page. It has a section on "Which part of Selenium is appropriate for me?", which answers your question.
精彩评论