How to use screenshot method of Selenium.WebDriver.Remote Package

Best Selenium code snippet using Selenium.WebDriver.Remote.screenshot

web_driver.rb

Source:web_driver.rb Github

copy

Full Screen

1# Description: Webdriver class for handling the Grid / Local execution2# Created by LZD643 on 3/19/2015.3# Bugs:4# 1. Unable to pick executable from different location - FIXED5# 2. Need to add handle for executable browser location. - FIXED6#7# License: Usage of custom framework is restricted to limited audience.8require 'active_model'9require 'watir-webdriver'10require 'selenium-webdriver'11require 'webdriver-user-agent'12require_relative 'sauce_driver'13require_relative 'automation_environment'1415class WebDriver16 include ActiveModel::Validations1718 attr_accessor :driver_object, :user_agent,:browser_switches1920 validate :validate_driver2122 # create the Webdriver object23 def initialize(options={})2425 web_driver_properties = {26 :driver_object => nil,27 :user_agent => nil,28 :browser_switches =>%w[--disable-extensions]29 }.merge(options)3031 self.driver_object = web_driver_properties[:driver_object]32 self.user_agent = web_driver_properties[:user_agent]33 self.browser_switches =web_driver_properties[:browser_switches]34 end3536 # create the driver object based on the browser37 def get_webdriver_object(automation_env_obj)38 if automation_env_obj.execution_type =='remote'39 get_remote_webdriver_object(automation_env_obj)40 else41 get_local_webdriver_object(automation_env_obj)42 end43 # Check whether object has been created or not.44 if valid?45 puts ('===========================================================')46 puts ("Browser : #{automation_env_obj.browser_name} \n" )47 puts ("Implicit wait : #{automation_env_obj.implicit_wait} \n" )48 if automation_env_obj.browser_version.present?49 puts ("Browser Version : #{automation_env_obj.browser_version} \n" )50 end51 puts ("Execution Env: #{automation_env_obj.execution_type} \n" )52 puts ('===========================================================')53 self.driver_object.manage.window.maximize54 self.driver_object.switch_to.default_content55 return self.driver_object56 end57 end58 private59 #Getting the browser object for remote execution60 def get_remote_webdriver_object(automation_env_obj)61 caps = ''62 case automation_env_obj.browser_name.downcase63 when 'chrome'64 caps = Selenium::WebDriver::Remote::Capabilities.chrome65 caps[:trustAllSSLCertificates] = true66 caps['browserName'] = automation_env_obj.browser_name67 if automation_env_obj.browser_version.present?68 caps.version = automation_env_obj.browser_version69 end70 if automation_env_obj.platform.present?71 caps.platform = automation_env_obj.platform72 end7374 caps['takesScreenshot'] = true75 when 'firefox'76 caps = Selenium::WebDriver::Remote::Capabilities.firefox77 caps[:trustAllSSLCertificates] = true78 caps['browserName'] = automation_env_obj.browser_name79 if automation_env_obj.browser_version.present?80 caps.version = automation_env_obj.browser_version81 end82 if automation_env_obj.platform.present?83 caps.platform = automation_env_obj.platform84 end85 caps['takesScreenshot'] = true86 when 'ie'||'internet explorer'||'iexplore'87 caps = Selenium::WebDriver::Remote::Capabilities.internet_explorer88 caps[:trustAllSSLCertificates] = true89 caps['browserName'] = automation_env_obj.browser_name90 if automation_env_obj.browser_version.present?91 caps.version = automation_env_obj.browser_version92 end93 if automation_env_obj.platform.present?94 caps.platform = automation_env_obj.platform95 end96 caps['takesScreenshot'] = true97 when 'android'98 caps = Selenium::WebDriver::Remote::Capabilities.android99 caps[:trustAllSSLCertificates] = true100 caps['browserName'] = automation_env_obj.browser_name101 if automation_env_obj.browser_version.present?102 caps.version = automation_env_obj.browser_version103 end104 if automation_env_obj.platform.present?105 caps.platform = automation_env_obj.platform106 end107 caps['takesScreenshot'] = true108 when 'iphone'109 caps = Selenium::WebDriver::Remote::Capabilities.iphone110 caps[:trustAllSSLCertificates] = true111 caps['browserName'] = automation_env_obj.browser_name112 if automation_env_obj.browser_version.present?113 caps.version = automation_env_obj.browser_version114 end115 if automation_env_obj.platform.present?116 caps.platform = automation_env_obj.platform117 end118 caps['takesScreenshot'] = true119 when 'headless'120 caps = Selenium::WebDriver::Remote::Capabilities.htmlunitwithjs121 caps[:trustAllSSLCertificates] = true122 caps['browserName'] = automation_env_obj.browser_name123 if automation_env_obj.browser_version.present?124 caps.version = automation_env_obj.browser_version125 end126 if automation_env_obj.platform.present?127 caps.platform = automation_env_obj.platform128 end129 caps['takesScreenshot'] = true130 when 'ipad'131 caps = Selenium::WebDriver::Remote::Capabilities.ipad132 caps[:trustAllSSLCertificates] = true133 caps['browserName'] = automation_env_obj.browser_name134 if automation_env_obj.browser_version.present?135 caps.version = automation_env_obj.browser_version136 end137 if automation_env_obj.platform.present?138 caps.platform = automation_env_obj.platform139 end140 caps['takesScreenshot'] = true141 else142 puts ('i am here')143 errors.add(:driver_object,'is invalid. Please check browser name & version')144 end145 self.driver_object = Selenium::WebDriver.for(:remote, :url => automation_env_obj.grid_url,146 :desired_capabilities => caps)147 end148 # getting the browser object for local execution149 def get_local_webdriver_object(automation_env_obj)150 case automation_env_obj.browser_name151 when 'chrome'152 self.driver_object = Selenium::WebDriver.for :chrome153 when 'firefox'154 self.driver_object = Selenium::WebDriver.for :firefox155 when 'ie'156 self.driver_object = Selenium::WebDriver.for :internet_explorer157 when 'android'158 self.driver_object = Selenium::WebDriver.for :android159 when 'iphone'160 self.driver_object = Selenium::WebDriver.for :iphone161 when 'ipad'162 self.driver_object = Selenium::WebDriver.for :ipad163 when 'headless'164 self.driver_object = Selenium::WebDriver.for :htmlunitwithjs165 else166 errors.add(:driver_object,'cannot intialize because of unknown browser.')167 end168 end169170 # after creation, this will validate whether the browser has been created or not.171 def validate_driver172 if driver_object.present? && driver_object ==nil173 errors.add(:driver_object,'is Nil. Please check the browser, version, Connection properties..')174 end175 end176177end ...

Full Screen

Full Screen

automation_context.rb

Source:automation_context.rb Github

copy

Full Screen

2require 'capybara/cucumber'3require 'webdrivers'4require 'selenium-webdriver'5require 'yaml'6require 'capybara-screenshot'7require 'rspec'8require 'capybara/dsl'9require 'rspec/core'10require 'rspec/expectations'11require 'logger'12require 'capybara-screenshot/cucumber'13module AutomationContext14 class << self15 attr_accessor :app_host, :local_run16 def startup(config_file)17 unless File.exist?(config_file)18 raise "Could not locate automation config file: #{config_file}"19 end20 test_config = YAML::load_file(config_file)21 case test_config['selenium']['browser']22 when 'chrome'23 self.bootstrap_chrome24 when 'firefox'25 self.bootstrap_ff26 when 'ie'27 self.bootstrap_ie28 when 'chrome-headless'29 self.bootstrap_chrome_headless30 when 'firefox-headless'31 self.bootstrap_ff_headless32 else33 -134 end35 Capybara.configure do |run_config|36 run_config.run_server = false37 run_config.default_driver = :remote_browser38 run_config.javascript_driver = :remote_browser39 run_config.app_host = test_config['test']['app_host']40 run_config.default_max_wait_time = 541 run_config.save_path = './FailedSnapshots'42 printf "Testing against app host: %s\n", run_config.app_host43 end44 end45 Capybara::Screenshot.autosave_on_failure = true46 Capybara::Screenshot.register_driver(:remote_browser) do |driver, path|47 driver.browser.save_screenshot(path)48 end49 def bootstrap_chrome50 Capybara.register_driver :remote_browser do |app|51 Capybara::Selenium::Driver.new(app, :browser => :chrome)52 end53 Capybara.default_driver = :remote_browser54 end55 def bootstrap_chrome_headless56 Capybara.register_driver :remote_browser do |app|57 options = Selenium::WebDriver::Chrome::Options.new(args: %w[--headless])58 Capybara::Selenium::Driver.new(app, browser: :chrome, options: options)59 end60 Capybara.default_driver = :remote_browser61 end...

Full Screen

Full Screen

env.rb

Source:env.rb Github

copy

Full Screen

...9require 'simplecov'10require 'rest-client'11require 'rubyXL'12require 'parallel'13require 'capybara-screenshot/cucumber'14Capybara::Screenshot.autosave_on_failure = true15Capybara.save_path = "screenshot"16Capybara::Screenshot.prune_strategy = :keep_last_run17SimpleCov.start18# set driver paths19geckodriver_cmd = "which geckodriver"20chromedriver_cmd = "which chromedriver"21edgedriver_cmd = "which msedgedriver"22browser_width, browser_height = 1920, 108023browser = ENV['CUCUMBER_BROWSER'] || 'headless'24browser_size = ENV['BROWSER_SIZE']25remote_server = ENV['SELENIUM_REMOTE_URL']26# Browser Size Input Example: "1920,1080"27if browser_size28 browser_width, browser_height = browser_size.split(",").map {|s| s.strip.to_i}29end...

Full Screen

Full Screen

capybara.rb

Source:capybara.rb Github

copy

Full Screen

1require 'capybara/rspec'2require 'capybara-screenshot'3require 'capybara-screenshot/rspec'4require 'rack_session_access/capybara'5RSpec.configure do6 Capybara.default_max_wait_time = 47 Capybara.javascript_driver = :selenium8end9##10# Configure capybara-screenshot11# Remove old images automatically12Capybara::Screenshot.prune_strategy = :keep_last_run13# Set up S3 uploads if desired14if ENV['OPENPROJECT_ENABLE_CAPYBARA_SCREENSHOT_S3_UPLOADS'] && ENV['AWS_ACCESS_KEY_ID']15 Capybara::Screenshot.s3_configuration = {16 s3_client_credentials: {17 access_key_id: ENV.fetch('AWS_ACCESS_KEY_ID'),18 secret_access_key: ENV.fetch('AWS_ACCESS_KEY_SECRET'),19 region: ENV.fetch('AWS_REGION', 'eu-west-1')20 },21 bucket_name: ENV.fetch('S3_BUCKET_NAME', 'openproject-travis-logs')22 }23end24Rails.application.config do...

Full Screen

Full Screen

spec_helper.rb

Source:spec_helper.rb Github

copy

Full Screen

2require "capybara/rspec"3require "sauce"4require "sauce/capybara"5require "selenium-webdriver"6require "capybara-screenshot/rspec"7if ENV["RUN_ON_SAUCE"]8 Capybara.default_driver = :sauce9else10 Capybara.default_driver = :selenium11 Capybara.run_server = false12end13Sauce.config do |config|14 config[:start_local_application] = false15 config[:start_tunnel] = ENV["RUN_ON_SAUCE"]16 config[:sauce_connect_4_executable] = ENV["SAUCE_CONNECT_4_EXECUTABLE"]17 options = { :screenResolution => "1280x1024" }18 config[:browsers] = [19 ["OS X 10.10", "Safari", "8.0", options],20 ["Windows 7", "Firefox", "40", options],21 ["Windows 8.1", "Internet Explorer", "11", options],22 ["Windows 8", "Chrome", nil, options]23 ]24end25Capybara.register_driver :selenium do |app|26 if ENV["HEADLESS"]27 require "headless"28 headless = Headless.new29 headless.start30 end31 ENV["BROWSER"] ||= "firefox"32 case ENV["BROWSER"]33 when "firefox"34 capabilities = Selenium::WebDriver::Remote::Capabilities.firefox35 when "safari"36 capabilities = Selenium::WebDriver::Remote::Capabilities.safari37 when "ie"38 capabilities = Selenium::WebDriver::Remote::Capabilities.ie39 else40 capabilities = Selenium::WebDriver::Remote::Capabilities.chrome41 end42 options = { :browser => ENV["BROWSER"].to_sym }43 unless ENV["REMOTE_URL"].nil?44 options = { :browser => :remote, :url => ENV["REMOTE_URL"], :desired_capabilities => capabilities }45 end46 Capybara::Selenium::Driver.new(app, options)47end48Capybara.save_and_open_page_path = "tmp/capybara"49Capybara::Screenshot.append_timestamp = false50Capybara::Screenshot.register_filename_prefix_formatter(:rspec) do |example|51 "screenshot_#{example.description.gsub(' ', '-').gsub(/^.*\/spec\//,'')}"52end53Capybara::Screenshot.prune_strategy = { keep: 20 }54Capybara::Screenshot::RSpec.add_link_to_screenshot_for_failed_examples = false...

Full Screen

Full Screen

global_galaxy_s5.rb

Source:global_galaxy_s5.rb Github

copy

Full Screen

...31#driver.scroll.to [0, 300]32#driver.goto loc133puts "You have15 seconds to turn the device"34sleep 1535driver.save_screenshot "./#{Time.now.strftime("GalaxyS5_screen_%d_%m_%Y__%H_%M_%S")}.png"36puts "You have 5 seconds to turn the device"37sleep 538driver.save_screenshot "./#{Time.now.strftime("GalaxyS5_screen_%d_%m_%Y__%H_%M_%S")}.png"39puts "You have 5 seconds to turn the device"40sleep 541driver.save_screenshot "./#{Time.now.strftime("GalaxyS5_screen_%d_%m_%Y__%H_%M_%S")}.png"42puts "You have 5 seconds to turn the device"43sleep 544driver.save_screenshot "./#{Time.now.strftime("GalaxyS5_screen_%d_%m_%Y__%H_%M_%S")}.png"45puts "You have 5 seconds to turn the device"46sleep 547driver.save_screenshot "./#{Time.now.strftime("GalaxyS5_screen_%d_%m_%Y__%H_%M_%S")}.png"48#driver.scroll.to [100, 0]49 50sleep 151end...

Full Screen

Full Screen

android_galaxy_s3_cart.rb

Source:android_galaxy_s3_cart.rb Github

copy

Full Screen

...29#driver.scroll.to [0, 300]30#driver.goto loc131puts "8 to expand" 32sleep 833driver.save_screenshot "./#{Time.now.strftime("GalaxyS4_screen_%d_%m_%Y__%H_%M_%S")}.png"34puts "8 to expand" 35sleep 836driver.save_screenshot "./#{Time.now.strftime("GalaxyS4_screen_%d_%m_%Y__%H_%M_%S")}.png"37puts "8 to expand" 38sleep 839driver.save_screenshot "./#{Time.now.strftime("GalaxyS4_screen_%d_%m_%Y__%H_%M_%S")}.png"40puts "8 to expand" 41sleep 842driver.save_screenshot "./#{Time.now.strftime("GalaxyS4_screen_%d_%m_%Y__%H_%M_%S")}.png"43#driver.scroll.to [100, 0]44 45sleep 146end...

Full Screen

Full Screen

galaxyS3_search_cart_oralb.rb

Source:galaxyS3_search_cart_oralb.rb Github

copy

Full Screen

...14 :desired_capabilities => caps) 15driver.get "http://int.oralb.pgsitecore.com/en-us/search-page?term=Satin%20tape"16puts "sleep 6"17sleep 618driver.save_screenshot "GalaxyS3/#{Time.now.strftime("%d_%m_%Y__%H_%M_%S")}.png"19puts "sleep 6"20sleep 621driver.save_screenshot "GalaxyS3/#{Time.now.strftime("%d_%m_%Y__%H_%M_%S")}.png"22puts "sleep 6"23sleep 624driver.save_screenshot "GalaxyS3/#{Time.now.strftime("%d_%m_%Y__%H_%M_%S")}.png"...

Full Screen

Full Screen

screenshot

Using AI Code Generation

copy

Full Screen

1driver.save_screenshot('google.png')2driver.save_screenshot('google.png')3driver.save_screenshot('google.png')4driver.save_screenshot('google.png')5driver.save_screenshot('google.png')6driver.save_screenshot('google.png')

Full Screen

Full Screen

screenshot

Using AI Code Generation

copy

Full Screen

1element = driver.find_element(:name, 'q')2element.screenshot_as(:png)3element = driver.find_element(:name, 'q')4element.screenshot_as(:png)5element = driver.find_element(:name, 'q')6element.screenshot_as(:png)7element = driver.find_element(:name, 'q')8element.screenshot_as(:png)9element = driver.find_element(:name, 'q')10element.screenshot_as(:png)

Full Screen

Full Screen

screenshot

Using AI Code Generation

copy

Full Screen

1driver.save_screenshot("google.png")2driver.save_screenshot("google.png")3driver.save_screenshot("google.png")4driver.save_screenshot("google.png")

Full Screen

Full Screen

screenshot

Using AI Code Generation

copy

Full Screen

1options.add_argument('--headless')2options.add_argument('--headless')3options.add_argument('--headless')4options.add_argument('--headless')

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.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful