How to use port method of Selenium.WebDriver.Firefox Package

Best Selenium code snippet using Selenium.WebDriver.Firefox.port

selenium_driver_setup.rb

Source:selenium_driver_setup.rb Github

copy

Full Screen

1module SeleniumDriverSetup2  def setup_selenium3    browser = $selenium_config[:browser].try(:to_sym) || :firefox4    host_and_port5    path = $selenium_config[:paths].try(:[], browser)6    if path7      Selenium::WebDriver.const_get(browser.to_s.capitalize).path = path8    end9    driver = if browser == :firefox10               firefox_driver11             elsif browser == :chrome12               chrome_driver13             elsif browser == :ie14               ie_driver15             end16    driver.manage.timeouts.implicit_wait = 317    driver18  end19  def ie_driver20    require 'testingbot'21    require 'testingbot/tunnel'22    puts "using IE driver"23    caps = Selenium::WebDriver::Remote::Capabilities.ie24    caps.version = "10"25    caps.platform = :WINDOWS26    caps[:unexpectedAlertBehaviour] = 'ignore'27    Selenium::WebDriver.for(28      :remote,29      :url => "http://#{$selenium_config[:testingbot_key]}:" +30                "#{$selenium_config[:testingbot_secret]}@hub.testingbot.com:4444/wd/hub",31      :desired_capabilities => caps)32  end33  def firefox_driver34    puts "using FIREFOX driver"35    profile = firefox_profile36    caps = Selenium::WebDriver::Remote::Capabilities.firefox(:unexpectedAlertBehaviour => 'ignore')37    if $selenium_config[:host_and_port]38      caps.firefox_profile = profile39      stand_alone_server_firefox_driver(caps)40    else41      ruby_firefox_driver(profile: profile, desired_capabilities: caps)42    end43  end44  def chrome_driver45    puts "using CHROME driver"46    if $selenium_config[:host_and_port]47      stand_alone_server_chrome_driver48    else49      ruby_chrome_driver50    end51  end52  def ruby_chrome_driver53    driver = nil54    begin55      tries ||= 356      puts "Thread: provisioning selenium chrome ruby driver"57      driver = Selenium::WebDriver.for :chrome58    rescue StandardError => e59      puts "Thread #{THIS_ENV}\n try ##{tries}\nError attempting to start remote webdriver: #{e}"60      sleep 261      retry unless (tries -= 1).zero?62    end63    driver64  end65  def stand_alone_server_chrome_driver66    driver = nil67    3.times do |times|68      begin69        driver = Selenium::WebDriver.for(70          :remote,71          :url => 'http://' + ($selenium_config[:host_and_port] || "localhost:4444") + '/wd/hub',72          :desired_capabilities => :chrome73        )74        break75      rescue StandardError => e76        puts "Error attempting to start remote webdriver: #{e}"77        raise e if times == 278      end79    end80    driver81  end82  def ruby_firefox_driver(options)83    driver = nil84    begin85      tries ||= 386      puts "Thread: provisioning selenium ruby firefox driver"87      driver = Selenium::WebDriver.for(:firefox, options)88    rescue StandardError => e89      puts "Thread #{THIS_ENV}\n try ##{tries}\nError attempting to start remote webdriver: #{e}"90      sleep 291      retry unless (tries -= 1).zero?92    end93    driver94  end95  def stand_alone_server_firefox_driver(caps)96    driver = nil97    3.times do |times|98      begin99        driver = Selenium::WebDriver.for(100          :remote,101          :url => 'http://' + ($selenium_config[:host_and_port] || "localhost:4444") + '/wd/hub',102          :desired_capabilities => caps103        )104        break105      rescue StandardError => e106        puts "Error attempting to start remote webdriver: #{e}"107        raise e if times == 2108      end109    end110    driver111  end112  def selenium_driver;113    $selenium_driver114  end115  alias_method :driver, :selenium_driver116  def firefox_profile117    profile = Selenium::WebDriver::Firefox::Profile.new118    profile.load_no_focus_lib=(true)119    profile.native_events = true120    if $selenium_config[:firefox_profile].present?121      profile = Selenium::WebDriver::Firefox::Profile.from_name($selenium_config[:firefox_profile])122    end123    profile124  end125  def host_and_port126    if $selenium_config[:host] && $selenium_config[:port] && !$selenium_config[:host_and_port]127      $selenium_config[:host_and_port] = "#{$selenium_config[:host]}:#{$selenium_config[:port]}"128    end129  end130  def set_native_events(setting)131    driver.instance_variable_get(:@bridge).instance_variable_get(:@capabilities).instance_variable_set(:@native_events, setting)132  end133  def app_host134    "http://#{$app_host_and_port}"135  end136  def self.setup_host_and_port137    ENV['CANVAS_CDN_HOST'] = "canvas.instructure.com"138    if $selenium_config[:server_port]139      $server_port = $selenium_config[:server_port]140      $app_host_and_port = "#{SERVER_IP}:#{$server_port}"141      return $server_port142    end143    # find an available socket144    s = Socket.new(:INET, :STREAM)145    s.setsockopt(:SOCKET, :REUSEADDR, true)146    s.bind(Addrinfo.tcp(SERVER_IP, 0))147    $server_port = s.local_address.ip_port148    server_ip = if $selenium_config[:browser] == 'ie'149                  # makes default URL for selenium the external IP of the box for standalone sel servers150                  `curl http://instance-data/latest/meta-data/public-ipv4` # command for aws boxes gets external ip151                else152                  s.local_address.ip_address153                end154    $app_host_and_port = "#{server_ip}:#{s.local_address.ip_port}"155    puts "found available port: #{$app_host_and_port}"156    return $server_port157  ensure158    s.close() if s159  end160  def self.start_webserver(webserver)161    setup_host_and_port162    case webserver163    when 'thin'164      self.start_in_process_thin_server165    when 'webrick'166      self.start_in_process_webrick_server167    else168      puts "no web server specified, defaulting to WEBrick"169      self.start_in_process_webrick_server170    end171  end172  def self.shutdown_webserver(server)173    shutdown = lambda do174      server.shutdown175      HostUrl.default_host = nil176      HostUrl.file_host = nil177    end178    at_exit { shutdown.call }179    return shutdown180  end181  def self.rack_app182    app = Rack::Builder.new do183      use Rails::Rack::Debugger unless Rails.env.test?184      run CanvasRails::Application185    end.to_app186    lambda do |env|187      nope = [503, {}, [""]]188      return nope unless allow_requests?189      # wrap request in a mutex so we can ensure it doesn't span spec190      # boundaries (see clear_requests!)191      result = request_mutex.synchronize { app.call(env) }192      # check if the spec just finished while we ran, and if so prevent193      # side effects like redirects (and thus moar requests)194      if allow_requests?195        result196      else197        # make sure we clean up the body of requests we throw away198        # https://github.com/rack/rack/issues/658#issuecomment-38476120199        result.last.close if result.last.respond_to?(:close)200        nope201      end202    end203  end204  class << self205    def disallow_requests!206      # ensure the current in-flight request (if any, AJAX or otherwise)207      # finishes up its work, and prevent any subsequent requests before the208      # next spec gets underway. otherwise race conditions can cause sadness209      # with our shared conn and transactional fixtures (e.g. special210      # accounts and their caching)211      @allow_requests = false212      request_mutex.synchronize { }213    end214    def allow_requests!215      @allow_requests = true216    end217    def allow_requests?218      @allow_requests219    end220    def request_mutex221      @request_mutex ||= Mutex.new222    end223  end224  def self.start_in_process_thin_server225    require File.expand_path(File.dirname(__FILE__) + '/servers/thin_server')226    server = SpecFriendlyThinServer227    app = self.rack_app228    server.run(app, :BindAddress => BIND_ADDRESS, :Port => $server_port, :AccessLog => [])229    shutdown = self.shutdown_webserver(server)230    return shutdown231  end232  def self.start_in_process_webrick_server233    require File.expand_path(File.dirname(__FILE__) + '/servers/webrick_server')234    server = SpecFriendlyWEBrickServer235    app = self.rack_app236    server.run(app, :BindAddress => BIND_ADDRESS, :Port => $server_port, :AccessLog => [])237    shutdown = self.shutdown_webserver(server)238    return shutdown239  end240end...

Full Screen

Full Screen

firefox.rb

Source:firefox.rb Github

copy

Full Screen

1# frozen_string_literal: true2# Licensed to the Software Freedom Conservancy (SFC) under one3# or more contributor license agreements.  See the NOTICE file4# distributed with this work for additional information5# regarding copyright ownership.  The SFC licenses this file6# to you under the Apache License, Version 2.0 (the7# "License"); you may not use this file except in compliance8# with the License.  You may obtain a copy of the License at9#10#   http://www.apache.org/licenses/LICENSE-2.011#12# Unless required by applicable law or agreed to in writing,13# software distributed under the License is distributed on an14# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY15# KIND, either express or implied.  See the License for the16# specific language governing permissions and limitations17# under the License.18require 'timeout'19require 'socket'20require 'rexml/document'21require 'selenium/webdriver/firefox/driver'22require 'selenium/webdriver/firefox/util'23require 'selenium/webdriver/firefox/extension'24require 'selenium/webdriver/firefox/binary'25require 'selenium/webdriver/firefox/profiles_ini'26require 'selenium/webdriver/firefox/profile'27require 'selenium/webdriver/firefox/launcher'28require 'selenium/webdriver/firefox/legacy/driver'29require 'selenium/webdriver/firefox/marionette/bridge'30require 'selenium/webdriver/firefox/marionette/driver'31require 'selenium/webdriver/firefox/options'32module Selenium33  module WebDriver34    module Firefox35      DEFAULT_PORT = 705536      DEFAULT_ENABLE_NATIVE_EVENTS = Platform.os == :windows37      DEFAULT_SECURE_SSL = false38      DEFAULT_ASSUME_UNTRUSTED_ISSUER = true39      DEFAULT_LOAD_NO_FOCUS_LIB = false40      def self.driver_path=(path)41        WebDriver.logger.deprecate 'Selenium::WebDriver::Firefox#driver_path=',42                                   'Selenium::WebDriver::Firefox::Service#driver_path='43        Selenium::WebDriver::Firefox::Service.driver_path = path44      end45      def self.driver_path46        WebDriver.logger.deprecate 'Selenium::WebDriver::Firefox#driver_path',47                                   'Selenium::WebDriver::Firefox::Service#driver_path'48        Selenium::WebDriver::Firefox::Service.driver_path49      end50      def self.path=(path)51        Binary.path = path52      end53    end # Firefox54  end # WebDriver55end # Selenium56require 'selenium/webdriver/firefox/service'...

Full Screen

Full Screen

port

Using AI Code Generation

copy

Full Screen

1element = driver.find_element(:name, 'q')2element = driver.find_element(:name, 'q')3element = driver.find_element(:name, 'q')4element = driver.find_element(:name, 'q')5element = driver.find_element(:name, 'q')

Full Screen

Full Screen

port

Using AI Code Generation

copy

Full Screen

1binary.add_firefox_option('-http-proxy', 'localhost:8080')2proxy = Selenium::WebDriver::Proxy.new(:http => 'localhost:8080')3caps = Selenium::WebDriver::Remote::Capabilities.firefox(:proxy => {:http => 'localhost:8080'})4driver = Selenium::WebDriver.for(:firefox, :desired_capabilities => caps)

Full Screen

Full Screen

port

Using AI Code Generation

copy

Full Screen

1driver.find_element(:name, "q").send_keys "Selenium"2driver.find_element(:name, "btnG").click3driver.find_element(:name, "q").send_keys "Selenium"4driver.find_element(:name, "btnG").click5driver.find_element(:id, "email").send_keys "test"6driver.find_element(:id, "pass").send_keys "test"7driver.find_element(:id, "loginbutton").click8options.add_argument('--headless')9driver.find_element(:name, "q").send_keys "Selenium"10driver.find_element(:name, "btnG").click11driver.find_element(:name, "q").send_keys "

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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful