![]() ![]() ![]() Sleep 0.1 # slight wait for alert switch_to. accept sleep 0.25 # allow time for the modal to be handled rescue modal_error # The alert is now gone if current_url != 'about:blank' begin # If navigation has not occurred attempt again and accept alert # since FF may have dismissed the alert at first attempt navigate. expired? sleep 0.05 end rescue Selenium :: WebDriver :: Error :: UnhandledAlertError, Selenium :: WebDriver :: Error :: UnexpectedAlertOpenError # This error is thrown if an unhandled alert is on the page # Firefox appears to automatically dismiss this alert, chrome does not # We'll try to accept it begin switch_to. empty? raise Capybara :: ExpectationNotMet, 'Timed out waiting for Selenium session reset' if timer. to( 'about:blank')Įnd navigated = true # Ensure the page is empty and trigger an UnhandledAlertError for any modals that appear during unload until find_xpath( '/html/body/*'). These examples use Capybara system specs, which can be backed by a number of different drivers. ![]() ![]() Or won't need to ever, in any case, for any reason or feature. It needs to use JS, unless your site doesn't use any JS. delete_all_cookies clear_storage # rescue Selenium::WebDriver::Error::NoSuchAlertError # Handle a bug in Firefox/Geckodriver where it thinks it needs an alert modal to exist # for no good reason # retry rescue Selenium :: WebDriver :: Error :: UnhandledError # rubocop:disable Lint/HandleExceptions # delete_all_cookies fails when we've previously gone # to about:blank, so we rescue this error and do nothing # instead. A library like Selenium or Cuprite that performs automated browser checks. timer( expire_in: 10)īegin unless navigated # Only trigger a navigation if we haven't done it already, otherwise it # can trigger an endless series of unload modals begin manage. # File lib/capybara/selenium/driver.rb, line 115 def reset! # Use instance variable directly so we avoid starting the browser just to reset the session return unless navigated = false timer = Capybara :: Helpers. ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |