I have the following program using watir-webdriver, I have made the code
simplest and tried to keep whatever there is, I have used methods so
expanding methods gives so many begin-rescue-ensure sections. But I
think that hardly is the point. The issue is – at the end of this code
run few thousand times on multithreading, I see few browsers are still
there unclosed. Am not able to find reason/solution. please help.
Though I have kept close in ensure section.
begin
begin
br=nil
while !br
br=Watir::Browser.new :ie
end
rescue => e
if br !=nil
br.close
end
retry
end
###############
execute(br) #it has begin-rescue statements also
ensure
if br!=nil
br.close
end
end
Try closing with this instead of checking for nil first, it seems more
reliable:
br.close rescue nil
What is the diffrence?
I’d also add that line before “br=Watir::Browser.new :ie”, just in case
there’s something there.
even if something is there… it will get overwritten…right?
Are these popup windows remaining? I think I covered closing popups in a
previous thread.
no-not pop-ups.
When all else fails, there’s always this option:
Try closing with this instead of checking for nil first, it seems more
reliable:
br.close rescue nil
What is the diffrence?
This will attempt to close the browser even if it is nil, it just
removes the chance of the “if” statement missing something.
I’d also add that line before “br=Watir::Browser.new :ie”, just in case
there’s something there.
even if something is there… it will get overwritten…right?
If there is something there, the window might remain open, and webdriver
could open a new window while abandoning the old one.
This will attempt to close the browser even if it is nil, it just
removes the chance of the “if” statement missing something.
I’d also add that line before “br=Watir::Browser.new :ie”, just in case
there’s something there.
even if something is there… it will get overwritten…right?
If there is something there, the window might remain open, and webdriver
could open a new window while abandoning the old one.
but this says br is not defined. Isnt it correct that br is not defined
but we are using ‘br’.
Probably you are suggesting correct thing which I am not understanding,
that is why even putting browser.close() in ensure section gives some
unclosed browser at the end.
If your browser is disconnected from the local variable at any point,
you’ll lose the ability to close it without resorting to the task
manager. That might happen here:
execute(br)
You could avoid this by using a global or instance variable for the
browser rather than handing it to a method like that.
The first example above is obviously a deliberate failure, but something
akin to that might be happening somewhere in your code.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.