简体   繁体   中英

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

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"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM