testing - watir webdriver try catch proxy -


here working codes connecting proxy watir webdriver:

b = watir::browser.new :chrome, :switches => %w[--proxy-server=xxx.xxx.xx.xxx:80] 

now if proxy don't work, how can catch , try other one? try , catch or cases?

it looks can determine if proxy works going page. if chrome cannot connect proxy, displays message of "unable connect proxy server." therefore, can try:

1) going page using proxy 2) check message 3) if message appears, try proxy 4) if message not appear, proxy works

for example, following attempt first proxy, fail. go try next proxy, etc.

proxy_servers = ['111.111.11.111:80', '222.222.22.222:80']  browser = nil  proxy_servers.each |proxy|     browser = watir::browser.new :chrome, :switches => ["--proxy-server=#{proxy}"]      # try going page     browser.goto 'http://www.google.ca'      #if chrome says "unable connect proxy server", try 1     if browser.text.include?('unable connect proxy server')         browser.close     else         break     end end  # throw exception if valid proxy server cannot found raise 'no valid proxy servers found' unless browser.exists? 

Comments

Popular posts from this blog

matlab - Deleting rows with specific rules -

php - MySQLi multi_query results for later use -