How to use proxy method of Selenium.WebDriver.Remote.Http Package

Best Selenium code snippet using Selenium.WebDriver.Remote.Http.proxy

capybara.rb

Source:capybara.rb Github

copy

Full Screen

...6require 'extensions/capybara-mechanize-extensions'7class CapybaraSetup8 attr_reader :driver9 def initialize10 http_proxy = ENV['HTTP_PROXY'] || ENV['http_proxy']11 browser_cli_args = ENV['BROWSER_CLI_ARGS'].split(/\s+/).compact if ENV['BROWSER_CLI_ARGS']12 capybara_opts = {:environment => ENV['ENVIRONMENT'],13 :http_proxy => http_proxy,14 :profile => ENV['FIREFOX_PROFILE'],15 :browser => ENV['BROWSER'],16 :webdriver_proxy_on => ENV['PROXY_ON'],17 :url => ENV['REMOTE_URL'],18 :chrome_switches => ENV['CHROME_SWITCHES'],19 :firefox_prefs => ENV['FIREFOX_PREFS'],20 :args => browser_cli_args21 }22 selenium_remote_opts = {:os => ENV['PLATFORM'],23 :os_version => ENV['PLATFORM_VERSION'],24 :browser_name => ENV['REMOTE_BROWSER'],25 :browser_version => ENV['REMOTE_BROWSER_VERSION'],26 :url => ENV['REMOTE_URL']27 }28 custom_opts = {:job_name => ENV['SAUCE_JOB_NAME'],29 :max_duration => ENV['SAUCE_MAX_DURATION'],30 :firefox_cert_path => ENV['FIREFOX_CERT_PATH'],31 :firefox_cert_prefix => ENV['FIREFOX_CERT_PREFIX'],32 :browserstack_build => ENV['BS_BUILD'],33 :browserstack_debug => ENV['BS_DEBUG'] || 'true', # BrowserStack debug mode on by default34 :browserstack_device => ENV['BS_DEVICE'],35 :browserstack_device_orientation => ENV['BS_DEVICE_ORIENTATION'],36 :browserstack_project => ENV['BS_PROJECT'],37 :browserstack_resolution => ENV['BS_RESOLUTION']38 }39 validate_env_vars(capybara_opts.merge(selenium_remote_opts)) #validate environment variables set using cucumber.yml or passed via command line40 if(capybara_opts[:http_proxy])41 proxy_uri = URI(capybara_opts[:http_proxy])42 @proxy_host = proxy_uri.host43 @proxy_port = proxy_uri.port44 end45 capybara_opts[:browser] = capybara_opts[:browser].intern #update :browser value to be a symbol, required for Selenium46 selenium_remote_opts[:browser_name] = selenium_remote_opts[:browser_name].intern if selenium_remote_opts[:browser_name]#update :browser value to be a symbol, required for Selenium47 Capybara.run_server = false #Disable rack server48 Capybara.ignore_hidden_elements = false49 [capybara_opts, selenium_remote_opts, custom_opts].each do |opts| #delete nil options and environment (which is only used for validation)50 opts.delete_if {|k,v| (v.nil? or k == :environment)}51 end52 case capybara_opts[:browser] 53 when :mechanize then54 @driver = register_mechanize_driver(capybara_opts)55 else56 @driver = register_selenium_driver(capybara_opts, selenium_remote_opts, custom_opts)57 end58 Capybara.default_driver = @driver59 end60 private61 def validate_env_vars(opts)62 msg1 = 'Please ensure following environment variables are set ENVIRONMENT [int|test|stage|live], BROWSER[headless|ie|chrome|firefox] and HTTP_PROXY (if required)'63 msg2 = 'Please ensure the following environment variables are set PLATFORM, REMOTE_URL, REMOTE_BROWSER (browser to use on remote machine), HTTP_PROXY (if required), REMOTE_BROWSER_PROXY (if required) and BROWSER_VERSION (if required)'64 [:environment, :browser].each do |item|65 !opts.has_key?(item) or opts[item]==nil ? raise(msg1) : '' 66 end67 if opts[:browser]=='remote'68 [:url, :browser_name].each do |item|69 !opts.has_key?(item) or opts[item]==nil ? raise(msg2) : '' 70 end71 end72 end73 # WARNING: This modifies the Firefox profile passed in the parameters74 def update_firefox_profile_with_certificates(profile, certificate_path, certificate_prefix = '')75 profile_path = profile.layout_on_disk76 77 # Create links to the certificate files in the profile directory78 ['cert8.db', 'key3.db', 'secmod.db'].each do |cert_file|79 source_file = "#{certificate_prefix}#{cert_file}"80 source_path = "#{certificate_path}" + File::SEPARATOR + source_file81 dest_path = profile_path + File::SEPARATOR + cert_file82 if(! File.exist?(source_path))83 raise "Firefox cert db file #{source_path} does not exist."84 end85 FileUtils.cp(source_path, dest_path)86 end 87 # Force the certificates to get pulled into the profile88 profile = Selenium::WebDriver::Firefox::Profile.new(profile_path)89 # Avoid Firefox certificate alerts90 profile["security.default_personal_cert"] = 'Select Automatically'91 92 return profile93 end94 def register_selenium_driver(opts,remote_opts,custom_opts)95 Capybara.register_driver :selenium do |app|96 if opts[:firefox_prefs] || opts[:profile]97 opts[:profile] = create_profile(opts[:profile], opts[:firefox_prefs])98 if custom_opts[:firefox_cert_path]99 opts[:profile] = update_firefox_profile_with_certificates(opts[:profile], custom_opts[:firefox_cert_path], custom_opts[:firefox_cert_prefix])100 end101 end102 opts[:switches] = [opts.delete(:chrome_switches)] if(opts[:chrome_switches])103 if opts[:browser] == :remote104 client = Selenium::WebDriver::Remote::Http::Default.new105 client.proxy = set_client_proxy(opts)106 remote_opts[:firefox_profile] = opts.delete :profile if opts[:profile]107 remote_opts['chrome.switches'] = opts.delete :switches if opts[:switches]108 caps = Selenium::WebDriver::Remote::Capabilities.new(remote_opts)109 add_custom_caps(caps, custom_opts) if remote_opts[:url].include? 'saucelabs' #set sauce specific parameters - will this scupper other on sauce remote jobs? 110 add_browserstack_caps(caps, custom_opts) if remote_opts[:url].include? 'browserstack' #set browserstack specific parameters111 opts[:desired_capabilities] = caps112 opts[:http_client] = client113 end114 clean_opts(opts, :http_proxy, :webdriver_proxy_on, :firefox_prefs)115 Capybara::Selenium::Driver.new(app,opts)116 end 117 :selenium118 end119 def add_custom_caps(caps, custom_opts)120 sauce_time_limit = custom_opts.delete(:max_duration).to_i #note nil.to_i == 0 121 # This no longer works with the latest selenium-webdriver release122 #caps.custom_capabilities({:'job-name' => (custom_opts[:job_name] or 'frameworks-unamed-job'), :'max-duration' => ((sauce_time_limit if sauce_time_limit != 0) or 1800)}) 123 end124 def add_browserstack_caps(caps, custom_opts)125 caps[:'build'] = custom_opts[:browserstack_build] if custom_opts[:browserstack_build]126 caps[:'browserstack.debug'] = custom_opts[:browserstack_debug] if custom_opts[:browserstack_debug]127 caps[:'device'] = custom_opts[:browserstack_device] if custom_opts[:browserstack_device]128 caps[:'deviceOrientation'] = custom_opts[:browserstack_device_orientation] if custom_opts[:browserstack_device_orientation]129 caps[:'project'] = custom_opts[:browserstack_project] if custom_opts[:browserstack_project]130 caps[:'resolution'] = custom_opts[:browserstack_resolution] if custom_opts[:browserstack_resolution]131 end132 def set_client_proxy(opts)133 Selenium::WebDriver::Proxy.new(:http => opts[:http_proxy]) if opts[:http_proxy] && opts[:webdriver_proxy_on] != 'false' #set proxy on client connection if required, note you may use ENV['HTTP_PROXY'] for setting in browser (ff profile) but not for client conection, hence allow for PROXY_ON=false134 end135 def create_profile(profile_name = nil, additional_prefs = nil)136 additional_prefs = JSON.parse(additional_prefs) if additional_prefs137 if(additional_prefs && !profile_name)138 profile = Selenium::WebDriver::Firefox::Profile.new139 profile.native_events = true140 elsif(profile_name == 'BBC_INTERNAL')141 profile = Selenium::WebDriver::Firefox::Profile.new142 if(@proxy_host && @proxy_port) 143 profile["network.proxy.type"] = 1144 profile["network.proxy.no_proxies_on"] = "*.sandbox.dev.bbc.co.uk,*.sandbox.bbc.co.uk"145 profile["network.proxy.http"] = @proxy_host 146 profile["network.proxy.ssl"] = @proxy_host 147 profile["network.proxy.http_port"] = @proxy_port148 profile["network.proxy.ssl_port"] = @proxy_port149 end150 profile.native_events = true151 else152 profile = Selenium::WebDriver::Firefox::Profile.from_name profile_name153 profile.native_events = true154 end155 if additional_prefs156 additional_prefs.each do |k, v|157 profile[k] = v158 end159 end160 profile161 end162 def register_mechanize_driver(opts)...

Full Screen

Full Screen

minitest_helper.rb

Source:minitest_helper.rb Github

copy

Full Screen

1require File.dirname(__FILE__) + '/config/automation_config';2require File.dirname(__FILE__) + '/config/proxy/settings';3require 'minitest/autorun' 4require 'shoulda/context' 5require 'selenium-webdriver' 6require 'browsermob/proxy'7require 'timeout'8require 'minitest/reporters'9Minitest::Reporters.use! Minitest::Reporters::DefaultReporter.new10#### HEALTHCENTRAL11HC_BASE_URL = Configuration["healthcentral"]["base_url"]12HC_DRUPAL_URL = Configuration["healthcentral"]["drupal_url"]13IMMERSIVE_URL = Configuration["healthcentral"]["immersive"]14COLLECTION_URL = Configuration["collection_url"]15ASSET_HOST = Configuration["asset_host"]16MED_BASE_URL = Configuration["medtronic"]["base_url"]17#### BERKELEY WELLNESS18BW_BASE_URL = Configuration["berkeley"]["base_url"]19BW_ASSET_HOST = Configuration["berkeley"]["asset_host"]20#### THE BODY21BODY_URL = Configuration["thebody"]["base_url"]22THE_BODY_ASSET_HOST = Configuration["thebody"]["asset_host"]23 24$_cache_buster ||= "?foo=#{rand(36**8).to_s(36)}"25def firefox26 # Selenium::WebDriver::Firefox::Binary.path= '/opt/firefox/firefox'27 # Selenium::WebDriver::Firefox::Binary.path= '/Applications/Firefox.app/Contents/MacOS/firefox'28 @driver = Selenium::WebDriver.for :firefox29 @driver.manage.window.resize_to(1224,1000)30 @driver.manage.timeouts.implicit_wait = 531end32def firefox_with_proxy33 proxy_location = Settings.location34 @server = BrowserMob::Proxy::Server.new(proxy_location)35 @server.start36 @proxy = server.create_proxy37 @profile = Selenium::WebDriver::Firefox::Profile.new38 @profile.proxy = @proxy.selenium_proxy39 @driver = Selenium::WebDriver.for :firefox, :profile => @profile40 @driver.manage.window.resize_to(1224,1000)41 @driver.manage.timeouts.implicit_wait = 542end43def fire_fox_with_secure_proxy44 proxy_location = Settings.location45 $_server ||= BrowserMob::Proxy::Server.new(proxy_location).start46 @proxy = $_server.create_proxy47 @profile = Selenium::WebDriver::Firefox::Profile.new48 @profile.proxy = @proxy.selenium_proxy(:http, :ssl)49 @driver = Selenium::WebDriver.for :firefox, :profile => @profile50 @driver.manage.window.resize_to(1224,1000)51 @driver.manage.timeouts.implicit_wait = 352 @driver.manage.timeouts.page_load = 2453end54def fire_fox_remote_proxy55 proxy_location = Settings.location56 server = BrowserMob::Proxy::Server.new(proxy_location)57 server.start58 @proxy = server.create_proxy59 @profile = Selenium::WebDriver::Firefox::Profile.new60 @profile.proxy = @proxy.selenium_proxy(:http, :ssl)61 caps = Selenium::WebDriver::Remote::Capabilities.new(62 :browser_name => "firefox", :firefox_profile => @profile63 )64 @driver = Selenium::WebDriver.for(65 :remote,66 url: 'http://jenkins.choicemedia.com:4444//wd/hub',67 desired_capabilities: caps) 68 @driver.manage.window.resize_to(1224,1000)69 @driver.manage.timeouts.implicit_wait = 570end71def mobile_fire_fox_with_secure_proxy72 proxy_location = Settings.location73 $_server ||= BrowserMob::Proxy::Server.new(proxy_location).start74 75 @proxy = $_server.create_proxy76 @profile = Selenium::WebDriver::Firefox::Profile.new77 @profile.proxy = @proxy.selenium_proxy(:http, :ssl)78 @profile['general.useragent.override'] = 'Mozilla/5.0 (Linux; U; Android 4.0.3; ko-kr; LG-L160L Build/IML74K) AppleWebkit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30'79 @driver = Selenium::WebDriver.for :firefox, :profile => @profile80 @driver.manage.window.resize_to(425,960)81 @driver.manage.timeouts.implicit_wait = 582 @driver.manage.timeouts.page_load = 2483end84def fire_fox_remote85 @driver = Selenium::WebDriver.for(86 :remote,87 url: 'http://jenkins.choicemedia.com:4444//wd/hub',88 desired_capabilities: :firefox)89 @driver.manage.window.resize_to(1224,1000)90 @driver.manage.timeouts.implicit_wait = 591end92def cleanup_driver_and_proxy93 @driver.quit 94 @proxy.close95end96def phantomjs97 @driver = Selenium::WebDriver.for :remote, url: 'http://localhost:8001'98end99def visit(url)100 preload_page(url)101 begin102 @driver.navigate.to url 103 rescue Timeout::Error, Net::ReadTimeout, Selenium::WebDriver::Error::TimeOutError104 end105 begin106 @driver.execute_script("window.stop();")107 rescue Timeout::Error, Net::ReadTimeout, Selenium::WebDriver::Error::JavascriptError108 end109 110 #Avoid race conditions111 sleep 0.75112end113def preload_page(url)114 if ENV['TEST_ENV'] == "production" || ENV['TEST_ENV'] == "staging"115 begin116 RestClient::Request.execute(method: :get, url: url,117 timeout: 10)118 rescue RestClient::RequestTimeout119 end120 end121end122def wait_for_page_to_load123 begin124 Timeout::timeout(3) do125 loop until finished_loading?126 end127 rescue Timeout::Error, Net::ReadTimeout, EOFError128 end129 sleep 0.5130 begin131 @driver.execute_script("window.stop();")132 rescue Timeout::Error, Net::ReadTimeout133 end134end135def finished_loading?136 state = @driver.execute_script "return window.document.readyState"137 sleep 0.5138 if state == "complete"139 true140 else141 false142 end143end144def wait_for145 begin146 Selenium::WebDriver::Wait.new(:timeout => 3).until { yield }147 rescue Selenium::WebDriver::Error::NoSuchElementError, Selenium::WebDriver::Error::TimeOutError148 false149 rescue Net::ReadTimeout150 false151 end152end153#Find an element by css 154#If the element.diplayed? == true then return the element155#Otherwise return nil156def find(css)157 begin158 node = @driver.find_element(:css, css)159 node = nil if ( node.displayed? == false )160 rescue Selenium::WebDriver::Error::NoSuchElementError161 node = nil162 end163 node164end165#Looks for a Selenium element with the given css166#Text fails if the element is not on the page, or does not have text167#168# present_with_text?(".content_pad h1")169#170def present_with_text?(css)171 node = find css172 unless node173 self.errors.add(:functionality, "#{css} missing from page")174 end175 if node 176 unless node.text.length > 0177 self.errors.add(:functionality, "#{css} was blank")178 end179 end180end181def scroll_to_bottom_of_page182 @driver.execute_script("window.scrollTo(0,document.body.scrollHeight);")183end184def open_omniture_debugger185 @driver.execute_script "javascript:void(window.open(\"\",\"dp_debugger\",\"width=600,height=600,location=0,menubar=0,status=1,toolbar=0,resizable=1,scrollbars=1\").document.write(\"<script language='JavaScript' id=dbg src='https://www.adobetag.com/d1/digitalpulsedebugger/live/DPD.js'></\"+\"script>\"))"186 sleep 1187end188def get_omniture_from_debugger189 original_window = @driver.window_handles.first190 second_window = @driver.window_handles.last191 @driver.switch_to.window second_window192 wait_for { @driver.find_element(:css, 'td#request_list_cell').displayed? }193 omniture_node = find 'td#request_list_cell'194 begin195 omniture_text = omniture_node.text if omniture_node196 rescue Selenium::WebDriver::Error::StaleElementReferenceError197 omniture_text = nil198 end199 if omniture_text == nil200 sleep 1201 wait_for { @driver.find_element(:css, 'td#request_list_cell').displayed? }202 omniture_node = find 'td#request_list_cell'203 if omniture_node204 omniture_text = omniture_node.text205 else206 omniture_text = nil207 end208 end209 @driver.switch_to.window original_window210 omniture_text211end212def evaluate_script(script)213 begin214 @driver.execute_script "return #{script}"215 rescue Selenium::WebDriver::Error::JavascriptError216 "javascript error"217 end218end219def page_has_ad(ad_url)220 ads = []221 @proxy.har.entries.each do |entry|222 if entry.request.url.include?(ad_url)223 ads << entry.request.url224 end225 end226 if ads.compact.length >= 1227 true228 else229 false230 end231end...

Full Screen

Full Screen

tryUsamp_lib.rb

Source:tryUsamp_lib.rb Github

copy

Full Screen

...15 # Parameters returned : IE instance16 17 def Usampadmin_login(email,passwd)18 19# capabilities = Selenium::WebDriver::Remote::Capabilities.firefox #(:javascript_enabled => true, :proxy=> Selenium::WebDriver::Proxy.new(:http => "localhost:5865"))20# ie = Watir::Browser.new(:remote, :url => "http://127.0.0.1:4444/wd/hub", :desired_capabilities => capabilities)21 driver = Selenium::WebDriver.for :firefox, :profile => "Selenium"22 ie = Watir::Browser.new driver23 ie.goto('http://p.usampadmin.com')24 if ie.text.include?('Logout')25 ie.goto("http://p.usampadmin.com/login.php?hdMode=logout")26 end27 # Setting login credentials (email/password)28 ie.text_field(:name,"txtEmail").set email29 ie.text_field(:name,"txtPassword").set passwd30 #Click login button31 ie.button(:value, "Login").click32 # Checkpoint to verify that login was successful33 raise("Sorry! System Failed to login to Usampadmin") unless ie.link(:text,'Logout').exists?34 return ie35 end36 37 38 # Method to login to Surveyhead site39 # Parameters passed : email and password40 # Parameters returned : IE instance41 42 def Surveyhead_login(email,passwd)43 # New IE instance creation44 driver = Selenium::WebDriver.for :firefox, :profile => "Selenium"45 ff = Watir::Browser.new driver46 #ff.maximize47 ff.goto('http://www.p.surveyhead.com')48 # Setting login credentials (email/password)49 ff.text_field(:name, "txtEmail").set(email)50 ff.text_field(:name, "txtPassword").set(passwd)51 ff.button(:value,"login").click52 sleep 1553 if(ff.link(:id,"sb-nav-close").exists?)54 ff.link(:id,"sb-nav-close").click55 end56 sleep 557 58 if(ff.div(:id=>"loadingSurveys").exists?)59 while ff.div(:id=>"loadingSurveys").visible? do60 sleep 0.561 puts "waiting for surveys to load"62 end63 end64 65 raise("Sorry! System Failed to login to Usampadmin") unless ff.link(:text,'Logout').exists?66 return ff67 end68 69 # Method to login to sm.p.Surveyhead site70 # Parameters passed : email and password71 # Parameters returned : IE instance72 73 def Surveyhead_sm_login(email,passwd)74 75 # New IE instance creation76 driver = Selenium::WebDriver.for :firefox, :profile => "Selenium"77 ff = Watir::Browser.new driver78 #ff.maximize79 # Opening Usampadmin site80 ff.goto('http://www.sm.p.surveyhead.com')81 # Setting login credentials (email/password)82 ff.text_field(:name, "txtEmail").set(email)83 ff.text_field(:name, "txtPassword").set(passwd)84 #Click login button85 ff.button(:value, "Login").click86 sleep 1587 if(ff.link(:id,"sb-nav-close").exists?)88 ff.link(:id,"sb-nav-close").click89 end90 sleep 591 92 if(ff.div(:id=>"loadingSurveys").exists?)93 while ff.div(:id=>"loadingSurveys").visible? do94 sleep 0.595 puts "waiting for surveys to load"96 end97 end98 99 100 # Checkpoint to verify that login was successful101 raise("Sorry! System Failed to login to Usampadmin") unless ff.link(:text,'Logout').exists?102 return ff103 end104 105 106 #Parameters : IE instance107 def Network_site_login(email,passwd,type)108 109 # New Firefox instance creation110=begin 111 driver = Selenium::WebDriver.for :firefox, :profile => "Selenium"112 ff = Watir::Browser.new driver113 ff = Selenium::Client::Driver.new \114 :host => "localhost",115 :port => 4444,116 :browser => "*chrome",117 :url => "https://p.network.u-samp.com/login.php",118 :timeout_in_second => 60,119 :profile => "Selenium"120=end 121#ff.window.resize_to(800, 600)122 #ff.maximize()123 124 #capabilities = Selenium::WebDriver::Remote::Capabilities.firefox #(:javascript_enabled => true, :proxy=> Selenium::WebDriver::Proxy.new(:http => "localhost:5865"))125 #driver = Selenium::WebDriver::Remote::Capabilities.firefox(:profile => "Selenium")126 #ff = Watir::Browser.new(:remote, :url => "http://127.0.0.1:4444/wd/hub", :desired_capabilities => capabilities)127# ff = Selenium::Client::Driver.new \128# :host => "localhost",129# :port => 4444,130# :browser => "*chrome",131# :timeout_in_second => 60,132# :url => "https://p.network.u-samp.com/"133#134# ff.driver.start_new_browser_session(:captureNetworkTraffic => true)135 #firefox.exe -P Selenium136 #ff = custom C:\Program Files\Mozilla Firefox\firefox.exe -P firefox_browser137 #ff.clear_cookies138 # Opening Usampadmin site139 #capabilities = Selenium::WebDriver::Remote::Capabilities.firefox #(:profile => "Selenium") #(:javascript_enabled => true, :proxy=> Selenium::WebDriver::Proxy.new(:http => "localhost:5865"))140 #capabilities = Selenium::WebDriver::Remote::Capabilities.firefox (:profile => "Selenium")141 #ff = Watir::Browser.new(:remote, :url => "http://127.0.0.1:4444/wd/hub", :desired_capabilities => capabilities)142 #ff = Watir::Browser.new(:remote, :url => "http://127.0.0.1:4444/wd/hub", :desired_capabilities => capabilities)143 #ff = Watir::Browser.new(:remote, :desired_capabilities => capabilities)144 #ff = Watir::Browser.start("http://127.0.0.1:4444/wd/hub", :firefoxproxy, :remote)145 ff.goto('https://p.network.u-samp.com/login.php')146 #ff.clear_cookies147 # Setting login credentials (email/password)148 if (type == 'Client')149 ff.radio(:value, "Client").set150 else151 ff.radio(:value,"Publisher").set152 end153 ff.text_field(:id, "txtEmail").set(email)154 ff.text_field(:id, "txtPassword").set(passwd)155 #Click login button156 157 puts "Before loging to Network site"158 ...

Full Screen

Full Screen

ChromeUsamp_lib.rb

Source:ChromeUsamp_lib.rb Github

copy

Full Screen

...15 # Parameters returned : IE instance16 17 def Usampadmin_login(email,passwd)18 19# capabilities = Selenium::WebDriver::Remote::Capabilities.firefox #(:javascript_enabled => true, :proxy=> Selenium::WebDriver::Proxy.new(:http => "localhost:5865"))20# ie = Watir::Browser.new(:remote, :url => "http://127.0.0.1:4444/wd/hub", :desired_capabilities => capabilities)21 #driver = Selenium::WebDriver.for :firefox, :profile => "Selenium"22 #ie = Watir::Browser.new driver23 ie = Watir::Browser.new :chrome24 ie.goto('http://p.usampadmin.com')25 if ie.text.include?('Logout')26 ie.goto("http://p.usampadmin.com/login.php?hdMode=logout")27 end28 # Setting login credentials (email/password)29 ie.text_field(:name,"txtEmail").set email30 ie.text_field(:name,"txtPassword").set passwd31 #Click login button32 ie.button(:value, "Login").click33 # Checkpoint to verify that login was successful34 raise("Sorry! System Failed to login to Usampadmin") unless ie.link(:text,'Logout').exists?35 return ie36 end37 38 39 # Method to login to Surveyhead site40 # Parameters passed : email and password41 # Parameters returned : IE instance42 43 def Surveyhead_login(email,passwd)44 # New IE instance creation45 #driver = Selenium::WebDriver.for :firefox, :profile => "Selenium"46 #ff = Watir::Browser.new driver47 ff = Watir::Browser.new :chrome48 #ff.maximize49 ff.goto('http://www.p.ipoll.com')50 # Setting login credentials (email/password)51 ff.link(:id,"memLogin").click52 ff.text_field(:name, "txtEmail").set(email)53 ff.text_field(:name, "txtPassword").set(passwd)54 ff.button(:value,"login").click55 sleep 1556 if(ff.link(:id,"sb-nav-close").exists?)57 ff.link(:id,"sb-nav-close").click58 end59 sleep 560 61 if(ff.div(:id=>"loadingSurveys").exists?)62 while ff.div(:id=>"loadingSurveys").visible? do63 sleep 0.564 puts "waiting for surveys to load"65 end66 end67 68 raise("Sorry! System Failed to login to Usampadmin") unless ff.link(:text,'Logout').exists?69 return ff70 end71 72 # Method to login to sm.p.Surveyhead site73 # Parameters passed : email and password74 # Parameters returned : IE instance75 76 def Surveyhead_sm_login(email,passwd)77 78 # New IE instance creation79 #driver = Selenium::WebDriver.for :firefox, :profile => "Selenium"80 #ff = Watir::Browser.new driver81 ff = Watir::Browser.new :chrome82 #ff.maximize83 # Opening Usampadmin site84 ff.goto('http://www.sm.p.surveyhead.com')85 # Setting login credentials (email/password)86 ff.text_field(:name, "txtEmail").set(email)87 ff.text_field(:name, "txtPassword").set(passwd)88 #Click login button89 ff.button(:value, "Login").click90 sleep 1591 if(ff.link(:id,"sb-nav-close").exists?)92 ff.link(:id,"sb-nav-close").click93 end94 sleep 595 96 if(ff.div(:id=>"loadingSurveys").exists?)97 while ff.div(:id=>"loadingSurveys").visible? do98 sleep 0.599 puts "waiting for surveys to load"100 end101 end102 103 104 # Checkpoint to verify that login was successful105 raise("Sorry! System Failed to login to Usampadmin") unless ff.link(:text,'Logout').exists?106 return ff107 end108 109 110 #Parameters : IE instance111 def Network_site_login(email,passwd,type)112 113 # New Firefox instance creation114 #driver = Selenium::WebDriver.for :firefox, :profile => "Selenium"115 #driver = Selenium::WebDriver.for 116 ff = Watir::Browser.new :chrome117 #ff.window.resize_to(800, 600)118 #ff.maximize()119 120 #capabilities = Selenium::WebDriver::Remote::Capabilities.firefox #(:javascript_enabled => true, :proxy=> Selenium::WebDriver::Proxy.new(:http => "localhost:5865"))121 #driver = Selenium::WebDriver::Remote::Capabilities.firefox(:profile => "Selenium")122 #ff = Watir::Browser.new(:remote, :url => "http://127.0.0.1:4444/wd/hub", :desired_capabilities => capabilities)123# ff = Selenium::Client::Driver.new \124# :host => "localhost",125# :port => 4444,126# :browser => "*chrome",127# :timeout_in_second => 60,128# :url => "https://p.network.u-samp.com/"129#130# ff.driver.start_new_browser_session(:captureNetworkTraffic => true)131 #firefox.exe -P Selenium132 #ff = custom C:\Program Files\Mozilla Firefox\firefox.exe -P firefox_browser133 #ff.clear_cookies134 # Opening Usampadmin site135 #capabilities = Selenium::WebDriver::Remote::Capabilities.firefox #(:javascript_enabled => true, :proxy=> Selenium::WebDriver::Proxy.new(:http => "localhost:5865"))136 #ff = Watir::Browser.new(:remote, :url => "http://127.0.0.1:4444/wd/hub", :desired_capabilities => capabilities)137 #ff = Watir::Browser.new(:remote, :url => "http://127.0.0.1:4444/wd/hub", :desired_capabilities => capabilities)138 #ff = Watir::Browser.new(:remote, :desired_capabilities => capabilities)139 #ff = Watir::Browser.start("http://127.0.0.1:4444/wd/hub", :firefox, :remote)140 ff.goto('https://p.network.u-samp.com/login.php')141 #ff.clear_cookies142 # Setting login credentials (email/password)143 if (type == 'Client')144 ff.radio(:value, "Client").set145 else146 ff.radio(:value,"Publisher").set147 end148 ff.text_field(:id, "txtEmail").set(email)149 ff.text_field(:id, "txtPassword").set(passwd)...

Full Screen

Full Screen

Usamp_lib.rb

Source:Usamp_lib.rb Github

copy

Full Screen

...15 # Parameters returned : IE instance16 17 def Usampadmin_login(email,passwd)18 19# capabilities = Selenium::WebDriver::Remote::Capabilities.firefox #(:javascript_enabled => true, :proxy=> Selenium::WebDriver::Proxy.new(:http => "localhost:5865"))20# ie = Watir::Browser.new(:remote, :url => "http://127.0.0.1:4444/wd/hub", :desired_capabilities => capabilities)21 driver = Selenium::WebDriver.for :firefox, :profile => "Selenium"22 ie = Watir::Browser.new driver23 ie.goto('http://p.usampadmin.com')24 if ie.text.include?('Logout')25 ie.goto("http://p.usampadmin.com/login.php?hdMode=logout")26 end27 # Setting login credentials (email/password)28 ie.text_field(:name,"txtEmail").set email29 ie.text_field(:name,"txtPassword").set passwd30 #Click login button31 ie.button(:value, "Login").click32 # Checkpoint to verify that login was successful33 raise("Sorry! System Failed to login to Usampadmin") unless ie.link(:text,'Logout').exists?34 return ie35 end36 37 38 # Method to login to Surveyhead site39 # Parameters passed : email and password40 # Parameters returned : IE instance41 42 def Surveyhead_login(email,passwd)43 # New IE instance creation44 driver = Selenium::WebDriver.for :firefox, :profile => "Selenium"45 ff = Watir::Browser.new driver46 #ff.maximize47 ff.goto('http://www.p.surveyhead.com')48 # Setting login credentials (email/password)49 #ff.link(:id,"memLogin").click50 ff.text_field(:name, "txtEmail").set(email)51 ff.text_field(:name, "txtPassword").set(passwd)52 ff.button(:value,"Login").click53 sleep 1554 if(ff.link(:id,"sb-nav-close").exists?)55 ff.link(:id,"sb-nav-close").click56 end57 sleep 558 59 if(ff.div(:id=>"loadingSurveys").exists?)60 while ff.div(:id=>"loadingSurveys").visible? do61 sleep 0.562 puts "waiting for surveys to load"63 end64 end65 66 raise("Sorry! System Failed to login to Usampadmin") unless ff.link(:text,'Logout').exists?67 return ff68 end69 70 # Method to login to sm.p.Surveyhead site71 # Parameters passed : email and password72 # Parameters returned : IE instance73 74 def Surveyhead_sm_login(email,passwd)75 76 # New IE instance creation77 driver = Selenium::WebDriver.for :firefox, :profile => "Selenium"78 ff = Watir::Browser.new driver79 #ff.maximize80 # Opening Usampadmin site81 ff.goto('http://www.sm.p.surveyhead.com')82 # Setting login credentials (email/password)83 ff.text_field(:name, "txtEmail").set(email)84 ff.text_field(:name, "txtPassword").set(passwd)85 #Click login button86 ff.button(:value, "Login").click87 sleep 1588 if(ff.link(:id,"sb-nav-close").exists?)89 ff.link(:id,"sb-nav-close").click90 end91 sleep 592 93 if(ff.div(:id=>"loadingSurveys").exists?)94 while ff.div(:id=>"loadingSurveys").visible? do95 sleep 0.596 puts "waiting for surveys to load"97 end98 end99 100 101 # Checkpoint to verify that login was successful102 raise("Sorry! System Failed to login to Usampadmin") unless ff.link(:text,'Logout').exists?103 return ff104 end105 106 107 #Parameters : IE instance108 def Network_site_login(email,passwd,type)109 110 # New Firefox instance creation111 driver = Selenium::WebDriver.for :firefox, :profile => "Selenium"112 ff = Watir::Browser.new driver113 #ff.window.resize_to(800, 600)114 #ff.maximize()115 116 #capabilities = Selenium::WebDriver::Remote::Capabilities.firefox #(:javascript_enabled => true, :proxy=> Selenium::WebDriver::Proxy.new(:http => "localhost:5865"))117 #driver = Selenium::WebDriver::Remote::Capabilities.firefox(:profile => "Selenium")118 #ff = Watir::Browser.new(:remote, :url => "http://127.0.0.1:4444/wd/hub", :desired_capabilities => capabilities)119# ff = Selenium::Client::Driver.new \120# :host => "localhost",121# :port => 4444,122# :browser => "*chrome",123# :timeout_in_second => 60,124# :url => "https://p.network.u-samp.com/"125#126# ff.driver.start_new_browser_session(:captureNetworkTraffic => true)127 #firefox.exe -P Selenium128 #ff = custom C:\Program Files\Mozilla Firefox\firefox.exe -P firefox_browser129 #ff.clear_cookies130 # Opening Usampadmin site131 #capabilities = Selenium::WebDriver::Remote::Capabilities.firefox #(:javascript_enabled => true, :proxy=> Selenium::WebDriver::Proxy.new(:http => "localhost:5865"))132 #ff = Watir::Browser.new(:remote, :url => "http://127.0.0.1:4444/wd/hub", :desired_capabilities => capabilities)133 #ff = Watir::Browser.new(:remote, :url => "http://127.0.0.1:4444/wd/hub", :desired_capabilities => capabilities)134 #ff = Watir::Browser.new(:remote, :desired_capabilities => capabilities)135 #ff = Watir::Browser.start("http://127.0.0.1:4444/wd/hub", :firefox, :remote)136 ff.goto('https://p.network.u-samp.com/login.php')137 #ff.clear_cookies138 # Setting login credentials (email/password)139 if (type == 'Client')140 ff.radio(:value, "Client").set141 else142 ff.radio(:value,"Publisher").set143 end144 ff.text_field(:id, "txtEmail").set(email)145 ff.text_field(:id, "txtPassword").set(passwd)...

Full Screen

Full Screen

driver_configuration.rb

Source:driver_configuration.rb Github

copy

Full Screen

...22 #23 # For example when initialising the driver like this24 #25 # args = [26 # "--proxy-server=localhost:8080",27 # "--proxy-bypass-list=127.0.0.1,192.168.0.1",28 # "--user-agent=Mozilla/5.0 (MSIE 10.0; Windows NT 6.1; Trident/5.0)"29 # ]30 #31 # Capybara::Selenium::Driver.new(32 # app,33 # browser: :chrome,34 # options: Selenium::WebDriver::Firefox::Options.new(args: args)35 # )36 #37 # You can instead call Quke::DriverConfiguration.chrome which will38 # manage instantiating and setting up the39 # Selenium::WebDriver::Chrome::Options instance based on the40 # properties of the Quke::Configuration instance its initialised with41 #42 # Capybara::Selenium::Driver.new(43 # app,44 # browser: :chrome,45 # options: my_driver_config.chrome46 # )47 #48 def chrome49 no_proxy = config.proxy.no_proxy.tr(",", ";")50 options = Selenium::WebDriver::Chrome::Options.new51 options.headless! if config.headless52 options.add_argument("--proxy-server=#{config.proxy.host}:#{config.proxy.port}") if config.proxy.use_proxy?53 options.add_argument("--proxy-bypass-list=#{no_proxy}") unless config.proxy.no_proxy.empty?54 options.add_argument("--user-agent=#{config.user_agent}") unless config.user_agent.empty?55 options56 end57 # Returns an instance of Selenium::WebDriver::Firefox::Options to be58 # used when registering an instance of Capybara::Selenium::Driver,59 # configured to run using Firefox (the default).60 #61 # For example when initialising the driver like this62 #63 # my_profile = Selenium::WebDriver::Firefox::Profile.new64 # my_profile.proxy = Selenium::WebDriver::Proxy.new(65 # http: "10.10.2.70:8080",66 # ssl: "10.10.2.70:8080"67 # )68 # my_profile['general.useragent.override'] = "Mozilla/5.0 (MSIE 10.0; Windows NT 6.1; Trident/5.0)"69 # Capybara::Selenium::Driver.new(70 # app,71 # browser: :firefox,72 # options: Selenium::WebDriver::Firefox::Options.new(profile: my_profile)73 # )74 #75 # You can instead call Quke::DriverConfiguration.firefox which will76 # manage instantiating and setting up the77 # Selenium::WebDriver::Firefox::Options instance based on the78 # properties of the Quke::Configuration instance its initialised with79 #80 # Capybara::Selenium::Driver.new(81 # app,82 # browser: :firefox,83 # options: my_driver_config.firefox84 # )85 #86 def firefox87 options = Selenium::WebDriver::Firefox::Options.new(profile: firefox_profile)88 options.headless! if config.headless89 options90 end91 # Returns an instance of Selenium::WebDriver::Remote::Capabilities to be92 # used when registering an instance of Capybara::Selenium::Driver,93 # configured to run using the Browserstack[https://www.browserstack.com/]94 # service.95 #96 # For example when initialising the driver like this97 #98 # my_capabilites = Selenium::WebDriver::Remote::Capabilities.new99 # my_capabilites['build'] = my_config.browserstack['build']100 # # ... set rest of capabilities101 # Capybara::Selenium::Driver.new(102 # app,103 # browser: :remote,104 # url: 'http://jdoe:123456789ABCDE@hub.browserstack.com/wd/hub',105 # desired_capabilities: my_capabilites106 # )107 #108 # You can instead call Quke::DriverConfiguration.browserstack which will109 # manage instantiating and setting up the110 # Selenium::WebDriver::Remote::Capabilities instance based on the111 # properties of the Quke::Configuration instance its initialised with112 #113 # Capybara::Selenium::Driver.new(114 # app,115 # browser: :remote,116 # url: my_driver_config.browserstack_url,117 # desired_capabilities: my_driver_config.browserstack118 # )119 #120 # For further reference on browserstack capabilities121 # https://www.browserstack.com/automate/capabilities122 # https://www.browserstack.com/automate/ruby#configure-capabilities123 def browserstack124 # Documentation and the code for this class can be found here125 # http://www.rubydoc.info/gems/selenium-webdriver/0.0.28/Selenium/WebDriver/Remote/Capabilities126 # https://github.com/SeleniumHQ/selenium/blob/master/rb/lib/selenium/webdriver/remote/capabilities.rb127 capabilities = Selenium::WebDriver::Remote::Capabilities.new128 config.browserstack.capabilities.each do |key, value|129 capabilities[key] = value130 end131 capabilities132 end133 private134 def firefox_profile135 profile = Selenium::WebDriver::Firefox::Profile.new136 profile["general.useragent.override"] = config.user_agent unless config.user_agent.empty?137 profile.proxy = Selenium::WebDriver::Proxy.new(config.proxy.firefox_settings) if config.proxy.use_proxy?138 profile139 end140 end141end...

Full Screen

Full Screen

create_driver.rb

Source:create_driver.rb Github

copy

Full Screen

...13 :profile => profiles)14 else15 @driver = Selenium::WebDriver.for(:remote, :url => CONFIG.grid_url, :desired_capabilities => RemoteCapabilities.send(CONFIG.browser_cap))16 end17 if proxy_enabled? && !profiles18 @driver = Selenium::WebDriver.for(:remote, :url => CONFIG.grid_url, :desired_capabilities => RemoteCapabilities.send(CONFIG.browser_cap),19 :profile => profiles, :http_client => proxy_url)20 elsif proxy_enabled? && profiles21 @driver = Selenium::WebDriver.for(:remote, :url => CONFIG.grid_url, :desired_capabilities => RemoteCapabilities.send(CONFIG.browser_cap),22 :http_client => proxy_url)23 end24 end25 end26 def profiles27 if CONFIG.enable_profile28 CONFIG.profile29 else30 false31 end32 end33 def default_http34 client = Selenium::WebDriver::Remote::Http::Default.new35 client.timeout=30036 client37 end38 def proxy_url39 client = Selenium::WebDriver::Remote::Http::Default.new40 client.timeout=30041 client.proxy = Selenium::WebDriver::Proxy.new(:http => CONFIG.proxy_based_url)42 end43 def proxy_enabled?44 CONFIG.enable_proxy45 end46 end #CreateDriver47end #AutomationFramework...

Full Screen

Full Screen

webdriver_factory.rb

Source:webdriver_factory.rb Github

copy

Full Screen

...4 module WebdriverFactory5 extend self6 def build_chrome_driver(_options={})7 capabilities = Selenium::WebDriver::Remote::Capabilities.chrome8 capabilities.proxy = build_proxy(_options) if _options[:proxy].present?9 setup_webdriver Selenium::WebDriver.for(:chrome, detach: false, desired_capabilities: capabilities), _options10 end11 def build_firefox_driver(_options={})12 capabilities = Selenium::WebDriver::Remote::Capabilities.firefox13 capabilities.proxy = build_proxy(_options) if _options[:proxy].present?14 setup_webdriver Selenium::WebDriver.for(:firefox, desired_capabilities: capabilities), _options15 end16 def build_remote_driver(_options={})17 client = Selenium::WebDriver::Remote::Http::Default.new18 client.timeout = _options[:remote_timeout]19 client.proxy = build_proxy(_options) if _options[:proxy].present?20 setup_webdriver(Selenium::WebDriver.for(:remote, {21 :url => _options[:remote_host],22 :http_client => client,23 :desired_capabilities => _options[:capabilities] || Selenium::WebDriver::Remote::Capabilities.firefox24 }), _options)25 end26 private27 def build_proxy(_options)28 # TODO: support authentication29 Selenium::WebDriver::Proxy.new({30 :http => _options[:proxy],31 :ssl => _options[:proxy]32 })33 end34 def setup_webdriver(_driver, _options)35 _driver.manage.window.resize_to(_options[:window_width], _options[:window_height]) rescue nil36 return _driver37 end38 end39 end40end...

Full Screen

Full Screen

proxy

Using AI Code Generation

copy

Full Screen

1 def proxy=(proxy)2proxy = Selenium::WebDriver::Proxy.new(http: 'proxy:8080')3profile.proxy = Selenium::WebDriver::Proxy.new(http: 'proxy:8080')4options.add_argument('--proxy-server=proxy:8080')5driver = Selenium::WebDriver.for :chrome, proxy: Selenium::WebDriver::Proxy.new(http: 'proxy:8080')6driver = Selenium::WebDriver.for :chrome, proxy: { http: 'proxy:8080' }

Full Screen

Full Screen

proxy

Using AI Code Generation

copy

Full Screen

1proxy = Selenium::WebDriver::Proxy.new(http: 'proxy.example.com:8080')2http_client = Selenium::WebDriver::Remote::Http::Proxy.new('proxy.example.com:8080')3profile.proxy = Selenium::WebDriver::Proxy.new(http: 'proxy.example.com:8080')4profile.proxy = Selenium::WebDriver::Proxy.new(http: 'proxy.example.com:8080')5profile.proxy = Selenium::WebDriver::Proxy.new(http: 'proxy.example.com:8080')6profile.proxy = Selenium::WebDriver::Proxy.new(http: 'proxy.example.com:8080')7profile.proxy = Selenium::WebDriver::Proxy.new(http: 'proxy

Full Screen

Full Screen

proxy

Using AI Code Generation

copy

Full Screen

1 def request(*args)2 proxy = URI.parse(ENV['http_proxy'])3 http = Net::HTTP::Proxy(proxy.host, proxy.port).new(@server_url.host, @server_url.port)4 h.request(*args)5driver = Selenium::WebDriver.for :firefox, :proxy => Selenium::WebDriver::Proxy.new(:http => ENV['http_proxy'])6driver = Selenium::WebDriver.for :firefox, :http_client => Selenium::WebDriver::Remote::Http::Default.new(:proxy => ENV['http_proxy'])7driver = Selenium::WebDriver.for :firefox, :proxy => Selenium::WebDriver::Proxy.new(:http => ENV['http_proxy'])8driver = Selenium::WebDriver.for :firefox, :http_client => Selenium::WebDriver::Remote::Http::Default.new(:proxy => ENV['http_proxy'])9driver = Selenium::WebDriver.for :firefox, :proxy => Selenium::WebDriver::Proxy.new(:http => ENV['http_proxy'])10driver = Selenium::WebDriver.for :firefox, :http_client => Selenium::WebDriver::Remote::Http::Default.new(:proxy => ENV['http_proxy'])11driver = Selenium::WebDriver.for :firefox, :proxy => Selenium::WebDriver::Proxy.new(:http => ENV['http_proxy'])12driver = Selenium::WebDriver.for :firefox, :http_client => Selenium::WebDriver::Remote::Http::Default.new(:proxy => ENV['http_proxy'])13driver = Selenium::WebDriver.for :firefox, :proxy => Selenium::WebDriver::Proxy.new(:http => ENV['http_proxy'])

Full Screen

Full Screen

proxy

Using AI Code Generation

copy

Full Screen

1 def call(verb, url, command_hash, command_parameters)2 proxy = Net::HTTP::Proxy(@proxy, @port)3 http = proxy.new(url.host, url.port)4 h.request(build_request(verb, url, command_hash, command_parameters))5driver = Selenium::WebDriver.for(:remote, :url => "http://localhost:4444/wd/hub", :desired_capabilities => caps)6driver.get("http://www.google.com")7driver = Selenium::WebDriver.for(:remote, :url => "http://localhost:4444/wd/hub", :desired_capabilities => caps)8driver.get("http://www.google.com")9driver = Selenium::WebDriver.for(:remote, :url => "http://localhost:4444/wd/hub", :desired_capabilities => caps)10driver.get("http://www.google.com")11driver = Selenium::WebDriver.for(:remote, :url => "http://localhost:4444/wd/hub", :desired_capabilities => caps)12driver.get("http://www.google.com")13driver = Selenium::WebDriver.for(:remote, :url => "http://localhost:4444/wd/hub", :desired_capabilities => caps)14driver.get("http://www.google.com")15driver = Selenium::WebDriver.for(:remote, :url => "http://localhost:4444/wd/hub", :desired_capabilities =>

Full Screen

Full Screen

proxy

Using AI Code Generation

copy

Full Screen

1proxy = Selenium::WebDriver::Proxy.new(:http => "proxy.example.com:8080")2driver = Selenium::WebDriver.for(:remote, :desired_capabilities => caps, :http_client => http_client)3driver.get("http://www.google.com")4profile.proxy = Selenium::WebDriver::Proxy.new(:http => "proxy.example.com:8080")5driver.get("http://www.google.com")6options.add_argument('--proxy-server=proxy.example.com:8080')7driver.get("http://www.google.com")8driver = Selenium::WebDriver.for :chrome, :proxy => Selenium::WebDriver::Proxy.new(:http => "proxy.example.com:8080")9driver.get("http://www.google.com")

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Selenium automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful