Class: FireWatir::Firefox
- Inherits:
-
Object
- Object
- FireWatir::Firefox
- Defined in:
- lib/patches/firewatir.rb
Instance Method Summary collapse
- #close ⇒ Object
-
#wait(last_url = nil) ⇒ Object
Waits for the page to get loaded.
Instance Method Details
#close ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/patches/firewatir.rb', line 4 def close if js_eval("getWindows().length").to_i == 1 js_eval("getWindows()[0].close()") if current_os == :macosx %x{ osascript -e 'tell application "Firefox" to quit' } end # wait for the app to close properly @t.join if @t else # Check if window exists, because there may be the case that it has been closed by click event on some element. # For e.g: Close Button, Close this Window link etc. window_number = find_window(:url, @window_url) # If matching window found. Close the window. if window_number.try(:>, 0) js_eval "getWindows()[#{window_number}].close()" end end end |
#wait(last_url = nil) ⇒ Object
Waits for the page to get loaded.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/patches/firewatir.rb', line 31 def wait(last_url = nil) #puts "In wait function " isLoadingDocument = "" start = Time.now while isLoadingDocument != "false" # MONKEYPATCH - START isLoadingDocument = js_eval("#{browser_var}=#{window_var}.getBrowser(); #{browser_var}.webProgress.isLoadingDocument;") rescue return # MONKEYPATCH - END #puts "Is browser still loading page: #{isLoadingDocument}" # Raise an exception if the page fails to load if (Time.now - start) > 300 raise "Page Load Timeout" end end # If the redirect is to a download attachment that does not reload this page, this # method will loop forever. Therefore, we need to ensure that if this method is called # twice with the same URL, we simply accept that we're done. url = js_eval("#{browser_var}.contentDocument.URL") if(url != last_url) # Check for Javascript redirect. As we are connected to Firefox via JSSh. JSSh # doesn't detect any javascript redirects so check it here. # If page redirects to itself that this code will enter in infinite loop. # So we currently don't wait for such a page. # wait variable in JSSh tells if we should wait more for the page to get loaded # or continue. -1 means page is not redirected. Anyother positive values means wait. jssh_command = "var wait = -1; var meta = null; meta = #{browser_var}.contentDocument.getElementsByTagName('meta'); if(meta != null) { var doc_url = #{browser_var}.contentDocument.URL; for(var i=0; i< meta.length;++i) { var content = meta[i].content; var regex = new RegExp(\"^refresh$\", \"i\"); if(regex.test(meta[i].httpEquiv)) { var arrContent = content.split(';'); var redirect_url = null; if(arrContent.length > 0) { if(arrContent.length > 1) redirect_url = arrContent[1]; if(redirect_url != null) { regex = new RegExp(\"^.*\" + redirect_url + \"$\"); if(!regex.test(doc_url)) { wait = arrContent[0]; } } break; } } } } wait;" wait_time = js_eval(jssh_command).to_i begin if(wait_time != -1) sleep(wait_time) # Call wait again. In case there are multiple redirects. js_eval "#{browser_var} = #{window_var}.getBrowser()" wait(url) end rescue end end set_browser_document() run_error_checks() return self end |