Are you seeing two instances of the same browser, or two different 
browsers?   Is there somewhere else in you code that creates a browser? 
 maybe the issue is not in the stuff you have below but in some other piece 
of code, perhaps elsewhere in env.rb  or another file in the support 
directory.  Do a global search of all your code for "Watir::Browser.new" 
and see if you find another one somewhere you forgot about or forgot to 
remove. 

BTW a potential problem I see with your stuff is that you could have env 
variables defining more than one browser type and more than one test env, 
and if you do you are at the mercy of the order of your ifs as to what gets 
used.  Even if you set the BETA variable, if the TEST variable already 
existed on that system for some reason, it's the one that would get used. 

I'd recommend looking for TWO env variables only.  I'd call them BROWSER 
and TEST_ENV.   That way if one already exists, your new one defined at 
runtime would override the old one.

Set BROWSER to either "firefox" "chrome" or "phantomjs
Set TEST_ENV to either "dev" "test" or "beta"


Then in env.rb do something like this

  $BROWSER_TYPE = ENV['BROWSER']
  browser = Watir::Browser.new $ROWSER_TYPE.to_sym

  $TEST_ENVIRONMENT = ENV["TEST_ENV"]
  case $TEST_ENVIRONMENT
  when "test"
    $env_dtm = "http://xxx.yyy.zzz.qqq/";
    $env_webstore = "http://xxx1.yyy1.zzz1.qqq1/";
  when "dev"
    $env_dtm = "http://xxx2.yyy2.zzz2.qqq2/"; 
    $env_webstore = "http://xxx3.yyy3.zzz3.qqq3/";
 when "beta"
    $env_dtm = "http://xxx4.yyy4.zzz4.qqq4/"; or
    $env_webstore = "http://xxx5.yyy5.zzz5.qqq5/";
  else raise "I don't understand the test environment setting of 
#{$TEST_ENVIRONMENT}"
  end

I'm creating constants above because sometimes you may need other logic in 
code that is conditional based on the browser in use, or the test 
environment, so it may be useful to have access to that info inside of 
steps, helper methods, data objects, etc   If for example there is a test 
that must never be run against production, you can guard inside an 
appropriate step to make sure that does not take place.  (usually that's 
controlled by tags, but you can't count on someone executing tests manually 
to remember to include the proper exclude tags)

(Note to other readers: some of the above discussion (env.rb, support 
directlry, tags, steps) is specific to cucumber, which I gather the OP is 
using.  If those parts lost you, that's why.  in Cucumber the env.rb file 
is run first before anything else, so is used to setup test environment, 
configuration settings, etc, it's also where most of us using Cukes create 
our browser object.  ) 

On Monday, April 8, 2013 6:39:12 AM UTC-7, [email protected] wrote:
>
> Hey Guys,
>
> I have an issue where 2 browsers are being started but only one is being 
> interacted with. When the tests finish, only one of the 2 browsers is 
> closed. 
>
> I have this in my env.rb:
>
> def start_browser
>   if ENV['HEADLESS'] == 'true'
>     @browser = Watir::Browser.new(:phantomjs)
>   elsif ENV['FIREFOX'] == 'true'
>     @browser = Watir::Browser.new(:firefox)
>   elsif ENV['CHROME'] == 'true'
>     @browser = Watir::Browser.new(:chrome)
>   end
>
>   if ENV['TEST'] == 'true'
>     $env_dtm = "http://xxx.yyy.zzz.qqq/";
>     $env_webstore = "http://xxx1.yyy1.zzz1.qqq1/";
>   elsif ENV['DEV'] == 'true'
>     $env_dtm = "http://xxx2.yyy2.zzz2.qqq2/"; 
>     $env_webstore = "http://xxx3.yyy3.zzz3.qqq3/";
>   elsif ENV['BETA'] == 'true'
>     $env_dtm = "http://xxx4.yyy4.zzz4.qqq4/"; or
>     $env_webstore = "http://xxx5.yyy5.zzz5.qqq5/";
>   end
>
> end
>
> I have this because I pass in two variables on the command line to dictate 
> on what environment I want to run my tests in and also on what driver.
>
> Ever since I put in the variables for the environments I have been getting 
> two browsers appear.
>
> Is there anything I can do that will close everything.
>
> Kind regards,
> Knoll
>

-- 
-- 
Before posting, please read http://watir.com/support. In short: search before 
you ask, be nice.

[email protected]
http://groups.google.com/group/watir-general
[email protected]

--- 
You received this message because you are subscribed to the Google Groups 
"Watir General" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to