collective / robotframework-selenium2screenshots

Robot Framework keyword library for capturing annotated screenshots with Selenium2Library
28 stars 12 forks source link

"Bootstrap jQuery" doesn't wait for jQuery to be loaded #6

Closed leorochael closed 7 years ago

leorochael commented 7 years ago

After adding the jQuery <script /> tag, Bootstrap jQuery executes:

Wait Until Keyword Succeeds    60    2
...    Selenium2Library.Execute Javascript
...    return (function(){return window.document.jQuery !== undefined;})();;

Which has two bugs:

  1. The keyword always succeeds immediately, as the javascript will execute and return false if window.document.jQuery is undefined.
  2. The keyword will never return true, because jQuery is loaded on window.jQuery not on window.document.jQuery.

As a workaround, I created the following Keywords that I use in my robot scripts:

** Keywords **

Really Bootstrap JQuery
  Bootstrap jQuery
  Wait Until Keyword Succeeds    60    2
  ...    JQuery Should Be Loaded

JQuery Should Be Loaded
  ${jQueryType} =     Execute javascript    return typeof(window.jQuery);
  Should Be Equal    function    ${jQueryType}
datakurre commented 7 years ago

🙈

I'll make a release with return window.jQuery !== undefined; so that you can try it out.

datakurre commented 7 years ago

@leorochael Please, try out 0.7.1 and re-open if the issue remains. Thanks!

leorochael commented 7 years ago

Hi @datakurre,

Thanks for the fix, but you only fixed the problem "2" I reported. Problem "1" remains and is the actual root of the problem:

It'll just return false, but that's not a problem for Wait Until Keyword Succeeds, which only repeats a keyword on exception, not on a False return.

You need to do like I did above and create a Keyword JQuery Should Be Loaded that uses Should Be Equal like I documented in the issue, and then wrap it with Wait Until Keyword Succeeds.

If that isn't done, there is a chance that other keywords from Selenium2Screenshots fail with a message like "JQuery is not loaded" which is extremely hard to understand since, by the time you get to the JS console on the browser, JQuery will already be loaded, and you'll pull your hair out trying to finish a demo for a conference talk like i did :smirk:.

datakurre commented 7 years ago

@leorochael Thanks again, and sorry for needing to explain that again. No that I really got that, I will apply your wrapping approach soonish.

datakurre commented 7 years ago

Fixed in https://github.com/datakurre/robotframework-selenium2screenshots/commit/a5b4bb21beda8e71b28be99e8e81ef930118e57d and released in 0.7.2

leorochael commented 7 years ago

Thanks!