1

I am working on writing a story for a bdd framework which uses jbehave/selenium/webdriver and am having a problem where the test encounters an error while running the story but appears to be fine when running manually. I'm having a problem where javascript for the functionality I'm testing behaves slightly different when I'm running tests manually on firefox vs through selenium web driver on the same system/version of firefox and this difference is causing a js error.

I've debugged and basically the root of the problem appears to be that var request_XML_container = $('div_appendpoint_id'); returns something different when I'm running the test manually vs when I run through the bdd framework.

    var request_XML_container = $('div_appendpoint_id');
    request_XML_container.innerHTML = encoded_xml_from_request;
    var pos = method_to_get_position('id_of_place_div_should_be_appended_to');

    // JS exception is thrown saying that style is not defined **ONLY** 
    // when running through web driver.  Running test manually on 
    // same system and same browser works fine.
    request_XML_container.style.left = (pos[0] - 300) + 'px';
    request_XML_container.style.top = (pos[1] + 25) + 'px';
    request_XML_container.style.display = "block";

Why this would work fine when running manually that var request_XML_container = $('div_appendpoint_id'); would return an item with style defined, but when running through webdriver that the style attribute of the element would not be defined?

UPDATE: I had originally thought that this was updating an iframe, but I read the markup wrong and the iframe I saw is a sibling - not a parent - of the element where the response is being appended to. I'm trying to simply append the response to a div. To be honest, this only makes things more confusing as grabbing a div by id should be pretty straight forward and I'm now sure why webdriver would be producing a different return element in this situation.

UPDATE 2: Steps to reproduce and information about the system I'm on:

  1. Use webdriver to navigate to this url: http://fiddle.jshell.net/C3VB5/11/show/
  2. Have webdriver click the button. It should not work
  3. Run your test again, but pause put a breakpoint at your code to click the driver
  4. Click the button on the browser that webdriver opened. It should not work
  5. Refresh the browser page on the browser that webdriver opened. Now, it should work.
  6. System details:
    • OS : OS X 10.8.5 (12F37)
    • IDE : Eclipse Kepler: Build id: 20130614-0229
    • Browser (used manually and by webdriver) : Firefox 23.0.1
    • Selenium version: 2.35.0

UPDATE 3: I have provided this maven project on github to aid in reproducing: https://github.com/dkwestbr/WebdriverBug/tree/master/Webdriver

Synopsis/tl:dr; Basically, in certain situations it appears as though webdriver is overwriting the '$()' javascript method with a method that does not return an HTMLElement with innerHTML or style defined (among other things). This post details the issue and how to reproduce.

I have opened this ticket to track the issue: https://code.google.com/p/selenium/issues/detail?id=6287&thanks=6287&ts=1379519170

Dave
  • 6,141
  • 2
  • 38
  • 65
  • I believe this boils down to different JS engines. Are you running your tests headless, or with a different browser than the one you are testing it on manually? – Nathan Merrill Sep 17 '13 at 00:58
  • I'm away from my work computer at the moment, but I'll take a look at that first thing in the morning and get back to you. – Dave Sep 17 '13 at 02:19
  • @MrTi - these tests are not running as headless and it is using the same version of firefox that I have installed. I am manually testing and running the automated testing on the same browser (verified by starting firefox, checking the version in the "About Firefox" and by pausing my automated tests and checking the same info in the browser that shows up through that way). – Dave Sep 17 '13 at 19:00
  • This is pretty odd...do you have any extensions installed on your manual version, or are you setting any preferences when starting up your driver? – Nathan Merrill Sep 17 '13 at 19:06
  • @MrTi - I just checked by starting my tests in debug, pausing, and viewing the extensions normally both in my browser that I start and in the browser started by selenium. The only difference is that the one started by selenium has the Firefox Webdriver 2.35.0 extension installed while the firefox I open has no extensions. Both show a ff version of 23.0.1 – Dave Sep 17 '13 at 19:22
  • @MrTi - I will try to reproduce the issue with a jsfiddle. In the meantime, please let me know if there is any other info you need. – Dave Sep 17 '13 at 19:24
  • @MrTi - I've made this jsFiddle to reproduce the issue. If you write a story which simply navigates to this page and clicks the button using webdriver, the button won't work. If you pause the tests in your debugger and click the button yourself, it will not work. Refresh the page and it will work. I'll update my question with more details but in the mean time here is a link to the fiddle which can be used to reproduce: http://fiddle.jshell.net/C3VB5/11/show/ – Dave Sep 18 '13 at 15:26
  • The button works just fine with me. Using Selenium 2.30 with FF 19 on Windows.. – Nathan Merrill Sep 18 '13 at 15:57
  • @MrTi - did the green text show up after the button was pressed? I maybe should have been more specific but the problem isn't with pressing the button but with the javascript which is executed once the button is pressed. – Dave Sep 18 '13 at 16:27
  • Text was there, green and all. – Nathan Merrill Sep 18 '13 at 17:30
  • @MrTi - I've added this github project to help reproduce. At this point I'm starting to think this could be a bug with Tucydides, not webdriver. https://github.com/dkwestbr/WebdriverBug/tree/master/Webdriver – Dave Sep 23 '13 at 18:34
  • I don't think that this is a Thucydides problem. It sounds like a OS/Browser combo problem. Could you try the code on Windows, (and if it doesn't work) on a lower version of FF. – Nathan Merrill Sep 23 '13 at 20:14
  • @MrTi - I tried this on Windows 7 and was able to reproduce the issue. I'll try on a different version of FF. – Dave Sep 23 '13 at 20:27
  • @MrTi - doing this on Chrome also has the issue. – Dave Sep 24 '13 at 16:13
  • Hm...it may be a Thucydides problem...using FF, try 'driver.get(fiddleAddress); driver.findElement(btnElement).click()`. If you can get it to work with some basic code, then I'd imagine its Thucydides. – Nathan Merrill Sep 24 '13 at 16:16
  • @MrTi - that works! It looks like this is an issue with Thucydides. I will follow up on the ticket I filed with them. Thank you for the help. – Dave Sep 24 '13 at 17:27
  • @MrTi - if you put your workaround and a brief summary of why this is not an issue with Thucydides and not webdriver as an answer then I will upvote/accept. – Dave Sep 24 '13 at 17:38
  • Eh, too much work. Not here for the rep points :P – Nathan Merrill Sep 24 '13 at 17:47

1 Answers1

0

I have confirmed that this is a bug with the Thucydides framework (understandable since they still aren't at a 1.0 release).

Issue can be tracked here: https://java.net/jira/browse/THUCYDIDES-203

Dave
  • 6,141
  • 2
  • 38
  • 65