42

Why can't we just record all of our test cases in Selenium IDE, export it to Java/WebDriver and run it in WebDriver with Eclipse?

I need a clear explanation as I am very much confused in using WebDriver!

And can anyone please explain why IDE recorded scripts fail in WebDriver?

Sagar
  • 733
  • 3
  • 11
  • 16
  • 3
    The IDE has no concept of AJAX'ified or JS-heavy websites. Say you have a feed of items on your home page, however, they are not all loaded at once, they are loaded as you scroll down the page. Using the IDE you can pick out the feed items one by one, great, however, it's got no idea that *actually* that feed item isn't present until you **do something**. The IDE just cares about the physical elements at the time of recording, it's not too concerned about how the website, in general, is working. That's something only you know. – Arran Oct 30 '13 at 15:16

8 Answers8

56

why cant we just record all of our test cases in IDE, export it to java/webdriver and run it in webdriver

Great question, and here is the answer:

Selenium IDE is a Record and Playback tool, which is very easy to use, but it's very unreliable. Record and playback is typically a frowned upon in web applications. Since web applications are frequently changed, the IDE is not an ideal solution for a production environment, because of the maintenance nightmare that may arise.

Let me give you a practical example. You record your test, and you find an element with a dynamic ID. Sure we can import it into eclipse, but what happens when that test starts failing down the road? why not simply make your test agile and independent to catch these in the first place.

It also boils down to your principles of test automation. Test automation in MY opinion (and several other professionals), believe that test automation should be approached from a programming perspective. Programmers should write the tests, and maintain the tests. Ideally, your quality assurance personnel should be trained to write and maintain their own tests.

So again, back to your question, the IDE is designed to be a quick solution to automation, NOT a solution to a full regression suite.

And can anyone please explain why IDE recorded scripts fail in Webdriver?

I haven't used the IDE in a while, but the reason they fail, is because the scripts that are exported, are simply the steps, not an entire java file. This also is because Selenium IDE exportations are supposed to be agnostic when it comes to how to run your test. Say I'm a user of jUnit.. what if Selenium IDE exported it to TestNG all the time? That wouldn't be fair.. honestly i'd rather create my own tests than changing that one line every single time i create my test file.

You may read the full text of a research conducted, called Why do Record/Replay Tests of Web Applications Break?

ddavison
  • 28,221
  • 15
  • 85
  • 110
  • 4
    Couldn't agree more. UI automation should be considered a programming job. IDE won't generate the most efficient locators, but an experienced programmer can. IDE can't generate a well-structured test suite that smells good, while a good programmer should be able to do that. Furthermore, it sometimes requires changing the source code when appropriate (e.g. complex AJAX ExtJS web apps). – Yi Zeng Oct 30 '13 at 20:56
  • So what should i do now as i am not aware of the depth of java and i have been designated to execute all of our manual test cases in Slenium only?? PLEASE HELP ASAP. Thanq – Sagar Oct 31 '13 at 07:02
  • You can actually choose to which format you want to export your tests (both JUnit and TestNG are supported) - see my answer. – Marielle Oct 31 '13 at 07:34
  • @SagarT : you don't have be an expert in Java to write test cases using WebDriver, basics concepts will do... – Amith Oct 31 '13 at 08:38
  • Thanks a lot for your help _all_, it certainly cleared some doubts. – Sagar Nov 06 '13 at 06:39
  • Have one more question . Have a look and please brief mee!! http://stackoverflow.com/questions/19805614/eclipse-or-intellij-idea-for-selenium-webdriver-java – Sagar Nov 06 '13 at 06:41
  • take a look at http://stackoverflow.com/questions/6555767/how-to-get-started-with-selenium-2#19164784 – ddavison Nov 06 '13 at 15:16
  • @EngineeringBasics did this answer, answer your question? If so, click the Check Mark below the vote counter to accept the answer. If it didn't, find the answer that did so this can be closed `:)` – ddavison Jul 17 '14 at 13:27
  • 1
    Other good reason is because Selenium IDE commands are based on Selenium 1.0 (Remote Control). I mean, for example you have "highlight" command in Selenium IDE and in RemoteControl (which is deprecated) but you have not highlight command in Selenium 2.0 (webdriver) and that's gonna fail in 100% times. – discostu Sep 23 '15 at 11:44
  • 1
    You have no concrete examples whatsoever and your entire answer is hearsay."Programmers should write the tests" Why? "and maintain the tests" Why? "quality assurance personnel should be trained to write and maintain their own tests" Why? "but what happens when that test starts failing down the road?" Okay, like how? **No examples** at all. – 8protons Aug 29 '16 at 22:12
  • does it help to tell you that i'm a contributor to the project? – ddavison Aug 30 '16 at 06:34
  • @sircapsalot No, it doesn't. Firstly because saying that I worked on the iPhone doesn't make me an authority on every aspect of the device- for all you know, I was a UI designer. Secondly because your answers still lack examples to back up your claims. If I took your answer to my boss, which is actually why I am here (looking into IDE vs Sel.2), it couldn't convince him of moving off of the IDE because it doesn't have any explanation with sustenance. You might as well say, "Because Selenium 2 is prettier." – 8protons Sep 07 '16 at 20:45
  • @sircapsalot I think this answer would actually be useful if you could provide context. "Programmers should write their own tests" because....? Because why? "Quality assurance personnel should be trained to write and maintain their own tests" because....? Again, in case you don't understand, it's like answering, "What guns should the military use?" with "Soldiers should use the AK-47." That's it. That's all that is said. Really? No reason _why_ they should use the AK? No stats about the gun or good war stories as an example? I hope you're getting my point. – 8protons Sep 07 '16 at 20:49
  • comparing Selenium to an iPhone is apples and oranges. Selenium is a specialized piece of software that does one thing. an iPhone is a platform that is extensible to support millions of different applications added on to it. that's not Selenium. besides, i already prepared a very practical example in my answer. albeit this is not the venue to argue, and definitely not the venue to defame. let's not clutter this discussion. i will leave you by telling you you may tell your boss that Selenium IDE is no longer maintained nor supported. WebDriver is its successor. plain and simple. – ddavison Sep 08 '16 at 00:31
  • 1
    The research link is now broken. – kiwicomb123 Oct 27 '17 at 15:39
  • google the document, @kiwicomb123. it is possible since it's from academia, you have to have a subscription to a full-text research platform like ProQuest or [IEEE Xplore](http://ieeexplore.ieee.org/document/7515470/?reload=true). – ddavison Oct 27 '17 at 17:37
  • Isn't the inflexibility of IDE one of the main reasons? I have been using the IDE since several days but it seems that it doesn't provide a mechanism to reuse a group of steps. I don't know how to create a method with arguments of them. – ka3ak Nov 23 '20 at 09:42
12

Why can't we just record all of our test cases in Selenium IDE, export it to Java/WebDriver and run it in WebDriver with Eclipse.

You can actually do this with Selenium IDE quite easily. Record your test case / test suite in Selenium IDE, export to "Java / JUnit 4 / Webdriver" to a .java file. This will generate a JUnit test that you can import and run from Eclipse (with the correct version of JUnit of course).

It's not 100% reliable, and you may need to make some manual changes/corrections, but in general it works pretty well. Start with a single small testcase and work from there.

Marielle
  • 898
  • 6
  • 8
  • 1
    Too kind of you for telling this but using same convention when i run the test it fails in webdriver but passes in IDE!! – Sagar Oct 31 '13 at 07:37
  • 2
    Where does it fail? Can you share the relevant part of your script? (Both IDE and the java)? – Marielle Oct 31 '13 at 07:45
  • You might need to tune it. It might not work out the box, and could be related to dependencies. We set up a java project with an abstract test case, and then create our own formatter to capture the test case. To enable this feature, click Options -> Options and enable experimental features on the General tab. Then go to formats and Add. Here's an example of a custom formatter we use: https://gist.github.com/brettcave/9504827. Get a simple open("/") test case working first before you start expanding on it. – Brett Mar 12 '14 at 11:12
9

Why not just record in the IDE and play the recording with WebDriver???

The IDE Does Not Know What to Wait For

Suppose Bob is performing manual checks and recording his interaction with Selenium IDE. He performs an operation that takes a while to update the GUI, and when the operation has finished, he clicks a button. Bob knows that the GUI has finished updating because a spinner that was show when the operation started is removed when the operation is finished. How is the IDE going to capture the fact that the operation must have finished before clicking on the button? (Note here this is not a case where the button is disabled until the operation is finished.) This is not a hypothetical: when you test dynamic tables (like those managed by DataTables), the user can change anything at any time.

This can be one of the reasons a sequence of commands created with the IDE would fail with WebDriver. It just does not know what to wait for.

It is possible to add waits manually in the IDE but if you are doing this, then you are no longer "just record[ing] all of our test cases". And what you are doing becomes more like writing code for WebDriver.

Users are Inefficient

Not long ago there was a Selenium question in which the user wanted to get Selenium to click on the last record in a table that had multiple pages of records. So the question was, how can I page through the table, all the way down to the last page and then click the last record? Someone (maybe me, maybe someone else) pointed out that if the table is sortable, it could be sorted in reverse order and then the Selenium code could click on the first record. That's 2 operations rather than p+1 operations: clicking p times, where p is the number of pages, plus 1 time for the click on the record.

When we write code for WebDriver, we have the opportunity to write the tests to avoid taking the scenic route to get the results we want. See the next point for the technical details as to why it matters.

Selenium Operations Can Be Costly

If the software that runs your Selenium commands is local, and your browser is local, you may not feel that Selenium operations can be costly but if you run your commands on one machine and the browser is remote, then you will notice a significant slowdown. For instance, if you spawn your browser in a Sauce Labs VM or in a BrowserStack VM to run a test suite, network delays are going to add significant time to how long it takes the suite to complete. For a complete application test suite, this can mean many minutes more.

The IDE produces a sequence of commands that each require a round-trip between the Selenium script and the browser. Each round-trip adds up. Suppose I want to check that two elements contain the same text. I'm not going to use Selenese because I don't usually use the IDE but using WebDriver code in Python, the script could be:

a = driver.find_element_by_id("a")
b = driver.find_element_by_id("b")
assert_equal(a.text, b.text)

This code requires 4 round-trips: one round-trip per find_element... and one per access to the text field. The same test could be written:

a_text, b_text = driver.execute_script("""
var a = document.getElementById("a");
var b = document.getElementById("b");
return [a.textcontent, b.textContent];
""");
assert_equal(a_text, b_text);

This needs only one round-trip. When you use the IDE to record actions, the sequence of commands is like the earlier snippet: lots of round-trips. When you write your code for WebDriver, you have the opportunity to optimize as you code.

This does not mean that the Selenium IDE has no use but I would never ever think of just recording tests with it and then playing those recordings with WebDriver.

Louis
  • 146,715
  • 28
  • 274
  • 320
3

If you are a newbie, you can actually use 80% of your IDE script as your webdriver JAVA script, u just have to slightly improvise your exported IDE script and it will work fine.

But when you start testing complex functionalities you have to learn some of the basic java methods to work it out!

2

I beg to differ. I see no reason in having to maintain extra code when a simple record and playback can achieve same results in a fraction of the time.

I do agree with the impl of the recorded script has to be agile. It can't just be as simple as the build in commands and one has to make it agile and even inplement their own macros (aka commands/aliases) specific to the app under test.

Still, if implemented right and with the help of few Selenium IDE plugins like flow control it becomes a breeze to maintain such complex test suits and have them played back via the HTML Runner. I've used Selenium IDE HTML scripts to fully cover complex sites and reused the same script for all responsive modes of the app.

Maintanance is simple as the IDE will help you quickly adjust a failed cmd and AJAX waits can easily be accounted for correctly by waiting for DOM content to change on the page. I'm still not convinced of this AJAX excuse for dismissing Selenium IDE.

For a Maven integration of flow controls command/aliases/macros used by Selenium IDE and Maven's SureFire test plugin see: https://github.com/paulbors/sideflow

Feel free to use it in your product and improve as needed.

Paul Bors
  • 105
  • 6
1

webdriver allows you to execute your test cases captured with Selenium IDE in a Selenium server or via RC to multiple servers. This includes options to integrate with Selenium-enabled providers (see link at the bottom).

For example, if you've captured your test case in IDE, you could easily integrate with your own selenium server, or a provider like Saucelabs to handle the running of your test cases in Firefox on Ubuntu, Safari on OSX and IE10 on Windows 8. As with any test case, you can run it from your IDE (Eclipse / IDEA / etc ) your builder (maven / gradle /), and / or via your CI system.

Check out https://saucelabs.com/selenium for some examples. We've also used our selenium test cases for load testing with Soasta - WebDriver allows simple IDE tests to be used in many different contexts.

Brett
  • 5,690
  • 6
  • 36
  • 63
  • For my team, this is the most important answer. Recording in the IDE is so easy, and manually editing Selenese is much easier than .net or java, the webdriver gets us from new-feature to successful-test much quicker - except that none of the selenium providers will import Selenese. – andrew lorien Dec 06 '16 at 02:59
1

Because when the complexity of your code will increase, it will be difficult for you to manage it using IDE. Maintenance of your scripts will be difficult using IDE.

Also Exporting test cases from IDE to webdriver is not 100% reliable.

Ankit
  • 169
  • 1
  • 4
  • 16
0

Other people have said a lot of helpful answers. One thing that is missing is that if you write code instead of using the IDE you have the power to make changes to the database. It depends on the website you are testing how useful this is, but here are some useful examples I've experienced. In one case the website had multiple sections of a class. One of our tests was merging these sections into one. The IDE couldn't do this. But with webdriver we can add all of our test data into the database, perform the merge, and then remove the data from the database.

Another advantage that webdriver has is Selenium Grid. With Grid you can run your tests in parallel and on multiple browsers. This makes your testing run faster and you can more thoroughly test the code.

Alex Cook
  • 3
  • 4