Best Selenium code snippet using Selenium.WebDriver.Firefox.profile
IM_Suite.rb
Source:IM_Suite.rb
...35myfile.print "<h1><u>Test Automation Report</u></h1><br /><center><table border=2 width=\"900px\">";36myfile.close;37=begin38#$ff = FireWatir::Firefox.new39driver = Selenium::WebDriver.for :firefox #, :profile => "Selenium"40$ff = Watir::Browser.new driver41sleep 242$ff.close43system ("ruby Test_01_Project_QG_Create.rb")44driver = Selenium::WebDriver.for :firefox #, :profile => "Selenium"45$ff = Watir::Browser.new driver46sleep 247$ff.close48system ("ruby Test_02_Auto_Open_QG.rb")49#$ff = FireWatir::Firefox.new50driver = Selenium::WebDriver.for :firefox #, :profile => "Selenium"51$ff = Watir::Browser.new driver52sleep 253$ff.close54system ("ruby Test_03_Auto_Close_QG.rb")55#$ff = FireWatir::Firefox.new56driver = Selenium::WebDriver.for :firefox #, :profile => "Selenium"57$ff = Watir::Browser.new driver58sleep 259$ff.close60system ("ruby Test_04_Non_member_survey_complete.rb")61#$ff = FireWatir::Firefox.new62driver = Selenium::WebDriver.for :firefox #, :profile => "Selenium"63$ff = Watir::Browser.new driver64sleep 265$ff.close66system ("ruby Test_05_Member_registration.rb")67#$ff = FireWatir::Firefox.new68driver = Selenium::WebDriver.for :firefox #, :profile => "Selenium"69$ff = Watir::Browser.new driver70sleep 271$ff.close72#system ("ruby Test_06_Survey_complete.rb")73#$ff = FireWatir::Firefox.new74driver = Selenium::WebDriver.for :firefox #, :profile => "Selenium"75$ff = Watir::Browser.new driver76sleep 277$ff.close78system ("ruby Test_07_Publisher_category_filer.rb")79#$ff = FireWatir::Firefox.new80driver = Selenium::WebDriver.for :firefox #, :profile => "Selenium"81$ff = Watir::Browser.new driver82sleep 283$ff.close84system ("ruby Test_08_Publisher_margin_%.rb")85#$ff = FireWatir::Firefox.new86driver = Selenium::WebDriver.for :firefox #, :profile => "Selenium"87$ff = Watir::Browser.new driver88sleep 289$ff.close90system ("ruby Test_09_US_getcount.rb")91#$ff = FireWatir::Firefox.new92driver = Selenium::WebDriver.for :firefox #, :profile => "Selenium"93$ff = Watir::Browser.new driver94sleep 295$ff.close96system ("ruby Test_10_CAN_getcount.rb")97#$ff = FireWatir::Firefox.new98driver = Selenium::WebDriver.for :firefox #, :profile => "Selenium"99$ff = Watir::Browser.new driver100sleep 2101$ff.close102system ("ruby Test_11_CP_Project.rb")103#$ff = FireWatir::Firefox.new104driver = Selenium::WebDriver.for :firefox #, :profile => "Selenium"105$ff = Watir::Browser.new driver106sleep 2107$ff.close108system ("ruby Test_12_CP_rule_processing.rb")109#$ff = FireWatir::Firefox.new110#sleep 2111#sleep 2112#$ff.close113system ("ruby Test_13_Curl_pixel.rb")114#$ff = FireWatir::Firefox.new115driver = Selenium::WebDriver.for :firefox #, :profile => "Selenium"116$ff = Watir::Browser.new driver117sleep 2118$ff.close119system ("ruby Test_14_Traditional_pixel.rb")120#$ff = FireWatir::Firefox.new121driver = Selenium::WebDriver.for :firefox #, :profile => "Selenium"122$ff = Watir::Browser.new driver123sleep 2124$ff.close125#system ("ruby Test_15_Profile_creation.rb")126driver = Selenium::WebDriver.for :firefox #, :profile => "Selenium"127$ff = Watir::Browser.new driver128#$ff = FireWatir::Firefox.new129sleep 2130$ff.close131system ("ruby Test_16_Reward_creation.rb")132#$ff = FireWatir::Firefox.new133driver = Selenium::WebDriver.for :firefox #, :profile => "Selenium"134$ff = Watir::Browser.new driver135sleep 2136$ff.close137system ("ruby Test_17_Member_data_review.rb")138#$ff = FireWatir::Firefox.new139driver = Selenium::WebDriver.for :firefox #, :profile => "Selenium"140$ff = Watir::Browser.new driver141sleep 2142$ff.close143system ("ruby Test_18_Publisher_bids.rb")144#$ff = FireWatir::Firefox.new145driver = Selenium::WebDriver.for :firefox #, :profile => "Selenium"146$ff = Watir::Browser.new driver147sleep 2148$ff.close149system ("ruby Test_19_Virtual_currency_reflection.rb")150#$ff = FireWatir::Firefox.new151driver = Selenium::WebDriver.for :firefox #, :profile => "Selenium"152$ff = Watir::Browser.new driver153sleep 2154$ff.close155system ("ruby Test_20_Custom_reward.rb")156#$ff = FireWatir::Firefox.new157driver = Selenium::WebDriver.for :firefox #, :profile => "Selenium"158$ff = Watir::Browser.new driver159sleep 2160$ff.close161system ("ruby Test_21_Registration_management.rb")162#$ff = FireWatir::Firefox.new163driver = Selenium::WebDriver.for :firefox #, :profile => "Selenium"164$ff = Watir::Browser.new driver165sleep 2166$ff.close167system ("ruby Test_22_Profile_redirection_on_signup.rb")168#$ff = FireWatir::Firefox.new169driver = Selenium::WebDriver.for :firefox #, :profile => "Selenium"170$ff = Watir::Browser.new driver171sleep 2172$ff.close173system ("ruby Test_23_Request_cash_out.rb")174#$ff = FireWatir::Firefox.new175driver = Selenium::WebDriver.for :firefox #, :profile => "Selenium"176$ff = Watir::Browser.new driver177sleep 2178$ff.close179system ("ruby Test_24_Survey_redirection.rb")180#$ff = FireWatir::Firefox.new181driver = Selenium::WebDriver.for :firefox #, :profile => "Selenium"182$ff = Watir::Browser.new driver183sleep 2184$ff.close185#system ("ruby Test_25_Profile_answering.rb")186#$ff = FireWatir::Firefox.new187driver = Selenium::WebDriver.for :firefox #, :profile => "Selenium"188$ff = Watir::Browser.new driver189sleep 2190$ff.close191=begin192system ("ruby Test_26_Site_rendering.rb")193#$ff = FireWatir::Firefox.new194driver = Selenium::WebDriver.for :firefox #, :profile => "Selenium"195$ff = Watir::Browser.new driver196sleep 2197$ff.close198=end199=begin200system ("ruby Test_27_Dashboard_on_off.rb")201#$ff = FireWatir::Firefox.new202driver = Selenium::WebDriver.for :firefox #, :profile => "Selenium"203$ff = Watir::Browser.new driver204sleep 2205$ff.close206system ("ruby Test_28_Disable_pub_account.rb")207#$ff = FireWatir::Firefox.new208driver = Selenium::WebDriver.for :firefox #, :profile => "Selenium"209$ff = Watir::Browser.new driver210sleep 2211$ff.close212system ("ruby Test_29_Enable_disable_queue2.rb")213#$ff = FireWatir::Firefox.new214driver = Selenium::WebDriver.for :firefox #, :profile => "Selenium"215$ff = Watir::Browser.new driver216sleep 2217$ff.close218system ("ruby Test_30_External_prescreener.rb")219#$ff = FireWatir::Firefox.new220driver = Selenium::WebDriver.for :firefox #, :profile => "Selenium"221$ff = Watir::Browser.new driver222sleep 2223$ff.close224system ("ruby Test_31_Merge_field_survey_url.rb")225#$ff = FireWatir::Firefox.new226driver = Selenium::WebDriver.for :firefox #, :profile => "Selenium"227$ff = Watir::Browser.new driver228sleep 2229$ff.close230#system ("ruby Test_32_Panel_book_search.rb")231#$ff = FireWatir::Firefox.new232#sleep 2233#$ff.close234system ("ruby Test_33_Custom_homepage_render.rb")235#$ff = FireWatir::Firefox.new236driver = Selenium::WebDriver.for :firefox #, :profile => "Selenium"237$ff = Watir::Browser.new driver238sleep 2239$ff.close240system ("ruby Test_34_Add_publisher.rb")241#$ff = FireWatir::Firefox.new242driver = Selenium::WebDriver.for :firefox #, :profile => "Selenium"243$ff = Watir::Browser.new driver244sleep 2245$ff.close246#system ("ruby Test_35_SH_email_update.rb")247#$ff = FireWatir::Firefox.new248#sleep 2249#$ff.close250system ("ruby Test_36_Project_search.rb")251#$ff = FireWatir::Firefox.new252driver = Selenium::WebDriver.for :firefox #, :profile => "Selenium"253$ff = Watir::Browser.new driver254sleep 2255$ff.close256system ("ruby Test_37_Add_publisher_group.rb")257#$ff = FireWatir::Firefox.new258driver = Selenium::WebDriver.for :firefox #, :profile => "Selenium"259$ff = Watir::Browser.new driver260sleep 2261$ff.close262system ("ruby Test_38_Add_employee.rb")263#$ff = FireWatir::Firefox.new264driver = Selenium::WebDriver.for :firefox #, :profile => "Selenium"265$ff = Watir::Browser.new driver266sleep 2267$ff.close268system ("ruby Test_39_Add_client.rb")269#$ff = FireWatir::Firefox.new270driver = Selenium::WebDriver.for :firefox #, :profile => "Selenium"271$ff = Watir::Browser.new driver272sleep 2273$ff.close274system ("ruby Test_40_Simulate_completes.rb")275#$ff = FireWatir::Firefox.new276driver = Selenium::WebDriver.for :firefox #, :profile => "Selenium"277$ff = Watir::Browser.new driver278sleep 2279$ff.close280system ("ruby Test_41_Member_search.rb")281#$ff = FireWatir::Firefox.new282driver = Selenium::WebDriver.for :firefox #, :profile => "Selenium"283$ff = Watir::Browser.new driver284sleep 2285$ff.close286system ("ruby Test_42_QG_notifications.rb")287#$ff = FireWatir::Firefox.new288driver = Selenium::WebDriver.for :firefox #, :profile => "Selenium"289$ff = Watir::Browser.new driver290sleep 2291$ff.close292system ("ruby Test_43_Add_tools.rb")293#$ff = FireWatir::Firefox.new294driver = Selenium::WebDriver.for :firefox #, :profile => "Selenium"295$ff = Watir::Browser.new driver296sleep 2297$ff.close298system ("ruby Test_44_Pub_client_association.rb")299#$ff = FireWatir::Firefox.new300driver = Selenium::WebDriver.for :firefox #, :profile => "Selenium"301$ff = Watir::Browser.new driver302sleep 2303$ff.close304system ("ruby Test_45_Email_link_pub.rb")305#$ff = FireWatir::Firefox.new306driver = Selenium::WebDriver.for :firefox #, :profile => "Selenium"307$ff = Watir::Browser.new driver308sleep 2309$ff.close310system ("ruby Test_46_Donot_include_member_last_hour.rb")311#$ff = FireWatir::Firefox.new312driver = Selenium::WebDriver.for :firefox #, :profile => "Selenium"313$ff = Watir::Browser.new driver314sleep 2315$ff.close316system ("ruby Test_47_QG_Publisher_redirect.rb")317#$ff = FireWatir::Firefox.new318driver = Selenium::WebDriver.for :firefox #, :profile => "Selenium"319$ff = Watir::Browser.new driver320sleep 2321$ff.close322#system ("ruby Test_48_Profile_linked_survey.rb")323#$ff = FireWatir::Firefox.new324driver = Selenium::WebDriver.for :firefox #, :profile => "Selenium"325$ff = Watir::Browser.new driver326sleep 2327$ff.close328system ("ruby Test_49_Supplier_add_show_hide.rb")329#$ff = FireWatir::Firefox.new330driver = Selenium::WebDriver.for :firefox #, :profile => "Selenium"331$ff = Watir::Browser.new driver332sleep 2333$ff.close334system ("ruby Test_50_Add_prescreener.rb")335#$ff = FireWatir::Firefox.new336driver = Selenium::WebDriver.for :firefox #, :profile => "Selenium"337$ff = Watir::Browser.new driver338sleep 2339$ff.close340system ("ruby Test_51_Setup_live_closed_QG.rb")341#$ff = FireWatir::Firefox.new342driver = Selenium::WebDriver.for :firefox #, :profile => "Selenium"343$ff = Watir::Browser.new driver344sleep 2345$ff.close346#system ("ruby Test_52_Profile_criteria_cases.rb")347#$ff = FireWatir::Firefox.new348driver = Selenium::WebDriver.for :firefox #, :profile => "Selenium"349$ff = Watir::Browser.new driver350sleep 2351$ff.close352system ("ruby Test_53_List_projects.rb")353#$ff = FireWatir::Firefox.new354driver = Selenium::WebDriver.for :firefox #, :profile => "Selenium"355$ff = Watir::Browser.new driver356sleep 2357$ff.close358system ("ruby Test_54_EX_ST_Links.rb")359#$ff = FireWatir::Firefox.new360driver = Selenium::WebDriver.for :firefox #, :profile => "Selenium"361$ff = Watir::Browser.new driver362sleep 2363$ff.close364system ("ruby Test_55_Member_ID_report.rb")365#$ff = FireWatir::Firefox.new366driver = Selenium::WebDriver.for :firefox #, :profile => "Selenium"367$ff = Watir::Browser.new driver368sleep 2369$ff.close370#system ("ruby Test_56_Profile_mapping_on_corp.rb")371#$ff = FireWatir::Firefox.new372#sleep 2373#$ff.close374system ("ruby Test_57_Success_fail_oq_rewards.rb")375#$ff = FireWatir::Firefox.new376driver = Selenium::WebDriver.for :firefox #, :profile => "Selenium"377$ff = Watir::Browser.new driver378sleep 2379$ff.close380system ("ruby Test_58_Confirmit_code_url.rb")381#$ff = FireWatir::Firefox.new382driver = Selenium::WebDriver.for :firefox #, :profile => "Selenium"383$ff = Watir::Browser.new driver384sleep 2385$ff.close386system ("ruby Test_59_Confirmit_code_url_recontact.rb")387#$ff = FireWatir::Firefox.new388driver = Selenium::WebDriver.for :firefox #, :profile => "Selenium"389$ff = Watir::Browser.new driver390sleep 2391$ff.close392system ("ruby Test_60_Survey_complete_invalid_token.rb")393#$ff = FireWatir::Firefox.new394driver = Selenium::WebDriver.for :firefox #, :profile => "Selenium"395$ff = Watir::Browser.new driver396sleep 2397$ff.close398system ("ruby Test_61_Rewards_at_site_level.rb")399#$ff = FireWatir::Firefox.new400driver = Selenium::WebDriver.for :firefox #, :profile => "Selenium"401$ff = Watir::Browser.new driver402sleep 2403$ff.close404system ("ruby Test_62_Reward_config_foriegn_lang.rb")405#$ff = FireWatir::Firefox.new406driver = Selenium::WebDriver.for :firefox #, :profile => "Selenium"407$ff = Watir::Browser.new driver408sleep 2409$ff.close410system ("ruby Test_63_Broadcasts.rb")411#$ff = FireWatir::Firefox.new412driver = Selenium::WebDriver.for :firefox #, :profile => "Selenium"413$ff = Watir::Browser.new driver414sleep 2415$ff.close416system ("ruby Test_64_Email_clicks_allowed.rb")417#$ff = FireWatir::Firefox.new418driver = Selenium::WebDriver.for :firefox #, :profile => "Selenium"419$ff = Watir::Browser.new driver420sleep 2421$ff.close422system ("ruby Test_65_Project_QG_Create.rb")423#$ff = FireWatir::Firefox.new424driver = Selenium::WebDriver.for :firefox #, :profile => "Selenium"425$ff = Watir::Browser.new driver426sleep 2427$ff.close428system ("ruby Test_66_Config_setting_cases.rb")429#$ff = FireWatir::Firefox.new430driver = Selenium::WebDriver.for :firefox #, :profile => "Selenium"431$ff = Watir::Browser.new driver432sleep 2433$ff.close434system ("ruby Test_67_No_of_QG_clicks_allowed.rb")435#$ff = FireWatir::Firefox.new436driver = Selenium::WebDriver.for :firefox #, :profile => "Selenium"437$ff = Watir::Browser.new driver438sleep 2439$ff.close440system ("ruby Test_68_QG_cpi_cases.rb")441#$ff = FireWatir::Firefox.new442driver = Selenium::WebDriver.for :firefox #, :profile => "Selenium"443$ff = Watir::Browser.new driver444sleep 2445$ff.close446system ("ruby Test_69_QG_notif_email.rb")447#$ff = FireWatir::Firefox.new448driver = Selenium::WebDriver.for :firefox #, :profile => "Selenium"449$ff = Watir::Browser.new driver450sleep 2451$ff.close452#system ("ruby Test_70_FBconnect.rb")453#$ff = FireWatir::Firefox.new454#sleep 2455#$ff.close456system ("ruby Test_71_Routing_qns_QG.rb")457#$ff = FireWatir::Firefox.new458driver = Selenium::WebDriver.for :firefox #, :profile => "Selenium"459$ff = Watir::Browser.new driver460sleep 2461$ff.close462system ("ruby Test_72_Member_registration_UK.rb")463#$ff = FireWatir::Firefox.new464driver = Selenium::WebDriver.for :firefox #, :profile => "Selenium"465$ff = Watir::Browser.new driver466sleep 2467$ff.close468system ("ruby Test_73_Member_registration_Canada.rb")469#$ff = FireWatir::Firefox.new470driver = Selenium::WebDriver.for :firefox #, :profile => "Selenium"471$ff = Watir::Browser.new driver472sleep 2473$ff.close474#system ("ruby Test_74_Member_registration_India.rb")475#$ff = FireWatir::Firefox.new476#sleep 2477#$ff.close478system ("ruby Test_75_reward_based_on_publisher_cpi.rb")479#$ff = FireWatir::Firefox.new480driver = Selenium::WebDriver.for :firefox #, :profile => "Selenium"481$ff = Watir::Browser.new driver482sleep 2483$ff.close484#system ("ruby Test_XX_Member_acc_close.rb")485#$ff = FireWatir::Firefox.new486#sleep 2487#$ff.close488#system ("ruby ")489system ("ruby Test_XX_Project_QG_status_change.rb")490#$ff = FireWatir::Firefox.new491driver = Selenium::WebDriver.for :firefox #, :profile => "Selenium"492$ff = Watir::Browser.new driver493sleep 2494$ff.close495system ("ruby Test_XX_Profiles_rewards_inactivate.rb")496#$ff = FireWatir::Firefox.new497driver = Selenium::WebDriver.for :firefox #, :profile => "Selenium"498$ff = Watir::Browser.new driver499sleep 2500$ff.close501=end502$myfile = File.open($out_fl_path, 'a');503$myfile.print "</tr></table></center></body></html>";504$myfile.close;505filename = $wd+"/Output Repository/Non4S_Test_Report.html"506#ie = Watir::IE.new507driver = Selenium::WebDriver.for :ie #, :profile => "Selenium"508ie = Watir::Browser.new driver509#ie = FireWatir::Firefox.new510ie.goto("file:///"+filename)511 html_text = ie.html512 $html_contents=ie.html513 #puts $html_contents514 $html_array = $html_contents.split(/\n/)515 #puts $html_array516 0.upto($html_array.size - 1) { |index|517 if($html_array[index] =~ /TEST [A-Z]+ED/)518 #if($html_array[index].contains_text("TEST"))519 puts "***"520 puts $html_array[index]521 #sleep 1...
example-rspec-capybara.rb
Source:example-rspec-capybara.rb
...33 Capybara.default_driver = :selenium34when "FIREFOX-HARDCODED-PROFILE"35 #Register driver to use a hard coded FireFox Profile 36 Capybara.register_driver :selenium do |app|37 profile = Selenium::WebDriver::Firefox::Profile.new38 #this allows you to encode values into a temporary profile that exists only durring testing. 39 #you can look up each of the values at the following URL:40 #documentation: http://www.rubydoc.info/gems/selenium-webdriver/0.0.28/Selenium/WebDriver/Firefox/Profile41 #Does not work before FF48 (FF47 was the last FF version before Mozilla switched to Marrionette)42 #example of a hardcoded profile value43 profile['general.useragent.override'] = ENV['USERAGENT']44 #to make sure downloaded files like PDFs go to the downloads directory45 profile['browser.download.folderList'] = 246 profile['browser.download.manager.showWhenStarting'] = false47 profile['browser.download.dir'] = File.expand_path("../../../", __FILE__)+"/downloads"48 profile['browser.helperApps.neverAsk.saveToDisk'] = "application/pdf"49 profile['plugin.disable_full_page_plugin_for_types'] = "application/pdf"50 options = Selenium::WebDriver::Firefox::Options.new(profile: profile)51 #https://github.com/SeleniumHQ/selenium/wiki/Ruby-Bindings#ssl-certificates52 desired_caps = Selenium::WebDriver::Remote::Capabilities.firefox(53 {54 marionette: true,55 accept_insecure_certs: (ENV['ACCEPTALLCERTS'] == "true")56 }57 )58 if (ENV['FIREFOXPATH'] != 'default')59 Selenium::WebDriver::Firefox.path = ENV['FIREFOXPATH']60 end61 #this was used with capybara (2.14.2) and selenium-webdriver (3.4.1)62 #Capybara::Selenium::Driver.new(app, :browser => :firefox, :profile => profile, desired_capabilities: desired_caps)63 Capybara::Selenium::Driver.new(app, :browser => :firefox, options: options, desired_capabilities: desired_caps)64 end65 Capybara.default_driver = :selenium66## legacy capybara (2.14.2)67# when "FIREFOX-SAVED-PROFILE"68 ## this was used with capybara (2.14.2) and selenium-webdriver (3.4.1) and has been left 69 ## so that if you are using older browsers and need to set this up you still can 70 ## this uses a previously created profile in FF. You can look at the paths for each profile by typing71 ## in the URL bar about:profiles and then copy the path of the profile into your .env or .env.dev files72 ## this allows you to set certain things in the browser like SSL exceptions that you want to be applied 73 ## durring your tests. 74 ## Does not work before FF47 75 # puts "FireFox Profile: "+ENV['FFPROFILEPATH']76 # Capybara.register_driver :selenium do |app|77 # profile = Selenium::WebDriver::Zipper.zip(ENV['FFPROFILEPATH'])78 # desired_caps = Selenium::WebDriver::Remote::Capabilities.firefox(79 # {80 # marionette: true,81 # accept_insecure_certs: (ENV['ACCEPTALLCERTS'] == "true"),82 # firefox_options: {profile: profile},83 # }84 # )85 # 86 # Capybara::Selenium::Driver.new(87 # app,88 # browser: :firefox,89 # desired_capabilities: desired_caps90 # )91 # end92 # Capybara.current_driver = :selenium 93when "FIREFOX-SAVED-PROFILE"94 #capybara (3.0.2) selenium-webdriver (3.11.0)95 #this uses a previously created profile in FF. You can look at the profile name by typing96 #in the URL bar about:profiles and then copy the name of the profile into your .env or .env.dev files97 #this allows you to set certain things in the browser like SSL exceptions that you want to be applied 98 #durring your tests. It does take longer to load 99 #Does not work before FF47 100 101 Capybara.register_driver :selenium do |app|102 options = Selenium::WebDriver::Firefox::Options.new103 options.profile = ENV['FFPROFILEPATH']104 #https://github.com/SeleniumHQ/selenium/wiki/Ruby-Bindings#ssl-certificates105 desired_caps = Selenium::WebDriver::Remote::Capabilities.firefox(106 {107 marionette: true,108 accept_insecure_certs: (ENV['ACCEPTALLCERTS'] == "true"),109 }110 )111 112 Capybara::Selenium::Driver.new(113 app,114 browser: :firefox,115 options: options,116 desired_capabilities: desired_caps117 )118 end119 120 if (ENV['FIREFOXPATH'] != 'default')121 Selenium::WebDriver::Firefox.path = ENV['FIREFOXPATH']122 end 123 Capybara.current_driver = :selenium124when "FIREFOX"125 #works >=FF48126 #https://github.com/SeleniumHQ/selenium/wiki/Ruby-Bindings#ssl-certificates127 desired_caps = Selenium::WebDriver::Remote::Capabilities.firefox(128 {129 marionette: true,130 accept_insecure_certs: (ENV['ACCEPTALLCERTS'] == "true")131 }132 )133 Capybara.register_driver :selenium do |app|134 Capybara::Selenium::Driver.new(135 app, 136 browser: :firefox,137 desired_capabilities: desired_caps138 )139 end140 if (ENV['FIREFOXPATH'] != 'default')141 Selenium::WebDriver::Firefox.path = ENV['FIREFOXPATH']142 end143 Capybara.default_driver = :selenium144when "SAFARI"145 #tested: Safari 10.1.1146 #result: as of Safari 10 there are many problems and not all tests will work147 #This is a standard property but doesn't seem to be working in Safari yet: 148 # desired_caps = Selenium::WebDriver::Remote::Capabilities.safari(149 # {150 # accept_insecure_certs: (ENV['ACCEPTALLCERTS'] == "true")151 # }152 # )153 Capybara.register_driver :selenium do |app|154 Capybara::Selenium::Driver.new(155 app,156 browser: :safari #,157 #desired_capabilities: desired_caps158 )159 end160 Capybara.default_driver = :selenium161when "SAFARI-TECHNOLOGY-PREVIEW"162 #This is what we use to test the Safari release channel. 163 #You will have to install Safari Technology Preview from Apple.164 #This is a standard property but doesn't seem to be working in Safari yet:165 # desired_caps = Selenium::WebDriver::Remote::Capabilities.safari(166 # {167 # accept_insecure_certs: (ENV['ACCEPTALLCERTS'] == "true")168 # }169 # )170 171 Capybara.register_driver :selenium do |app|172 Capybara::Selenium::Driver.new(173 app,174 browser: :safari,175 driver_path: '/Applications/Safari Technology Preview.app/Contents/MacOS/safaridriver' #,176 #desired_capabilities: desired_caps177 )178 end179 Capybara.default_driver = :selenium180else181 #default to Firefox182 #works <FF48 && >=FF48183 Capybara.register_driver :selenium do |app|184 Capybara::Selenium::Driver.new(app, browser: :firefox)185 end186 Capybara.default_driver = :selenium187end188Capybara.default_max_wait_time = (ENV['TIMEOUT'] || 20).to_i189##############################TESTS##############################190#go to https://self-signed.badssl.com/ manualy and add an exception191#then if you are using FireFox go to about:profiles in address bar and get the 192#path to the FireFox Profile and set it in /features/step_definitions/.env.dev 193#run test to see if the exception you194describe 'EXAMPLE TESTS', :js => true, :type => :feature do195 it "ssl cert" do196 #test if ssl cert exception is working 197 visit 'https://self-signed.badssl.com/'198 #puts page.driver.browser.manage.window.inspect199 #worked < chromedriver 2.33 with Chrome 62.200 #page.driver.browser.manage.window.resize_to 1024, 768201 # > chromedriver 2.33 with Chrome 62.202 page.current_window.resize_to 1024, 768203 page.save_screenshot('screenshots/rspec+capybara+selenium.png')204 sleep 1205 end...
example-rspec.rb
Source:example-rspec.rb
...36 #@driver = Selenium::WebDriver.for :chrome, :switches => addswitch37 #capybara (3.0.2) selenium-webdriver (3.11.0)38 @driver = Selenium::WebDriver.for :chrome, options: options39 when "FIREFOX-HARDCODED-PROFILE"40 profile = Selenium::WebDriver::Firefox::Profile.new41 #this allows you to encode values into a temporary profile that exists only durring testing. 42 #you can look up each of the values at the following URL:43 #documentation: http://www.rubydoc.info/gems/selenium-webdriver/0.0.28/Selenium/WebDriver/Firefox/Profile44 #Does not work before FF48 (FF47 was the last FF version before Mozilla switched to Marrionette)45 #example of a hardcoded profile value46 profile['general.useragent.override'] = ENV['USERAGENT']47 #to make sure downloaded files go to the downloads directory48 profile['browser.download.folderList'] = 249 profile['browser.download.manager.showWhenStarting'] = false50 profile['browser.download.dir'] = File.expand_path("../../../", __FILE__)+"/downloads"51 profile['browser.helperApps.neverAsk.saveToDisk'] = "application/pdf"52 profile['plugin.disable_full_page_plugin_for_types'] = "application/pdf"53 options = Selenium::WebDriver::Firefox::Options.new(profile: profile)54 desired_caps = Selenium::WebDriver::Remote::Capabilities.firefox(55 {56 marionette: true,57 accept_insecure_certs: (ENV['ACCEPTALLCERTS'] == "true")58 }59 )60 if (ENV['FIREFOXPATH'] != 'default')61 Selenium::WebDriver::Firefox.path = ENV['FIREFOXPATH']62 end63 #this was used with capybara (2.14.2) and selenium-webdriver (3.4.1)64 #@driver = Selenium::WebDriver.for :firefox, :profile => profile, desired_capabilities: desired_caps65 @driver = Selenium::WebDriver.for :firefox, options: options, desired_capabilities: desired_caps66 # when "FIREFOX-SAVED-PROFILE"67 #this was used with capybara (2.14.2) and selenium-webdriver (3.4.1) and has been left 68 #so that if you are using older browsers and need to set this up you still can 69 #this uses a previously created profile in FF. You can look at the paths for each profile by typing70 #in the URL bar about:profiles and then copy the path of the profile into your .env or .env.dev files71 #this allows you to set certain things in the browser like SSL exceptions that you want to be applied 72 #durring your tests. 73 #Does not work before FF47 74 # puts "FireFox Profile: "+ENV['FFPROFILEPATH']75 # profile = Selenium::WebDriver::Zipper.zip(ENV['FFPROFILEPATH'])76 # desired_caps = Selenium::WebDriver::Remote::Capabilities.firefox(77 # {78 # marionette: true,79 # accept_insecure_certs: (ENV['ACCEPTALLCERTS'] == "true"),80 # firefox_options: {profile: profile},81 # }82 # )83 # @driver = Selenium::WebDriver.for :firefox, desired_capabilities: desired_caps84 when "FIREFOX-SAVED-PROFILE"85 #capybara (3.0.2) selenium-webdriver (3.11.0)86 #this uses a previously created profile in FF. You can look at the paths for each profile by typing87 #in the URL bar about:profiles and then copy the path of the profile into your .env or .env.dev files88 #this allows you to set certain things in the browser like SSL exceptions that you want to be applied 89 #durring your tests. 90 #Does not work before FF47 91 options = Selenium::WebDriver::Firefox::Options.new92 options.profile = ENV['FFPROFILEPATH']93 desired_caps = Selenium::WebDriver::Remote::Capabilities.firefox(94 {95 marionette: true,96 accept_insecure_certs: (ENV['ACCEPTALLCERTS'] == "true"),97 }98 )99 if (ENV['FIREFOXPATH'] != 'default')100 Selenium::WebDriver::Firefox.path = ENV['FIREFOXPATH']101 end102 @driver = Selenium::WebDriver.for :firefox, options: options, desired_capabilities: desired_caps103 when "FIREFOX"104 #works >=FF48105 desired_caps = Selenium::WebDriver::Remote::Capabilities.firefox(106 {...
env.rb
Source:env.rb
...46 Capybara.default_driver = :selenium47 when "FIREFOX-HARDCODED-PROFILE"48 #Register driver to use a hard coded FireFox Profile 49 Capybara.register_driver :firefox do |app|50 profile = Selenium::WebDriver::Firefox::Profile.new51 #example of setting a profile52 profile['general.useragent.override'] = ENV['USERAGENT']53 #to make sure downloaded files go to the downloads directory54 profile['browser.download.folderList'] = 255 profile['browser.download.manager.showWhenStarting'] = false56 profile['browser.download.dir'] = File.expand_path("../../../", __FILE__)+"/downloads"57 profile['browser.helperApps.neverAsk.saveToDisk'] = "application/pdf"58 profile['plugin.disable_full_page_plugin_for_types'] = "application/pdf"59 options = Selenium::WebDriver::Firefox::Options.new(profile: profile)60 desired_caps = Selenium::WebDriver::Remote::Capabilities.firefox(61 {62 marionette: true,63 accept_insecure_certs: (ENV['ACCEPTALLCERTS'] == "true")64 }65 )66 if (ENV['FIREFOXPATH'] != 'default')67 Selenium::WebDriver::Firefox.path = ENV['FIREFOXPATH']68 end69 #this was used with capybara (2.14.2) and selenium-webdriver (3.4.1)70 #Capybara::Selenium::Driver.new(app, :browser => :firefox, :profile => profile, desired_capabilities: desired_caps)71 Capybara::Selenium::Driver.new(app, :browser => :firefox, options: options, desired_capabilities: desired_caps)72 end73 Capybara.default_driver = :firefox74 #when "FIREFOX-SAVED-PROFILE"75 #this was used with capybara (2.14.2) and selenium-webdriver (3.4.1) and has been left 76 #so that if you are using older browsers and need to set this up you still can 77 #Register driver to use a pre-saved FireFox Profile (Does not work before FF47)78 # puts "FireFox Profile: "+ENV['FFPROFILEPATH']79 # Capybara.register_driver :selenium do |app|80 # profile = Selenium::WebDriver::Zipper.zip(ENV['FFPROFILEPATH'])81 # caps = Selenium::WebDriver::Remote::Capabilities.firefox(82 # {83 # marionette: true,84 # accept_insecure_certs: (ENV['ACCEPTALLCERTS'] == "true"),85 # firefox_options: {profile: profile}86 # }87 # )88 # Capybara::Selenium::Driver.new(89 # app,90 # browser: :firefox,91 # desired_capabilities: caps92 # )93 # end94 # Capybara.current_driver = :selenium95 when "FIREFOX-SAVED-PROFILE"96 #capybara (3.0.2) selenium-webdriver (3.11.0)97 #Register driver to use a pre-saved FireFox Profile (Does not work before FF47)98 puts "FireFox Profile: "+ENV['FFPROFILEPATH']99 Capybara.register_driver :selenium do |app|100 options = Selenium::WebDriver::Firefox::Options.new101 options.profile = ENV['FFPROFILEPATH']102 #see standard properties here: https://www.w3.org/TR/webdriver/#capabilities103 caps = Selenium::WebDriver::Remote::Capabilities.firefox(104 {105 marionette: true,106 accept_insecure_certs: (ENV['ACCEPTALLCERTS'] == "true"),107 }108 )109 if (ENV['FIREFOXPATH'] != 'default')110 Selenium::WebDriver::Firefox.path = ENV['FIREFOXPATH']111 end112 Capybara::Selenium::Driver.new(113 app,114 browser: :firefox,115 options: options,...
options.rb
Source:options.rb
...17module Selenium18 module WebDriver19 module Firefox20 class Options21 attr_reader :args, :prefs, :options, :profile22 attr_accessor :binary, :log_level23 KEY = 'moz:firefoxOptions'.freeze24 #25 # Create a new Options instance, only for W3C-capable versions of Firefox.26 #27 # @example28 # options = Selenium::WebDriver::Firefox::Options.new(args: ['--host=127.0.0.1'])29 # driver = Selenium::WebDriver.for :firefox, options: options30 #31 # @param [Hash] opts the pre-defined options to create the Firefox::Options with32 # @option opts [String] :binary Path to the Firefox executable to use33 # @option opts [Array<String>] :args List of command-line arguments to use when starting geckodriver34 # @option opts [Profile, String] :profile Encoded profile string or Profile instance35 # @option opts [String, Symbol] :log_level Log level for geckodriver36 # @option opts [Hash] :prefs A hash with each entry consisting of the key of the preference and its value37 # @option opts [Hash] :options A hash for raw options38 #39 def initialize(**opts)40 @args = Set.new(opts.delete(:args) || [])41 @binary = opts.delete(:binary)42 @profile = opts.delete(:profile)43 @log_level = opts.delete(:log_level)44 @prefs = opts.delete(:prefs) || {}45 @options = opts.delete(:options) || {}46 end47 #48 # Add a command-line argument to use when starting Firefox.49 #50 # @example Start geckodriver on a specific host51 # options = Selenium::WebDriver::Firefox::Options.new52 # options.add_argument('--host=127.0.0.1')53 #54 # @param [String] arg The command-line argument to add55 #56 def add_argument(arg)57 @args << arg58 end59 #60 # Add a new option not yet handled by these bindings.61 #62 # @example63 # options = Selenium::WebDriver::Firefox::Options.new64 # options.add_option(:foo, 'bar')65 #66 # @param [String, Symbol] name Name of the option67 # @param [Boolean, String, Integer] value Value of the option68 #69 def add_option(name, value)70 @options[name] = value71 end72 #73 # Add a preference that is only applied to the user profile in use.74 #75 # @example Set the default homepage76 # options = Selenium::WebDriver::Firefox::Options.new77 # options.add_preference('browser.startup.homepage', 'http://www.seleniumhq.com/')78 #79 # @param [String] name Key of the preference80 # @param [Boolean, String, Integer] value Value of the preference81 #82 def add_preference(name, value)83 prefs[name] = value84 end85 #86 # Run Firefox in headless mode.87 #88 # @example Enable headless mode89 # options = Selenium::WebDriver::Firefox::Options.new90 # options.headless!91 #92 def headless!93 add_argument '-headless'94 end95 #96 # Sets Firefox profile.97 #98 # @example Set the custom profile99 # profile = Selenium::WebDriver::Firefox::Profile.new100 # options = Selenium::WebDriver::Firefox::Options.new101 # options.profile = profile102 #103 # @example Use existing profile104 # options = Selenium::WebDriver::Firefox::Options.new105 # options.profile = 'myprofile'106 #107 # @param [Profile, String] profile Profile to be used108 #109 def profile=(profile)110 @profile = if profile.is_a?(Profile)111 profile112 else113 Profile.from_name(profile)114 end115 end116 #117 # @api private118 #119 def as_json(*)120 opts = @options121 opts[:profile] = @profile.encoded if @profile122 opts[:args] = @args.to_a if @args.any?123 opts[:binary] = @binary if @binary124 opts[:prefs] = @prefs unless @prefs.empty?125 opts[:log] = {level: @log_level} if @log_level126 {KEY => opts}127 end128 end # Options129 end # Firefox130 end # WebDriver131end # Selenium...
webdriver.rb
Source:webdriver.rb
...63 # @see Selenium::WebDriver::Safari::Driver64 #65 # @example66 #67 # WebDriver.for :firefox, profile: 'some-profile'68 # WebDriver.for :firefox, profile: Profile.new69 # WebDriver.for :remote, url: "http://localhost:4444/wd/hub", desired_capabilities: caps70 #71 # One special argument is not passed on to the bridges, :listener.72 # You can pass a listener for this option to get notified of WebDriver events.73 # The passed object must respond to #call or implement the methods from AbstractEventListener.74 #75 # @see Selenium::WebDriver::Support::AbstractEventListener76 #77 def self.for(*args)78 WebDriver::Driver.for(*args)79 end80 #81 # Returns logger instance that can be used across the whole Selenium.82 #...
constants.rb
Source:constants.rb
1module Ptera2 FIREFOX_HEADLESS = proc { |app|3 profile = Selenium::WebDriver::Firefox::Profile.new4 profile['devtools.jsonview.enabled'] = false5 options = Selenium::WebDriver::Firefox::Options.new(profile: profile)6 options.headless!7 # profile["general.useragent.override"] = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.1.1 Safari/605.1.15"8 Capybara::Selenium::Driver.new(app, options: options)9 }10 FIREFOX_NORMAL = proc { |app|11 profile = Selenium::WebDriver::Firefox::Profile.new12 profile['devtools.jsonview.enabled'] = false13 options = Selenium::WebDriver::Firefox::Options.new(profile: profile)14 # options.headless!15 # profile["general.useragent.override"] = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.1.1 Safari/605.1.15"16 Capybara::Selenium::Driver.new(app, options: options)17 }18 FIREFOX_WITH_PROXY = proc { |proxy_host|19 proc { |app|20 profile = Selenium::WebDriver::Firefox::Profile.new21 profile['devtools.jsonview.enabled'] = false22 profile.proxy = Selenium::WebDriver::Proxy.new(http: proxy_host, ssl: proxy_host)23 options = Selenium::WebDriver::Firefox::Options.new(profile: profile)24 Capybara::Selenium::Driver.new(app, options: options)25 }26 }27 FIREFOX_WITH_DOWNLOAD = proc { |download_dir|28 proc { |app|29 profile = Selenium::WebDriver::Firefox::Profile.new30 profile['devtools.jsonview.enabled'] = false31 FileUtils.mkdir_p(download_dir)32 profile['browser.download.dir'] = download_dir.to_s33 profile['browser.download.folderList'] = 234 profile['browser.helperApps.alwaysAsk.force'] = false35 profile['browser.download.manager.showWhenStarting'] = false36 profile['browser.helperApps.neverAsk.saveToDisk'] = "text/csv"37 options = Selenium::WebDriver::Firefox::Options.new(profile: profile)38 # options.headless!39 Capybara::Selenium::Driver.new(app, options: options)40 }41 }42 FIREFOX_WITH_DOWNLOAD_HEADLESS = proc { |download_dir|43 proc { |app|44 profile = Selenium::WebDriver::Firefox::Profile.new45 profile['devtools.jsonview.enabled'] = false46 FileUtils.mkdir_p(download_dir)47 profile['browser.download.dir'] = download_dir.to_s48 profile['browser.download.folderList'] = 249 profile['browser.helperApps.alwaysAsk.force'] = false50 profile['browser.download.manager.showWhenStarting'] = false51 profile['browser.helperApps.neverAsk.saveToDisk'] = "text/csv"52 options = Selenium::WebDriver::Firefox::Options.new(profile: profile)53 options.headless!54 Capybara::Selenium::Driver.new(app, options: options)55 }56 }57end...
profile
Using AI Code Generation
1driver.find_element(:name, 'q').send_keys "Selenium WebDriver"2driver.find_element(:name, 'btnG').click3driver.find_element(:name, 'q').send_keys "Selenium WebDriver"4driver.find_element(:name, 'btnG').click5driver.find_element(:id, 'email').send_keys "
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!