What is the workflow for using Selenium in Java?

I am really confused by the Selenium website. At first they are suitable for explaining the Selenium IDE, but it outputs HTML test cases. But when you move on to the Java documentation, it uses WebDriver, which is pure java, and your HTML test cases are useless. I found the export to the JUnit function from the Selenium IDE, but does not use the WebDriver api, it wraps it inside the Selenium api, which does not even work. I get errors that can only have one session at a time. I had only one test, making sure that with netstat I had no other software listening on the port and a disconnected instance of selenium. It just won't work. In addition, the test file expanded from an obsolete class.

You cannot return a test case to the Selenium IDE from Java code so that you can throw away the Selenium IDE at this point.

I converted the test case to a clean WebDriver and I got it to work. So what is the recommended workflow for working with selenium and JUnit? Should I forget about the Selenium IDE and write actions in the browser and just write everything in Java? Or can I still use the Selenium IDE?

+4
source share
3 answers

Having recently completed a project that used Selenium 2.0, I could find that the Selenium IDE is only good for prototype tests.

There are several flaws in the IDE that prevent it from being used to run Selenium tests. I could recall the following:

  • Usually you want to run tests in Suite. Although the IDE has this feature, I found that the IDE lacks a more important function to run a test installation and break scripts. This is trivial to achieve in JUnit / TestNG, but pretty painful with the written scripts in HTML. In short, recorded tests are not supported until you use the library to test modules to run tests with Java.
  • Data in tests cannot be used for testing; You will need to duplicate the data in each test that requires it. This is expected when tests are stored in a presentation language such as HTML.
  • The format of exported tests does not use the page-object design template by default (which works very well for organizing Selenium tests). I did not try to create my own template for this, but it only convinced me that the best tests involving WebDriver and JUnit / TestNG were written by hand.

The best way to use the Selenium IDE is to create failed test records (by functional testers) instead of directly exporting the tests to your test suite. You can use the IDE to record a preliminary test to capture important aspects of the test (call confirmation / verification), and then rewrite it into your package.

+3
source

I use the IDE to create a "Work Flow Script", converting it to java code. Then I write everything from scratch in Java, but with information from a converted IDE script. This will have all the IDs, etc., But also in the order in which you planned the "click", even some parts of it can be copied right away. In any case, this speeds up the work a little, but if you use webdriver, this will complicate the situation even more, and I have not yet switched to the latest version.

Greetings Stefan

+2
source

The bottom line is that you can use any of them, depending on your purpose. In your case, WebDriver sounds like a way to go.

The Selenium IDE is useful if you want to generate 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 homepage . It has a section, β€œWhat part of Selena suits me?” That answers your question.

+1
source

All Articles