[wtr-general] Re: How to Access JavaScript Variables
Thanks for detail answer, Chuck van der Linden. I found bug in my code so simple code line like this: $browser.execute_script(global_javascript_variable) successfully access variable (same can be done with functions). I agree with you that playing with JavaScript is not what Watir suppose to do. However in some rare cases extra information can be useful for testing complex web application. In my case I found this information about web application actions state in JavaScript variables. Seems these variables was build for applications need, but It perfectly suit for my custom readyCheck method for Watir tests. On 23 Lap, 19:48, Chuck van der Linden sqa...@gmail.com wrote: The first question I'd have then would be why do you want to do this? and might there be some other way (e.g. if that variable is controlling something that is reflected on the screen or in the DOM, then perhaps you can figure out how to 'see' it the way a user would. The intent of Watir is to drive the browser the way the user interacts with it. There's little provision for interacting directly with the javascript or retrieving/changing values in variables other than via how it would happen with a genuine user using an input element or clicking on things etc. About the only exception to this is the ability to invoke a specific bit of javascript via .execute_script. That method is mostly there to allow a fallback way to simulate the response to some user action which for some reason cannot be automated. It does however return a result, so it might be able to be used for what you want to do. None of your code however is trying to capture that response, so perhaps start with that.. e.g. myvar = $myBrowser.ie.document.targetWindow.myvar #note that the .document method is lower case, not .Document puts myvar also quite possibly you may want .parentWindow there, not .targetWindow I'm not enough of a JS expert to know which would be proper. If that won't work, then you're going to need to know javascript well enough to figure out what to execute there. If you don't know that, this might be better posted to Stack Overflow with both Watir and JavaScript tags on the question, in order to get attention from people proficient in JS. Also to better assist in troubleshooting, it's helpful to know what happened when you tried what you tried, did you get an error, did it appear to work with no error but you got nothing back, etc.. saying I tried this and not telling us (or the folks on SO) and here's what happened' makes it very hard to determine where you might be going wrong. If it helps, this is what the .execute_script method is doing under the covers def execute_script(source) escaped_src = source.to_s.gsub(/[\r\n']/) {|m| \\#{m}} document.parentWindow.eval(escaped_src) rescue WIN32OLERuntimeError, NoMethodError #if eval fails we need to use execScript(source.to_s) which does not return a value, hence the workaround wrapper = _watir_helper_div_#{rand(10)} cmd = var e = document.createElement('DIV'); e.id='#{wrapper}'; e.innerHTML = eval('#{escaped_src}'); document.body.appendChild(e); document.parentWindow.execScript(cmd) wrapper_obj = document.getElementById(wrapper) result_value = wrapper_obj.innerHTML wrapper_obj.style.display = 'none' result_value end On Nov 22, 2:32 am, xeranas anorku...@gmail.com wrote: I want access some javascript global variables, but out of luck so at first I want know that I use correct methods to take value. lets say on website exist simple script: script type=text/javascript var myvar = 5; /script I was trying with methods below access myvar value: $myBrowser.ie.Document.targetWindow.myvar $myBrowser.execute_script(targetWindow.myvar) $myBrowser.execScript(targetWindow.myvar) Is these methods are correctly write? What differences between them? -- Before posting, please read http://watir.com/support. In short: search before you ask, be nice. watir-general@googlegroups.com http://groups.google.com/group/watir-general watir-general+unsubscr...@googlegroups.com
[wtr-general] Re: method_missing: fireEvent WIN32OLERuntimeError
Thanks for replies. About method ready, yea it write in stupid way and on IF !ready($b) is used (method name should be named notReady).. Updating ruby with watir doesn't solve my problem. However I found other solution: I change: $b.text_field(:id, 'singlelineedit1').when_present.set(1) to: $b.text_field(:id, 'singlelineedit1').when_present.value = 1 and no more ugly error :) On Nov 21, 9:29 pm, brett sykes brettcsy...@gmail.com wrote: Yes, it looks like his ready method is returning true when the browser is in a busy state. But, besides that point, if you take Chucks advice and update to a more modern version (like 1.9.1), you can take advantage of the very cool #when_present extension and simplify your current code to something more along the lines of: #- 999.times do $b.text_field(:id, 'singlelineedit1').when_present.set(1) $b.text_field(:id, 'multilineedit1').when_present.set(...) $b.button(:id, button1).when_present.click end #- Brett On Mon, Nov 21, 2011 at 2:07 PM, Chuck van der Linden sqa...@gmail.comwrote: maybe I'm not reading things right, but I think your 'ready' method is returning true when the browser is not ready I might also recommend a more current version of Watir, v1.6.7 is a little old You might want to try this with 1.9.1 and see if it works any differently for you. On Nov 21, 9:00 am, xeranas anorku...@gmail.com wrote: Hi all, I trying to do simple task fill 2 fields and click 'add', and so on.. ~ 80 times. But currently it crashes after 20-30 times with errors below. I guess this must be 'synchronous' problem.. But I have no idea how I can fix it. I use methods: check page with ie.busy and ie.readyState, before every action, do check if field exist before making action with it.. nothing is useful except sleep, but it's very slow down script. Please note that ~20 times watir handle situation correctly, but later somehow can't find method which was used ~20 times before in loop.. If you interested for my code:http://pastebin.com/xEKHp129 C:/Ruby187/lib/ruby/gems/1.8/gems/watir-1.6.7/lib/watir/ input_elements.rb:415:in `method_missing': fireEvent (WIN32OLERuntimeError) OLE error code:80004005 in htmlfile Unspecified error. HRESULT error code:0x80020009 Exception occurred. from C:/Ruby187/lib/ruby/gems/1.8/gems/watir-1.6.7/lib/watir/ input_eleme nts.rb:415:in `type_by_character' from C:/Ruby187/lib/ruby/gems/1.8/gems/watir-1.6.7/lib/watir/ input_eleme nts.rb:427:in `characters_in' from C:/Ruby187/lib/ruby/gems/1.8/gems/watir-1.6.7/lib/watir/ input_eleme nts.rb:412:in `type_by_character' from C:/Ruby187/lib/ruby/gems/1.8/gems/watir-1.6.7/lib/watir/ input_eleme nts.rb:378:in `set' from coll_items1000.rb:52 from coll_items1000.rb:42:in `times' from coll_items1000.rb:42 -- Before posting, please readhttp://watir.com/support. In short: search before you ask, be nice. watir-general@googlegroups.com http://groups.google.com/group/watir-general watir-general+unsubscr...@googlegroups.comhttp://groups.google.com/group/watir-general%0Awatir-general+unsubscr... -- Before posting, please read http://watir.com/support. In short: search before you ask, be nice. watir-general@googlegroups.com http://groups.google.com/group/watir-general watir-general+unsubscr...@googlegroups.com
[wtr-general] How to Access JavaScript Variables
I want access some javascript global variables, but out of luck so at first I want know that I use correct methods to take value. lets say on website exist simple script: script type=text/javascript var myvar = 5; /script I was trying with methods below access myvar value: $myBrowser.ie.Document.targetWindow.myvar $myBrowser.execute_script(targetWindow.myvar) $myBrowser.execScript(targetWindow.myvar) Is these methods are correctly write? What differences between them? -- Before posting, please read http://watir.com/support. In short: search before you ask, be nice. watir-general@googlegroups.com http://groups.google.com/group/watir-general watir-general+unsubscr...@googlegroups.com
[wtr-general] method_missing: fireEvent WIN32OLERuntimeError
Hi all, I trying to do simple task fill 2 fields and click 'add', and so on.. ~ 80 times. But currently it crashes after 20-30 times with errors below. I guess this must be 'synchronous' problem.. But I have no idea how I can fix it. I use methods: check page with ie.busy and ie.readyState, before every action, do check if field exist before making action with it.. nothing is useful except sleep, but it's very slow down script. Please note that ~20 times watir handle situation correctly, but later somehow can't find method which was used ~20 times before in loop.. If you interested for my code: http://pastebin.com/xEKHp129 C:/Ruby187/lib/ruby/gems/1.8/gems/watir-1.6.7/lib/watir/ input_elements.rb:415:in `method_missing': fireEvent (WIN32OLERuntimeError) OLE error code:80004005 in htmlfile Unspecified error. HRESULT error code:0x80020009 Exception occurred. from C:/Ruby187/lib/ruby/gems/1.8/gems/watir-1.6.7/lib/watir/ input_eleme nts.rb:415:in `type_by_character' from C:/Ruby187/lib/ruby/gems/1.8/gems/watir-1.6.7/lib/watir/ input_eleme nts.rb:427:in `characters_in' from C:/Ruby187/lib/ruby/gems/1.8/gems/watir-1.6.7/lib/watir/ input_eleme nts.rb:412:in `type_by_character' from C:/Ruby187/lib/ruby/gems/1.8/gems/watir-1.6.7/lib/watir/ input_eleme nts.rb:378:in `set' from coll_items1000.rb:52 from coll_items1000.rb:42:in `times' from coll_items1000.rb:42 -- Before posting, please read http://watir.com/support. In short: search before you ask, be nice. watir-general@googlegroups.com http://groups.google.com/group/watir-general watir-general+unsubscr...@googlegroups.com
[wtr-general] Re: Verify that all page requests are finished
Thanks Jarmo Pertman and Dave McNulla I will try yours suggestions. Yes this application is user-unfriendly.. I hope development make more friendly on next version. On 30 Gruo, 00:04, Dave McNulla mcnu...@gmail.com wrote: That sounds really ugly from a usability standpoint. Maybe it could be implemented as a wizard, get input, click Next, get next set of choices, select one, click next, etc. The hard part there is getting people to scrap a bad design - they love their output even if it's ugly. You'll have to find an effective way to get them to scrap it. Other possibilities (not sure which will work): * wait until clicking on the next field does not produce a popup (sounds like it wouldn't work) * look for an attribute change in the next field, wait until that happens Good luck, Dave On Dec 28, 7:06 am, xeranas anorku...@gmail.com wrote: If user too quick click next input (e.g. field 'B') while request for field 'A' isn't finished warning pop-up shows up. After it close pop- up and request still isn't finished user can fill other inputs (field B, field C and so on) no more pop-up shows up (it shows only once via request) BUT after request field 'A' is was finished all fields which was filled until field 'A' response are cleared (deleted values). what is the essential point of that request or these requests These request sent data to db or other services and waiting response. The response data needed for collecting future data. Application sent and retrieve data on almost every input. User are forced wait till get response (all additional inputs will be cleared if user enters). These request are visible on browser status bar, but it looks like Watir don't see them :( On 28 Gruo, 14:14, Jarmo Pertman jarm...@gmail.com wrote: So what happens if the request is made? How do you as a user use that page and what value will you get if that request is made? In another way - what is the essential point of that request or these requests? Try to think in these terms what could you set as your condition. If there isn't any point, then do you even have to care about these requests? Why? Jarmo Pertman - IT does really matter -http://www.itreallymatters.net On Dec 27, 5:03 pm, xeranas anorku...@gmail.com wrote: Hi, i'm new with Watir and I need help with situation below.. I'm trying create tests for web application. The problem is that almost every input send request to main server when input was triggered. After request response page content have not changed. The only one field request can exist at time on my web application. Other inputs must wait until previous field request are finished. So i'm stuck. ie.wait not help, ie.wait_until with .exit? also not help (page content haven't change after response). The only thing help is sleep. But i don't want add sleep on every input X sec (response sometime get almost instant but sometime need wait more than 1 min..) I need be sure that no requests running at the moment before next test step. Maybe I misread function which help with my problem.. Any help is much appreciated -- Before posting, please read http://watir.com/support. In short: search before you ask, be nice. watir-general@googlegroups.com http://groups.google.com/group/watir-general watir-general+unsubscr...@googlegroups.com
[wtr-general] Re: Verify that all page requests are finished
If user too quick click next input (e.g. field 'B') while request for field 'A' isn't finished warning pop-up shows up. After it close pop- up and request still isn't finished user can fill other inputs (field B, field C and so on) no more pop-up shows up (it shows only once via request) BUT after request field 'A' is was finished all fields which was filled until field 'A' response are cleared (deleted values). what is the essential point of that request or these requests These request sent data to db or other services and waiting response. The response data needed for collecting future data. Application sent and retrieve data on almost every input. User are forced wait till get response (all additional inputs will be cleared if user enters). These request are visible on browser status bar, but it looks like Watir don't see them :( On 28 Gruo, 14:14, Jarmo Pertman jarm...@gmail.com wrote: So what happens if the request is made? How do you as a user use that page and what value will you get if that request is made? In another way - what is the essential point of that request or these requests? Try to think in these terms what could you set as your condition. If there isn't any point, then do you even have to care about these requests? Why? Jarmo Pertman - IT does really matter -http://www.itreallymatters.net On Dec 27, 5:03 pm, xeranas anorku...@gmail.com wrote: Hi, i'm new with Watir and I need help with situation below.. I'm trying create tests for web application. The problem is that almost every input send request to main server when input was triggered. After request response page content have not changed. The only one field request can exist at time on my web application. Other inputs must wait until previous field request are finished. So i'm stuck. ie.wait not help, ie.wait_until with .exit? also not help (page content haven't change after response). The only thing help is sleep. But i don't want add sleep on every input X sec (response sometime get almost instant but sometime need wait more than 1 min..) I need be sure that no requests running at the moment before next test step. Maybe I misread function which help with my problem.. Any help is much appreciated -- Before posting, please read http://watir.com/support. In short: search before you ask, be nice. watir-general@googlegroups.com http://groups.google.com/group/watir-general watir-general+unsubscr...@googlegroups.com
[wtr-general] Verify that all page requests are finished
Hi, i'm new with Watir and I need help with situation below.. I'm trying create tests for web application. The problem is that almost every input send request to main server when input was triggered. After request response page content have not changed. The only one field request can exist at time on my web application. Other inputs must wait until previous field request are finished. So i'm stuck. ie.wait not help, ie.wait_until with .exit? also not help (page content haven't change after response). The only thing help is sleep. But i don't want add sleep on every input X sec (response sometime get almost instant but sometime need wait more than 1 min..) I need be sure that no requests running at the moment before next test step. Maybe I misread function which help with my problem.. Any help is much appreciated -- Before posting, please read http://watir.com/support. In short: search before you ask, be nice. watir-general@googlegroups.com http://groups.google.com/group/watir-general watir-general+unsubscr...@googlegroups.com