Class: Workarea::SystemTest

Inherits:
ActionDispatch::SystemTestCase
  • Object
show all
Extended by:
TestCase::Decoration
Includes:
Factories, IntegrationTest::Configuration, 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::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::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?

Instance Method Details

#assert_no_js_errorsObject

Intentionally fails, providing a custom error message, if any JavaScript errors are thrown during a test run.



141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/workarea/system_test.rb', line 141

def assert_no_js_errors
  page.driver.browser.manage.logs.get(:browser).each do |log_entry|
    # Bad responses (like 422 or 401) show as errors as well, which are OK
    # for system tests because they indicate the site is functioning properly.
    if log_entry.level == 'SEVERE' && log_entry.message =~ /Uncaught/
      assert(false, log_entry.message)
    elsif log_entry.level == 'WARNING'
      STDERR.puts 'WARN: Browser warning'
      STDERR.puts log_entry.message
    end
  end
end

#javascript?Boolean

Returns:

  • (Boolean)


127
128
129
# File 'lib/workarea/system_test.rb', line 127

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

#reset_window_sizeObject

Resets the dimensions of the testing browser



118
119
120
121
122
123
124
125
# File 'lib/workarea/system_test.rb', line 118

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



131
132
133
# File 'lib/workarea/system_test.rb', line 131

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



163
164
165
# File 'lib/workarea/system_test.rb', line 163

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.



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/workarea/system_test.rb', line 90

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,
      "        Problem:\n          JavaScript errors were detected during Workarea::SystemTest#wait_for_xhr.\n          You might have an error in an XHR callback.  wait_for_xhr is a test helper\n          that checks if there are any unfinished XHR requests.  This is called\n          automatically throughout testing in Capybara interactions to ensure\n          consistency in test results.\n        Errors:\n          \#{javascript_errors.map(&:message).join(\"\\r\")}\n      eos\n    )\n  else\n    raise error\n  end\nend\n"