[ 
http://jira.openqa.org/browse/WTR-462?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=19999#action_19999
 ] 

Alan Baird commented on WTR-462:
--------------------------------

Simplified quite a lot, this is the design of one of the frameworks we are 
using:

class MyFramework < Watir::IE
  def initialize
    super
  end
  def goto_google
    goto 'google.com'
  end
  def recycle_browser
    close
    _new_window_init
  end
end

I never liked this design, but I inherited it and have to live with it.  It 
would be nice, for reasons that aren't worth going into, for the MyFramework 
class to handle it's own browser if it detected an error and needed to restart 
itself.  That's why I asked the question, since I couldn't really tell if 
restarting the underlying IE instance without getting a new Watir::IE instance 
was something that *should* be done or not.

I prefer to design frameworks that use Watir with a pointer to an instance of 
Watir, more like this:

class MyFramework
  attr_accessor :br  
  def initialize
    @br = Watir::IE.new
  end
  def goto_google
    @br.goto 'google.com'
  end
  def recycle_browser
    @br.close
    @br = Watir::IE.new
  end
end

Mind you, these are really simplistic, I'm just trying to show the concept.  
However, I have been in arguments where people don't like typing all the @br's 
in the second example and want to use the first.  To me, this issue (not being 
able to restart IE out from under an instance of Watir::IE) it a good argument 
for designing it the 2nd way.

Sorry for the long winded explanation.  At the very least, I think close should 
end with setting @closing since there is already a wait in there for IE.  I 
will try to send a pull request soon.
    

> Watir::IE#close doesn't set @closing variable to false after closing IE
> -----------------------------------------------------------------------
>
>                 Key: WTR-462
>                 URL: http://jira.openqa.org/browse/WTR-462
>             Project: Watir
>          Issue Type: Bug
>          Components: Other
>    Affects Versions: 1.6.7
>         Environment: WIN XP, IE7
>            Reporter: Alan Baird
>            Priority: Major
>
> All -
> Consider the following example where I am trying to restart a browser using 
> Watir's instance methods:
> irb(main):001:0> require 'watir'
> => true
> irb(main):002:0> br = Watir::IE.new
> => #<Watir::IE:0x2e384a4 url="about:blank" title=""> irb(main):003:0> br.goto 
> 'google.com'
> => 1.641
> irb(main):004:0> br.close
> => nil
> irb(main):005:0> br._new_window_init
> => 0.422
> irb(main):006:0> br.goto 'google.com'
> => 0.859
> irb(main):007:0> br.close
> => nil
> This actually works just fine until the last line where the browser doesn't 
> close (but the first br.close does close the browser).  
> So, I examined the close method:
>     # Closes the Browser
>     def close
>       return unless exists?
>       @closing = true
>       @ie.stop
>       wait rescue nil
>       chwnd = @ie.hwnd.to_i
>       @ie.quit
>       while Win32API.new("user32","IsWindow", 'L', 'L').Call(chwnd) == 1
>         sleep 0.3
>       end
>     end
> Note that @closing is never set to false.  Thus, whenever close is called 
> subsequently, it will return immediately because the first thing #exists? 
> does is: 
>       return false if @closing
> The fix is simple, just add @closing = false to the end of #close.  I tested 
> this in a monkeypatched version and it fixes the problem as I recreated it in 
> IRB above.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://jira.openqa.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        
_______________________________________________
Wtr-development mailing list
Wtr-development@rubyforge.org
http://rubyforge.org/mailman/listinfo/wtr-development

Reply via email to