Class: Workarea::SystemTest

Inherits:
ActionDispatch::SystemTestCase
  • Object
show all
Extended by:
TestCase::Decoration
Includes:
Factories, IntegrationTest::Configuration, IntegrationTest::Locales, TestCase::Configuration, TestCase::Encryption, TestCase::Geocoder, TestCase::Locales, TestCase::Mail, TestCase::RunnerLocation, TestCase::S3, TestCase::SearchIndexing, TestCase::Workers
Defined in:
lib/workarea/system_test.rb

Instance Method Summary collapse

Methods included from TestCase::Decoration

inherited, load_decorator

Methods included from IntegrationTest::Locales

#set_locales

Methods included from IntegrationTest::Configuration

#set_current_admin, #set_current_user

Methods included from Factories

add, #create_admin_bookmark, #create_admin_visit, #create_audit_log_entry, #create_email_signup, #create_help_article, #create_inventory, #create_release, #create_shipping, #create_shipping_service, #create_shipping_sku, #create_tax_category, #create_tempfile, #factory_defaults, #factory_defaults_config, included, require_factories

Methods included from TestCase::Geocoder

#restore_geocoder_config, #save_geocoder_config

Methods included from TestCase::Encryption

#ensure_encryption_key, #reset_encryption_key

Methods included from TestCase::S3

#mock_s3, #mock_s3_cors_response, #reset_s3

Methods included from TestCase::Locales

#restore_locales, #save_locales, #set_locales

Methods included from TestCase::RunnerLocation

#running_from_source?, #running_in_dummy_app?, #running_in_gem?

Methods included from TestCase::Configuration

#reset_config_state, #store_config_state

Instance Method Details

#javascript?Boolean

Returns:

  • (Boolean)


146
147
148
# File 'lib/workarea/system_test.rb', line 146

def javascript?
  Capybara.current_driver == Capybara.javascript_driver
end

#reset_window_sizeObject

Resets the dimensions of the testing browser



137
138
139
140
141
142
143
144
# File 'lib/workarea/system_test.rb', line 137

def reset_window_size
  return unless javascript?

  page.driver.browser.manage.window.resize_to(
    Workarea.config.capybara_browser_width,
    Workarea.config.capybara_browser_height
  )
end

#scroll_to_bottomObject



150
151
152
# File 'lib/workarea/system_test.rb', line 150

def scroll_to_bottom
  page.execute_script('window.scrollBy(0, 9999999)')
end

#wait_for_iframeObject

There is some kind of timing problem around waiting for this iframe that after a few hours we still can’t find. This is a hack to keep this passing.

May God have mercy on our souls.

TODO v3.6 Remove this after we stop using an iframe for the admin toolbar



167
168
169
# File 'lib/workarea/system_test.rb', line 167

def wait_for_iframe
  sleep(0.5)
end

#wait_for_xhr(time = Capybara.default_max_wait_time) ⇒ Object

Waits until all XHR requests have finished, according to jQuery. Times out according to Capybara’s set timeout. Used to solve race conditions between XHR requests and assertions.



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/workarea/system_test.rb', line 109

def wait_for_xhr(time=Capybara.default_max_wait_time)
  Timeout.timeout(time) do
    loop until finished_all_xhr_requests?
  end
rescue Timeout::Error => error
  javascript_errors = page.driver.browser.manage.logs.get(:browser).each do |log_entry|
    log_entry.level == 'SEVERE' && /Uncaught/.match?(log_entry.message)
  end
  if javascript_errors.present?
    raise(
      Timeout::Error,
      <<~eos
        Problem:
          JavaScript errors were detected during Workarea::SystemTest#wait_for_xhr.
          You might have an error in an XHR callback.  wait_for_xhr is a test helper
          that checks if there are any unfinished XHR requests.  This is called
          automatically throughout testing in Capybara interactions to ensure
          consistency in test results.
        Errors:
          #{javascript_errors.map(&:message).join("\r")}
      eos
    )
  else
    raise error
  end
end