Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selenium 1 to Selenium 2 Migration

Selenium 2 has been in beta phase for last few months. I would like to know learning’s if any of our us have analyzed/migrated from selenium 1 to selenium 2

  1. How much was the effort involved in terms of Changes# to accomodates 2 features. Methods/API changes#
  2. How much was perf improvements in terms of run time of tests in Selenium 2
  3. Any best practices/learning shared would be useful
like image 627
Siva Avatar asked Apr 17 '11 07:04

Siva


1 Answers

Going through the transition myself. If you had Selenium 1 experience, Selenium 2 feels quite different actually. Here is my Selenium 2 pros/cons vs. Selenium 1 I see so far (I use Python so some of them are Python specific):

Pros:

  • Much faster.
  • No need to run a separate server.
  • Gone are wait_for_page_to_load(), wait_for_element_present(), etc. All element interactions, clicks, etc. are blocking now, which is good. The only problem is with asynchronously loaded content (Ajax) though, see Con bellow.

Cons:

  • Loading/waiting for asynchronous content which used to be "free" with wait_for_page_to_load() requires coding now. These are the solutions I found so far:
    • use PageFactory/AjaxElementLocatorFactory like explained here, unfortunately I couldn't find the equivalent for Python.
    • use webdriver.implicitly_wait(N), this seems to be doing the trick with Python but using that seems to cause my script to miss changing elements which it used to detect before.
    • don't do sleep(T), loop until element appears, etc, that defeats the purpose of the whole thing (and makes wait_for_page_to_load look beautiful)...
  • The whole thing still feels a bit raw. Different drivers and bindings seem to miss different functionality. Not to say you can't use it but be ready to find 'alternate solutions' for certain problems.
  • The documentation is a bit dubious (related to the prev. point I guess). Especially for Python. Be ready to read code and experiment a lot (which luckily is easy with Python). Most of the 'tutorials' you'll find on the web (again, esp. Python, Java seems to be much better covered) are just to get you started with the plainest of web applications.
  • No PHP bindings, not a big one I prefer Python but our original suite was PHP so I noticed.
  • SeleniumIDE seems to be useless with Selenium 2.

Other differences:

  • The page elements you are accessing have to be 'visible' on the page at the moment when you ask selenium to find them. For example if you have a menu (containing a list of links) which opens when you hover your mouse over, you have to make sure it is open/visible before you click on a link inside (which wasn't the case in Selenium 1). This has it's uses since you'd be testing what an user would see on the page but requires the extra code. I found two solutions:
    • run a Javascript which would open your menu, in my case driver.execute_script("document.getElementById('dashboard_menu_navigation').show()") then click the menu item driver.find_element_by_link_text('Orders').click()
    • use the Mouse / Keyboard classes to simulate actual interaction, this seems to be broken in the Python bindings though (see Cons above):

Example (which throws 'WebElement' object has no attribute 'mouse_move_to' today):

element=driver.find_element_by_id('mn_dashboard')
mouse=Mouse()
mouse.move_to(element)

The Cons list seems longer but that is mostly if you are coming from Selenium 1. I do prefer the lightness and speed of Selenium 2 and despite the early code (using 2.0b4 at the time of writing) the whole thing is quite usable.

Hope to save someone some time...

like image 119
ivaylo_iliev Avatar answered Sep 21 '22 18:09

ivaylo_iliev