Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Watir open multiple browser's or tab's

How can I open more than one browser using my code-watir, for example via a while loop from 0 to 10?

Here is my code:

require 'watir-webdriver'
require 'headless'
class Page
    @headless = Headless.new
    @headless.start
    @browser = Watir::Browser.start 'bit.ly/***'
    def self.get_connection

        puts "Browser started"  
        puts @browser.title
        @browser.driver.manage.timeouts.implicit_wait = 3 #3 seconds

        @browser.select_list(:name => 'ctl00$tresc$111').select_value('6')
        puts "Selected country"  
        @browser.select_list(:name => 'ctl00$tresc$222').wait_until_present
        @browser.select_list(:name => 'ctl00$tresc$333').select_value('95')
        puts "Selected city" 
    end

    def self.close_connection
        @browser.close
        @headless.destroy
    end
end

Page.get_connection
Page.close_connection

But how to do something like this?

while i < 10
Page.get_connection
end
like image 555
brabertaser19 Avatar asked Oct 06 '22 10:10

brabertaser19


1 Answers

This should open ten browsers:

10.times {Watir::Browser.new}

If you want to use the browsers later, you can put them in a hash:

browsers = {}
(0..9).each {|i| browsers[i] = Watir::Browser.new}
browsers[0].goto "google.com"
browsers[1].goto "yahoo.com"
like image 73
Željko Filipin Avatar answered Oct 10 '22 01:10

Željko Filipin