ruby_raider 3.12.1 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/runtime.yml +38 -0
- data/.github/workflows/system_tests.yml +1 -23
- data/.reek.yml +1 -0
- data/.rspec +1 -0
- data/Gemfile +2 -0
- data/README.md +17 -48
- data/RELEASE.md +22 -0
- data/bin/raider +5 -0
- data/lib/commands/scaffolding_commands.rb +2 -25
- data/lib/commands/utility_commands.rb +39 -3
- data/lib/generators/automation/automation_generator.rb +0 -5
- data/lib/generators/automation/templates/component.tt +1 -0
- data/lib/generators/automation/templates/home.tt +2 -2
- data/lib/generators/automation/templates/login.tt +6 -26
- data/lib/generators/automation/templates/page.tt +23 -18
- data/lib/generators/automation/templates/partials/home_page_selector.tt +1 -2
- data/lib/generators/automation/templates/partials/initialize_selector.tt +0 -8
- data/lib/generators/automation/templates/partials/pdp_page_selector.tt +1 -2
- data/lib/generators/automation/templates/partials/url_methods.tt +8 -2
- data/lib/generators/automation/templates/partials/visit_method.tt +0 -5
- data/lib/generators/automation/templates/pdp.tt +1 -9
- data/lib/generators/common_generator.rb +0 -2
- data/lib/generators/generator.rb +19 -17
- data/lib/generators/helper_generator.rb +25 -16
- data/lib/generators/infrastructure/templates/azure_pipelines.tt +1 -1
- data/lib/generators/infrastructure/templates/github.tt +2 -3
- data/lib/generators/infrastructure/templates/github_appium.tt +0 -8
- data/lib/generators/invoke_generators.rb +4 -23
- data/lib/generators/menu_generator.rb +1 -9
- data/lib/generators/rspec/templates/accessibility_spec.tt +1 -9
- data/lib/generators/rspec/templates/spec.tt +8 -24
- data/lib/generators/template_renderer/partial_cache.rb +3 -1
- data/lib/generators/template_renderer.rb +1 -1
- data/lib/generators/templates/common/gemfile.tt +3 -10
- data/lib/generators/templates/common/git_ignore.tt +0 -5
- data/lib/generators/templates/common/partials/mobile_config.tt +3 -1
- data/lib/generators/templates/common/partials/web_config.tt +17 -1
- data/lib/generators/templates/common/rakefile.tt +0 -15
- data/lib/generators/templates/common/read_me.tt +394 -242
- data/lib/generators/templates/common/rubocop.tt +0 -2
- data/lib/generators/templates/helpers/driver_helper.tt +30 -0
- data/lib/generators/templates/helpers/gesture_helper.tt +78 -0
- data/lib/generators/templates/helpers/network_helper.tt +521 -0
- data/lib/generators/templates/helpers/partials/quit_driver.tt +0 -2
- data/lib/generators/templates/helpers/partials/screenshot.tt +0 -2
- data/lib/generators/templates/helpers/partials/selenium_driver.tt +14 -1
- data/lib/generators/templates/helpers/screenshot_helper.tt +490 -0
- data/lib/generators/templates/helpers/spec_helper.tt +56 -27
- data/lib/generators/templates/helpers/trace_helper.tt +1242 -0
- data/lib/generators/templates/helpers/video_helper.tt +3 -8
- data/lib/ruby_raider/runtime/actionability.rb +129 -0
- data/lib/ruby_raider/runtime/actionable.rb +49 -0
- data/lib/ruby_raider/runtime/by_role.rb +55 -0
- data/lib/ruby_raider/runtime/config.rb +79 -0
- data/lib/ruby_raider/runtime/context.rb +38 -0
- data/lib/ruby_raider/runtime/errors.rb +69 -0
- data/lib/ruby_raider/runtime/finders.rb +73 -0
- data/lib/ruby_raider/runtime/js/actionability.js +134 -0
- data/lib/ruby_raider/runtime/js/role_engine.js +315 -0
- data/lib/ruby_raider/runtime/locator_converter.rb +72 -0
- data/lib/ruby_raider/runtime/matchers/base.rb +222 -0
- data/lib/ruby_raider/runtime/matchers/element.rb +183 -0
- data/lib/ruby_raider/runtime/matchers/page.rb +71 -0
- data/lib/ruby_raider/runtime/matchers/presence.rb +41 -0
- data/lib/ruby_raider/runtime/matchers/retrying_block.rb +104 -0
- data/lib/ruby_raider/runtime/observer.rb +170 -0
- data/lib/ruby_raider/runtime/role_finder.rb +83 -0
- data/lib/ruby_raider/runtime/rspec.rb +78 -0
- data/lib/ruby_raider/runtime/selectors.rb +60 -0
- data/lib/ruby_raider/runtime/strict.rb +142 -0
- data/lib/ruby_raider/runtime/wait.rb +84 -0
- data/lib/ruby_raider/runtime.rb +20 -0
- data/lib/scaffolding/name_normalizer.rb +1 -1
- data/lib/scaffolding/project_detector.rb +2 -28
- data/lib/scaffolding/scaffolding.rb +0 -20
- data/lib/scaffolding/templates/component.tt +0 -14
- data/lib/scaffolding/templates/page_object.tt +2 -14
- data/lib/scaffolding/templates/spec.tt +1 -9
- data/lib/utilities/utilities.rb +17 -8
- data/lib/version +1 -1
- data/ruby_raider.gemspec +3 -1
- data/sig/commands/scaffolding_commands.rbs +0 -2
- data/sig/commands/utility_commands.rbs +8 -0
- data/sig/generators/generator.rbs +4 -4
- data/sig/generators/helper_generator.rbs +1 -1
- data/sig/generators/menu_generator.rbs +0 -1
- data/sig/ruby_raider/runtime/actionability.rbs +25 -0
- data/sig/ruby_raider/runtime/actionable.rbs +13 -0
- data/sig/ruby_raider/runtime/by_role.rbs +15 -0
- data/sig/ruby_raider/runtime/config.rbs +26 -0
- data/sig/ruby_raider/runtime/context.rbs +12 -0
- data/sig/ruby_raider/runtime/errors.rbs +36 -0
- data/sig/ruby_raider/runtime/finders.rbs +26 -0
- data/sig/ruby_raider/runtime/locator_converter.rbs +21 -0
- data/sig/ruby_raider/runtime/matchers/base.rbs +64 -0
- data/sig/ruby_raider/runtime/matchers/element.rbs +78 -0
- data/sig/ruby_raider/runtime/matchers/page.rbs +38 -0
- data/sig/ruby_raider/runtime/matchers/presence.rbs +21 -0
- data/sig/ruby_raider/runtime/matchers/retrying_block.rbs +27 -0
- data/sig/ruby_raider/runtime/observer.rbs +46 -0
- data/sig/ruby_raider/runtime/role_finder.rbs +18 -0
- data/sig/ruby_raider/runtime/selectors.rbs +21 -0
- data/sig/ruby_raider/runtime/strict.rbs +35 -0
- data/sig/ruby_raider/runtime/wait.rbs +17 -0
- data/sig/ruby_raider/runtime.rbs +2 -0
- data/sig/scaffolding/project_detector.rbs +0 -4
- data/sig/scaffolding/scaffolding.rbs +0 -5
- data/sig/utilities/utilities.rbs +3 -1
- data/sig/vendor/selenium_webdriver.rbs +71 -0
- data/spec/commands/raider_commands_spec.rb +38 -3
- data/spec/commands/scaffolding_commands_spec.rb +27 -0
- data/spec/commands/utility_commands_spec.rb +53 -0
- data/spec/generators/fixtures/video_helper_stubs/selenium-webdriver.rb +11 -2
- data/spec/generators/gesture_helper_spec.rb +123 -0
- data/spec/generators/network_helper_spec.rb +634 -0
- data/spec/generators/screenshot_helper_spec.rb +776 -0
- data/spec/generators/template_renderer_spec.rb +0 -4
- data/spec/generators/trace_helper_spec.rb +1337 -0
- data/spec/generators/video_helper_spec.rb +0 -9
- data/spec/integration/commands/browser_update_after_creation_spec.rb +0 -8
- data/spec/integration/commands/scaffolding_commands_spec.rb +12 -70
- data/spec/integration/commands/utility_commands_spec.rb +19 -41
- data/spec/integration/content/azure_content_spec.rb +2 -6
- data/spec/integration/content/ci_content_spec.rb +1 -55
- data/spec/integration/content/common_content_spec.rb +1 -118
- data/spec/integration/content/config_content_spec.rb +52 -29
- data/spec/integration/content/gemfile_content_spec.rb +7 -72
- data/spec/integration/content/helper_content_spec.rb +158 -93
- data/spec/integration/content/page_content_spec.rb +85 -87
- data/spec/integration/content/readme_content_spec.rb +176 -71
- data/spec/integration/content/rspec_reporter_content_spec.rb +2 -2
- data/spec/integration/content/rubocop_content_spec.rb +1 -1
- data/spec/integration/content/syntax_validation_spec.rb +2 -2
- data/spec/integration/content/test_content_spec.rb +23 -147
- data/spec/integration/end_to_end_features_spec.rb +1 -43
- data/spec/integration/end_to_end_spec.rb +648 -292
- data/spec/integration/generators/automation_generator_spec.rb +3 -37
- data/spec/integration/generators/axe_addon_spec.rb +2 -35
- data/spec/integration/generators/azure_generator_spec.rb +1 -1
- data/spec/integration/generators/common_generator_spec.rb +1 -40
- data/spec/integration/generators/config_features_spec.rb +1 -24
- data/spec/integration/generators/github_generator_spec.rb +0 -12
- data/spec/integration/generators/helpers_generator_spec.rb +91 -71
- data/spec/integration/generators/invoke_generators_spec.rb +54 -45
- data/spec/integration/generators/rspec_generator_spec.rb +0 -6
- data/spec/integration/scaffolding_e2e_spec.rb +17 -179
- data/spec/integration/spec_helper.rb +4 -6
- data/spec/integration/trace_format_checker.rb +150 -0
- data/spec/integration/trace_page_server.rb +147 -0
- data/spec/menus/menu_generator_spec.rb +14 -39
- data/spec/runtime/actionability_spec.rb +207 -0
- data/spec/runtime/actionable_spec.rb +125 -0
- data/spec/runtime/browser/actionability_script_browser_spec.rb +150 -0
- data/spec/runtime/browser/actionable_browser_spec.rb +98 -0
- data/spec/runtime/browser/finders_browser_spec.rb +148 -0
- data/spec/runtime/browser/matchers_browser_spec.rb +67 -0
- data/spec/runtime/browser/retrying_block_browser_spec.rb +37 -0
- data/spec/runtime/browser/role_engine_browser_spec.rb +184 -0
- data/spec/runtime/browser/strict_browser_spec.rb +38 -0
- data/spec/runtime/by_role_spec.rb +52 -0
- data/spec/runtime/config_spec.rb +79 -0
- data/spec/runtime/context_spec.rb +73 -0
- data/spec/runtime/errors_spec.rb +89 -0
- data/spec/runtime/finders_spec.rb +165 -0
- data/spec/runtime/fixtures/actionability.html +70 -0
- data/spec/runtime/fixtures/locators.html +46 -0
- data/spec/runtime/fixtures/matchers.html +33 -0
- data/spec/runtime/fixtures/roles.html +162 -0
- data/spec/runtime/matchers/base_spec.rb +165 -0
- data/spec/runtime/matchers/element_spec.rb +277 -0
- data/spec/runtime/matchers/page_spec.rb +102 -0
- data/spec/runtime/matchers/presence_spec.rb +59 -0
- data/spec/runtime/matchers/retrying_block_spec.rb +165 -0
- data/spec/runtime/observer_spec.rb +341 -0
- data/spec/runtime/role_finder_spec.rb +156 -0
- data/spec/runtime/role_query_spec.rb +75 -0
- data/spec/runtime/selectors_spec.rb +135 -0
- data/spec/runtime/strict_spec.rb +257 -0
- data/spec/runtime/support/browser.rb +48 -0
- data/spec/runtime/support/fake_bridge.rb +117 -0
- data/spec/runtime/wait_spec.rb +71 -0
- data/spec/scaffolding/name_normalizer_spec.rb +3 -2
- data/spec/scaffolding/scaffold_project_detector_spec.rb +4 -43
- data/spec/system/selenium_spec.rb +1 -5
- data/spec/system/support/system_test_helper.rb +2 -5
- data/spec/utilities/headless_config_spec.rb +0 -7
- data/spec/utilities/trace_command_spec.rb +66 -0
- data/spec/utilities/utilities_spec.rb +24 -0
- metadata +134 -44
- data/lib/generators/automation/templates/header.tt +0 -9
- data/lib/generators/cucumber/cucumber_generator.rb +0 -58
- data/lib/generators/cucumber/templates/accessibility_feature.tt +0 -5
- data/lib/generators/cucumber/templates/accessibility_steps.tt +0 -17
- data/lib/generators/cucumber/templates/cucumber.tt +0 -1
- data/lib/generators/cucumber/templates/env.tt +0 -7
- data/lib/generators/cucumber/templates/feature.tt +0 -21
- data/lib/generators/cucumber/templates/partials/appium_env.tt +0 -26
- data/lib/generators/cucumber/templates/partials/driver_world.tt +0 -18
- data/lib/generators/cucumber/templates/partials/mobile_steps.tt +0 -20
- data/lib/generators/cucumber/templates/partials/selenium_env.tt +0 -56
- data/lib/generators/cucumber/templates/partials/watir_env.tt +0 -48
- data/lib/generators/cucumber/templates/partials/watir_world.tt +0 -4
- data/lib/generators/cucumber/templates/partials/web_steps.tt +0 -28
- data/lib/generators/cucumber/templates/steps.tt +0 -5
- data/lib/generators/cucumber/templates/user_factory.tt +0 -15
- data/lib/generators/cucumber/templates/world.tt +0 -7
- data/lib/generators/templates/helpers/browser_helper.tt +0 -31
- data/lib/generators/templates/helpers/raider_element.tt +0 -159
- data/lib/generators/templates/helpers/wait_helper.tt +0 -470
- data/lib/scaffolding/templates/feature.tt +0 -6
- data/lib/scaffolding/templates/steps.tt +0 -19
- data/sig/generators/cucumber/cucumber_generator.rbs +0 -12
- data/spec/fixtures/watir_master/cucumber_watir/Readme.md.snapshot +0 -175
- data/spec/fixtures/watir_master/cucumber_watir/features/step_definitions/login_steps.rb.snapshot +0 -24
- data/spec/fixtures/watir_master/cucumber_watir/page_objects/abstract/page.rb.snapshot +0 -37
- data/spec/fixtures/watir_master/cucumber_watir/page_objects/pages/login.rb.snapshot +0 -33
- data/spec/fixtures/watir_master/rspec_watir/Readme.md.snapshot +0 -174
- data/spec/fixtures/watir_master/rspec_watir/page_objects/abstract/page.rb.snapshot +0 -37
- data/spec/fixtures/watir_master/rspec_watir/page_objects/pages/login.rb.snapshot +0 -33
- data/spec/fixtures/watir_master/rspec_watir/spec/login_page_spec.rb.snapshot +0 -49
- data/spec/integration/content/cucumber_reporter_content_spec.rb +0 -110
- data/spec/integration/generators/cucumber_generator_spec.rb +0 -100
- data/spec/integration/helpers/wait_helper_mobile_spec.rb +0 -281
- data/spec/integration/helpers/wait_helper_spec.rb +0 -496
- data/spec/integration/helpers/wait_helper_support.rb +0 -183
- data/spec/system/watir_spec.rb +0 -38
|
@@ -1,470 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'selenium-webdriver'
|
|
4
|
-
require 'yaml'
|
|
5
|
-
require_relative 'raider_element'
|
|
6
|
-
|
|
7
|
-
<%- if mobile? -%>
|
|
8
|
-
# Waits before it acts. Each method takes a locator ({ accessibility_id: 'name' },
|
|
9
|
-
# with or without braces, or { ios: {...}, android: {...} }), a RaiderElement or a
|
|
10
|
-
# raw element, polls every 0.1s until the element is ready, then acts on it:
|
|
11
|
-
# tap({ accessibility_id: 'login' })
|
|
12
|
-
# send_keys({ accessibility_id: 'user' }, 'admin')
|
|
13
|
-
# swipe('left', { accessibility_id: 'card' })
|
|
14
|
-
# scroll_to({ accessibility_id: 'footer' })
|
|
15
|
-
# eventually { expect(text(accessibility_id: 'welcome')).to eq('Hi') }
|
|
16
|
-
<%- else -%>
|
|
17
|
-
# Waits before it acts. Each method takes a locator ({ id: 'name' }, with or
|
|
18
|
-
# without braces), a RaiderElement or a raw element, polls every 0.1s until the
|
|
19
|
-
# element is ready, then calls the Selenium method of the same name:
|
|
20
|
-
# click({ id: 'login' })
|
|
21
|
-
# send_keys({ id: 'user' }, 'admin')
|
|
22
|
-
# eventually { expect(text(css: '.welcome')).to eq('Hi') }
|
|
23
|
-
<%- end -%>
|
|
24
|
-
# The wait is config/config.yml `timeout` seconds, or `timeout:` for one call.
|
|
25
|
-
module WaitHelper
|
|
26
|
-
class TimeoutError < Selenium::WebDriver::Error::TimeoutError; end
|
|
27
|
-
|
|
28
|
-
CONFIG_FILE = 'config/config.yml'
|
|
29
|
-
DEFAULT_TIMEOUT = 10
|
|
30
|
-
|
|
31
|
-
def self.default_timeout
|
|
32
|
-
@default_timeout ||= begin
|
|
33
|
-
config = File.exist?(CONFIG_FILE) ? YAML.load_file(CONFIG_FILE) : nil
|
|
34
|
-
(config.is_a?(Hash) && config['timeout']) || DEFAULT_TIMEOUT
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
def self.element(driver, locator, by = {})
|
|
39
|
-
RaiderElement.new(driver, Lookup.for(driver, locator, by))
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
<%- if mobile? -%>
|
|
43
|
-
# Swipes or scrolls the element, or the whole screen without a locator.
|
|
44
|
-
def self.gesture(driver, kind, direction, locator, timeout)
|
|
45
|
-
return element(driver, locator).public_send(kind, direction, timeout: timeout) if locator
|
|
46
|
-
|
|
47
|
-
gesture = Gesture.new(driver, kind, direction)
|
|
48
|
-
Waiter.new(driver, timeout: timeout).perform_action(kind, Lookup.screen(driver), Waiter::PRESENT) do
|
|
49
|
-
gesture.perform(nil)
|
|
50
|
-
end
|
|
51
|
-
nil
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
<%- end -%>
|
|
55
|
-
def find_element(locator = nil, visible: true, timeout: nil, **by)
|
|
56
|
-
Waiter.new(driver, timeout: timeout).find_element(Lookup.for(driver, locator, by), visible)
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
def find_elements(locator = nil, timeout: nil, **by)
|
|
60
|
-
Waiter.new(driver, timeout: timeout).find_elements(Lookup.for(driver, locator, by))
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
<%- if mobile? -%>
|
|
64
|
-
%i[click clear text displayed? enabled? selected?].each do |action|
|
|
65
|
-
<%- else -%>
|
|
66
|
-
%i[click clear submit hover scroll_into_view text displayed? enabled? selected?].each do |action|
|
|
67
|
-
<%- end -%>
|
|
68
|
-
define_method(action) do |locator = nil, timeout: nil, **by|
|
|
69
|
-
WaitHelper.element(driver, locator, by).public_send(action, timeout: timeout)
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
<%- if mobile? -%>
|
|
74
|
-
# tap is Appium's word for click and waits the same way. With a block and no
|
|
75
|
-
# locator it stays Ruby's Object#tap.
|
|
76
|
-
def tap(locator = nil, timeout: nil, **by, &block)
|
|
77
|
-
return super(&block) if block && locator.nil? && by.empty?
|
|
78
|
-
|
|
79
|
-
WaitHelper.element(driver, locator, by).tap(timeout: timeout)
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
<%- end -%>
|
|
83
|
-
def send_keys(locator, *keys, timeout: nil)
|
|
84
|
-
WaitHelper.element(driver, locator).send_keys(*keys, timeout: timeout)
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
<%- unless mobile? -%>
|
|
88
|
-
def select_by(locator, how, what, timeout: nil)
|
|
89
|
-
WaitHelper.element(driver, locator).select_by(how, what, timeout: timeout)
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
<%- end -%>
|
|
93
|
-
def attribute(locator, name, timeout: nil)
|
|
94
|
-
WaitHelper.element(driver, locator).attribute(name, timeout: timeout)
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
<%- if mobile? -%>
|
|
98
|
-
# direction: 'up', 'down', 'left' or 'right'.
|
|
99
|
-
def swipe(direction, locator = nil, timeout: nil)
|
|
100
|
-
WaitHelper.gesture(driver, :swipe, direction, locator, timeout)
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
def scroll(direction, locator = nil, timeout: nil)
|
|
104
|
-
WaitHelper.gesture(driver, :scroll, direction, locator, timeout)
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
# Scrolls the screen until the element is visible, then returns its RaiderElement.
|
|
108
|
-
def scroll_to(locator, direction: 'down', max_scrolls: 10, timeout: nil)
|
|
109
|
-
WaitHelper.element(driver, locator).scroll_to(direction: direction, max_scrolls: max_scrolls, timeout: timeout)
|
|
110
|
-
end
|
|
111
|
-
<%- else -%>
|
|
112
|
-
def drag_and_drop(source, target, timeout: nil)
|
|
113
|
-
WaitHelper.element(driver, source).drag_and_drop(target, timeout: timeout)
|
|
114
|
-
end
|
|
115
|
-
<%- end -%>
|
|
116
|
-
|
|
117
|
-
def eventually(timeout: nil, &block)
|
|
118
|
-
Waiter.new(nil, timeout: timeout).eventually(&block)
|
|
119
|
-
end
|
|
120
|
-
|
|
121
|
-
# How an element is found: a locator in a scope (the driver or a parent
|
|
122
|
-
# Lookup), or an element given as is. The found element is cached until reset.
|
|
123
|
-
class Lookup
|
|
124
|
-
OS_KEYS = %i[android ios].freeze
|
|
125
|
-
PASSED_HINT = 'it was passed in as an element, so it cannot be found again; ' \
|
|
126
|
-
"pass its locator (for example { id: 'name' }) instead"
|
|
127
|
-
MEMBER_HINT = 'it came from find_elements, which keeps no locator per element; call find_elements again to re-query'
|
|
128
|
-
|
|
129
|
-
attr_reader :hint
|
|
130
|
-
|
|
131
|
-
def self.for(driver, locator, by, scope: driver)
|
|
132
|
-
raise ArgumentError, 'pass the locator in braces or as keywords, not both' if locator && !by.empty?
|
|
133
|
-
|
|
134
|
-
given = locator || by
|
|
135
|
-
# A wrapper keeps how it was found, so it can still re-find itself.
|
|
136
|
-
return given.__send__(:lookup) if given.is_a?(RaiderElement)
|
|
137
|
-
return new(scope, element: given, hint: PASSED_HINT) if !given.is_a?(Hash) && given.respond_to?(:displayed?)
|
|
138
|
-
|
|
139
|
-
new(scope, locator: normalize(driver, given))
|
|
140
|
-
end
|
|
141
|
-
<%- if mobile? -%>
|
|
142
|
-
|
|
143
|
-
# No locator and no element: a whole-screen gesture, which locates nothing.
|
|
144
|
-
def self.screen(driver)
|
|
145
|
-
new(driver)
|
|
146
|
-
end
|
|
147
|
-
<%- end -%>
|
|
148
|
-
|
|
149
|
-
def self.normalize(driver, given)
|
|
150
|
-
locator = symbolize(given)
|
|
151
|
-
per_os = !locator.empty? && (locator.keys - OS_KEYS).empty?
|
|
152
|
-
locator = symbolize(locator.fetch(driver.appium_device.to_s.downcase.to_sym, nil), given) if per_os
|
|
153
|
-
return locator if locator.size == 1
|
|
154
|
-
|
|
155
|
-
raise ArgumentError, "a locator is a Hash with one key, such as { id: 'name' }; got #{given.inspect}"
|
|
156
|
-
end
|
|
157
|
-
|
|
158
|
-
def self.symbolize(hash, given = hash)
|
|
159
|
-
return hash.transform_keys(&:to_sym) if hash.is_a?(Hash)
|
|
160
|
-
|
|
161
|
-
raise ArgumentError, "a locator is a Hash with one key, such as { id: 'name' }; got #{given.inspect}"
|
|
162
|
-
end
|
|
163
|
-
|
|
164
|
-
def initialize(scope, locator: nil, element: nil, hint: nil, many: false)
|
|
165
|
-
@scope = scope
|
|
166
|
-
@locator = locator
|
|
167
|
-
@element = element
|
|
168
|
-
@last_found = element
|
|
169
|
-
@hint = hint
|
|
170
|
-
@many = many
|
|
171
|
-
@scope_stale = false
|
|
172
|
-
end
|
|
173
|
-
|
|
174
|
-
# The last element found. A reset only drops the re-find cache, so a wrapper
|
|
175
|
-
# keeps its element (and its == and hash) after a timed-out wait.
|
|
176
|
-
def element
|
|
177
|
-
@element || @last_found
|
|
178
|
-
end
|
|
179
|
-
|
|
180
|
-
def many
|
|
181
|
-
Lookup.new(@scope, locator: @locator, element: @element, many: true)
|
|
182
|
-
end
|
|
183
|
-
|
|
184
|
-
def locate
|
|
185
|
-
return find_all if @many
|
|
186
|
-
|
|
187
|
-
return @element if @element || !@locator
|
|
188
|
-
|
|
189
|
-
@element = @last_found = in_scope { |context| context.find_element(**@locator) }
|
|
190
|
-
end
|
|
191
|
-
|
|
192
|
-
# A stale element may mean its parent was re-rendered too, so stale resets the chain.
|
|
193
|
-
def reset(stale: false)
|
|
194
|
-
@element = nil if @locator
|
|
195
|
-
@scope_stale = false
|
|
196
|
-
@scope.reset(stale: true) if stale && @scope.is_a?(Lookup)
|
|
197
|
-
end
|
|
198
|
-
|
|
199
|
-
# After a stale error: the Lookup up the chain whose element went stale and cannot be
|
|
200
|
-
# found again (passed in, or from find_elements), or nil when re-finding can heal it.
|
|
201
|
-
def lost
|
|
202
|
-
return self unless @locator
|
|
203
|
-
|
|
204
|
-
@scope.lost if @scope_stale
|
|
205
|
-
end
|
|
206
|
-
|
|
207
|
-
def describe
|
|
208
|
-
return 'the element' unless @locator
|
|
209
|
-
|
|
210
|
-
"{#{@locator.map { |key, value| "#{key}: #{value.inspect}" }.join(', ')}}"
|
|
211
|
-
end
|
|
212
|
-
|
|
213
|
-
private
|
|
214
|
-
|
|
215
|
-
# A stale error while searching inside the parent means the parent, or one above it, went stale.
|
|
216
|
-
def in_scope
|
|
217
|
-
return yield(@scope) unless @scope.is_a?(Lookup)
|
|
218
|
-
|
|
219
|
-
begin
|
|
220
|
-
yield(@scope.locate)
|
|
221
|
-
rescue Selenium::WebDriver::Error::StaleElementReferenceError
|
|
222
|
-
@scope_stale = true
|
|
223
|
-
raise
|
|
224
|
-
end
|
|
225
|
-
end
|
|
226
|
-
|
|
227
|
-
def find_all
|
|
228
|
-
return [@element] unless @locator
|
|
229
|
-
|
|
230
|
-
found = in_scope { |context| context.find_elements(**@locator) }
|
|
231
|
-
raise Selenium::WebDriver::Error::NoSuchElementError, 'no match' if found.empty?
|
|
232
|
-
|
|
233
|
-
found
|
|
234
|
-
end
|
|
235
|
-
end
|
|
236
|
-
|
|
237
|
-
# Polls until a Lookup is ready, then yields the raw element. perform_action
|
|
238
|
-
# is the one choke point every public method (bar eventually) goes through.
|
|
239
|
-
class Waiter
|
|
240
|
-
POLL_INTERVAL = 0.1
|
|
241
|
-
DEADLINE_KEY = :raider_wait_deadline
|
|
242
|
-
VISIBLE_ENABLED = %i[visible enabled].freeze
|
|
243
|
-
PRESENT = [].freeze
|
|
244
|
-
<%- if mobile? -%>
|
|
245
|
-
CLICK = %i[visible enabled stable].freeze
|
|
246
|
-
VISIBLE = %i[visible].freeze
|
|
247
|
-
CHECKS = {
|
|
248
|
-
click: CLICK, tap: CLICK,
|
|
249
|
-
send_keys: VISIBLE_ENABLED, clear: VISIBLE_ENABLED,
|
|
250
|
-
swipe: VISIBLE, scroll: VISIBLE, scroll_to: VISIBLE,
|
|
251
|
-
text: PRESENT, attribute: PRESENT, displayed?: PRESENT, enabled?: PRESENT, selected?: PRESENT
|
|
252
|
-
}.freeze
|
|
253
|
-
<%- else -%>
|
|
254
|
-
CHECKS = {
|
|
255
|
-
click: %i[visible enabled stable].freeze,
|
|
256
|
-
send_keys: VISIBLE_ENABLED, clear: VISIBLE_ENABLED, submit: VISIBLE_ENABLED, select_by: VISIBLE_ENABLED,
|
|
257
|
-
hover: %i[visible stable].freeze,
|
|
258
|
-
drag_and_drop: %i[visible enabled stable].freeze,
|
|
259
|
-
scroll_into_view: PRESENT, text: PRESENT, attribute: PRESENT,
|
|
260
|
-
displayed?: PRESENT, enabled?: PRESENT, selected?: PRESENT
|
|
261
|
-
}.freeze
|
|
262
|
-
<%- end -%>
|
|
263
|
-
TARGET_CHECKS = %i[visible].freeze
|
|
264
|
-
STALE = 'stale element'
|
|
265
|
-
RETRIED = [Selenium::WebDriver::Error::StaleElementReferenceError,
|
|
266
|
-
Selenium::WebDriver::Error::ElementClickInterceptedError,
|
|
267
|
-
Selenium::WebDriver::Error::ElementNotInteractableError].freeze
|
|
268
|
-
HELPER_FILES = [__FILE__, File.expand_path('raider_element.rb', __dir__)].freeze
|
|
269
|
-
|
|
270
|
-
def initialize(driver, timeout: nil)
|
|
271
|
-
@driver = driver
|
|
272
|
-
@timeout = timeout
|
|
273
|
-
@last_rect = nil
|
|
274
|
-
end
|
|
275
|
-
|
|
276
|
-
def find_element(lookup, visible)
|
|
277
|
-
perform_action(:find_element, lookup, visible ? TARGET_CHECKS : PRESENT) { RaiderElement.new(@driver, lookup) }
|
|
278
|
-
end
|
|
279
|
-
|
|
280
|
-
def find_elements(lookup)
|
|
281
|
-
perform_action(:find_elements, lookup.many, PRESENT) do |elements|
|
|
282
|
-
elements.map { |found| RaiderElement.new(@driver, Lookup.new(@driver, element: found, hint: Lookup::MEMBER_HINT)) }
|
|
283
|
-
end
|
|
284
|
-
rescue TimeoutError
|
|
285
|
-
[]
|
|
286
|
-
end
|
|
287
|
-
|
|
288
|
-
# checks: a subset of %i[visible enabled stable]; present is always checked.
|
|
289
|
-
# target: a second Lookup (the drop target) that must be visible in the same poll.
|
|
290
|
-
# between: called after each poll that was not ready (scroll_to scrolls there); once it
|
|
291
|
-
# returns false the wait stops, and the timeout message ends with its to_s.
|
|
292
|
-
def perform_action(action, locator, checks, target: nil, between: nil)
|
|
293
|
-
lookup = locator.is_a?(Lookup) ? locator : Lookup.for(@driver, locator, {})
|
|
294
|
-
deadline, waited = deadline_and_wait
|
|
295
|
-
loop do
|
|
296
|
-
seen = catch(:not_ready) do
|
|
297
|
-
elements = [ready(lookup, checks)]
|
|
298
|
-
elements << ready(target, TARGET_CHECKS, 'drop target ') if target
|
|
299
|
-
return yield(*elements)
|
|
300
|
-
rescue *RETRIED => e
|
|
301
|
-
retry_reason(lookup, e, action)
|
|
302
|
-
end
|
|
303
|
-
lookup.reset(stale: seen == STALE)
|
|
304
|
-
target&.reset
|
|
305
|
-
if now >= deadline || (between && !between.call)
|
|
306
|
-
seen = [seen, between].compact.join(' ')
|
|
307
|
-
raise TimeoutError, timeout_message(lookup, checks, seen, [waited, waited + now - deadline].min), backtrace
|
|
308
|
-
end
|
|
309
|
-
|
|
310
|
-
pause(deadline)
|
|
311
|
-
end
|
|
312
|
-
end
|
|
313
|
-
|
|
314
|
-
# Retries the block until it passes. Calls inside it share its deadline (see deadline_and_wait).
|
|
315
|
-
def eventually
|
|
316
|
-
enclosing = Thread.current[DEADLINE_KEY]
|
|
317
|
-
require 'rspec/expectations'
|
|
318
|
-
retried = [RSpec::Expectations::ExpectationNotMetError, Selenium::WebDriver::Error::NoSuchElementError,
|
|
319
|
-
Selenium::WebDriver::Error::StaleElementReferenceError, TimeoutError]
|
|
320
|
-
deadline, waited = deadline_and_wait
|
|
321
|
-
Thread.current[DEADLINE_KEY] = deadline
|
|
322
|
-
loop do
|
|
323
|
-
return yield
|
|
324
|
-
rescue *retried => e
|
|
325
|
-
raise e.exception("(still failing after #{seconds(waited)}s)\n#{e.message}") if now >= deadline
|
|
326
|
-
|
|
327
|
-
pause(deadline)
|
|
328
|
-
end
|
|
329
|
-
ensure
|
|
330
|
-
Thread.current[DEADLINE_KEY] = enclosing
|
|
331
|
-
end
|
|
332
|
-
|
|
333
|
-
private
|
|
334
|
-
|
|
335
|
-
# Inside eventually, a call without timeout: waits for what is left of eventually's
|
|
336
|
-
# deadline; one with timeout: waits that long per attempt, never past eventually's deadline.
|
|
337
|
-
def deadline_and_wait
|
|
338
|
-
started = now
|
|
339
|
-
enclosing = Thread.current[DEADLINE_KEY]
|
|
340
|
-
own = started + (@timeout || WaitHelper.default_timeout) if @timeout || !enclosing
|
|
341
|
-
deadline = [own, enclosing].compact.min
|
|
342
|
-
[deadline, deadline - started]
|
|
343
|
-
end
|
|
344
|
-
|
|
345
|
-
def ready(lookup, checks, prefix = '')
|
|
346
|
-
element = lookup.locate
|
|
347
|
-
reason = unready(element, checks)
|
|
348
|
-
throw :not_ready, "#{prefix}#{reason}" if reason
|
|
349
|
-
|
|
350
|
-
element
|
|
351
|
-
rescue Selenium::WebDriver::Error::NoSuchElementError
|
|
352
|
-
throw :not_ready, "#{prefix}not found"
|
|
353
|
-
end
|
|
354
|
-
|
|
355
|
-
def unready(element, checks)
|
|
356
|
-
return 'present but not visible' if checks.include?(:visible) && !element.displayed?
|
|
357
|
-
return 'visible but disabled' if checks.include?(:enabled) && !element.enabled?
|
|
358
|
-
|
|
359
|
-
'still moving' if checks.include?(:stable) && !stable?(element)
|
|
360
|
-
end
|
|
361
|
-
|
|
362
|
-
# Stable: the same rect on two consecutive polls.
|
|
363
|
-
def stable?(element)
|
|
364
|
-
rect = element.rect
|
|
365
|
-
steady = rect == @last_rect
|
|
366
|
-
@last_rect = rect
|
|
367
|
-
steady
|
|
368
|
-
end
|
|
369
|
-
|
|
370
|
-
def retry_reason(lookup, error, action)
|
|
371
|
-
detail = error.message.lines.first.to_s.strip
|
|
372
|
-
case error
|
|
373
|
-
when Selenium::WebDriver::Error::StaleElementReferenceError
|
|
374
|
-
lost = lookup.lost
|
|
375
|
-
raise error.class, "#{detail} (during #{action}): #{lost.hint}", backtrace if lost
|
|
376
|
-
|
|
377
|
-
STALE
|
|
378
|
-
when Selenium::WebDriver::Error::ElementClickInterceptedError then "click intercepted: #{detail}"
|
|
379
|
-
else "not interactable: #{detail}"
|
|
380
|
-
end
|
|
381
|
-
end
|
|
382
|
-
|
|
383
|
-
def timeout_message(lookup, checks, seen, waited)
|
|
384
|
-
names = checks.map(&:to_s)
|
|
385
|
-
wanted = names.empty? ? 'present' : [names[0..-2].join(', '), names.last].reject(&:empty?).join(' and ')
|
|
386
|
-
"Waited #{seconds(waited)}s for #{lookup.describe} to be #{wanted}; last seen: #{seen}"
|
|
387
|
-
end
|
|
388
|
-
|
|
389
|
-
def seconds(value)
|
|
390
|
-
rounded = value.round(2)
|
|
391
|
-
rounded == rounded.to_i ? rounded.to_i : rounded
|
|
392
|
-
end
|
|
393
|
-
|
|
394
|
-
# Drops this helper's frames so the error points at the page object or spec line.
|
|
395
|
-
def backtrace
|
|
396
|
-
caller.reject { |line| HELPER_FILES.any? { |file| line.start_with?(file) } }
|
|
397
|
-
.drop_while { |line| line.start_with?('<internal:') }
|
|
398
|
-
end
|
|
399
|
-
|
|
400
|
-
def pause(deadline)
|
|
401
|
-
sleep([[POLL_INTERVAL, deadline - now].min, 0].max)
|
|
402
|
-
end
|
|
403
|
-
|
|
404
|
-
def now
|
|
405
|
-
Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
406
|
-
end
|
|
407
|
-
end
|
|
408
|
-
<%- if mobile? -%>
|
|
409
|
-
|
|
410
|
-
# A swipe or scroll through the platform's own mobile: command, as appium_lib issues them.
|
|
411
|
-
class Gesture
|
|
412
|
-
DIRECTIONS = %w[up down left right].freeze
|
|
413
|
-
COMMANDS = {
|
|
414
|
-
ios: { swipe: 'mobile: swipe', scroll: 'mobile: scroll' }.freeze,
|
|
415
|
-
android: { swipe: 'mobile: swipeGesture', scroll: 'mobile: scrollGesture' }.freeze
|
|
416
|
-
}.freeze
|
|
417
|
-
PERCENT = 0.75
|
|
418
|
-
|
|
419
|
-
def initialize(driver, kind, direction)
|
|
420
|
-
@driver = driver
|
|
421
|
-
@device = driver.appium_device.to_s.downcase.to_sym
|
|
422
|
-
@command = COMMANDS.dig(@device, kind)
|
|
423
|
-
raise NotImplementedError, "#{kind} has no gesture for #{driver.appium_device.inspect}; only :ios and :android" unless @command
|
|
424
|
-
|
|
425
|
-
@direction = direction.to_s
|
|
426
|
-
raise ArgumentError, "direction must be up, down, left or right; got #{direction.inspect}" unless DIRECTIONS.include?(@direction)
|
|
427
|
-
end
|
|
428
|
-
|
|
429
|
-
# element: the raw element to act on, or nil for the whole screen.
|
|
430
|
-
def perform(element)
|
|
431
|
-
@driver.execute_script(@command, arguments(element))
|
|
432
|
-
end
|
|
433
|
-
|
|
434
|
-
private
|
|
435
|
-
|
|
436
|
-
def arguments(element)
|
|
437
|
-
return { direction: @direction, element: element&.id }.compact if @device == :ios
|
|
438
|
-
|
|
439
|
-
area = element ? { elementId: element.id } : screen
|
|
440
|
-
area.merge(direction: @direction, percent: PERCENT)
|
|
441
|
-
end
|
|
442
|
-
|
|
443
|
-
def screen
|
|
444
|
-
rect = @driver.window_rect
|
|
445
|
-
{ left: rect.x, top: rect.y, width: rect.width, height: rect.height }
|
|
446
|
-
end
|
|
447
|
-
end
|
|
448
|
-
|
|
449
|
-
# Scrolls the screen once per call, between scroll_to's polls, up to max_scrolls times.
|
|
450
|
-
class Scroller
|
|
451
|
-
def initialize(gesture, max_scrolls)
|
|
452
|
-
@gesture = gesture
|
|
453
|
-
@max_scrolls = max_scrolls
|
|
454
|
-
@scrolls = 0
|
|
455
|
-
end
|
|
456
|
-
|
|
457
|
-
# False once every scroll is used up.
|
|
458
|
-
def call
|
|
459
|
-
return false if @scrolls >= @max_scrolls
|
|
460
|
-
|
|
461
|
-
@gesture.perform(nil)
|
|
462
|
-
@scrolls += 1
|
|
463
|
-
end
|
|
464
|
-
|
|
465
|
-
def to_s
|
|
466
|
-
"after #{@scrolls} scrolls"
|
|
467
|
-
end
|
|
468
|
-
end
|
|
469
|
-
<%- end -%>
|
|
470
|
-
end
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require_relative '../../page_objects/pages/<%= normalized_name %>'
|
|
4
|
-
|
|
5
|
-
Given('I am on the <%= normalized_name.tr("_", " ") %> page') do
|
|
6
|
-
<%- if selenium? -%>
|
|
7
|
-
@page = <%= page_class_name %>.new(driver)
|
|
8
|
-
<%- elsif watir? -%>
|
|
9
|
-
@page = <%= page_class_name %>.new(browser)
|
|
10
|
-
<%- end -%>
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
When('I perform an action') do
|
|
14
|
-
pending 'implement step'
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
Then('I see the expected result') do
|
|
18
|
-
pending 'implement step'
|
|
19
|
-
end
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
# Type definitions for CucumberGenerator
|
|
2
|
-
class CucumberGenerator < Generator
|
|
3
|
-
def generate_feature: () -> void
|
|
4
|
-
def generate_steps: () -> void
|
|
5
|
-
def generate_user_factory: () -> void
|
|
6
|
-
def generate_env_file: () -> void
|
|
7
|
-
def generate_world: () -> void
|
|
8
|
-
def generate_cucumber_file: () -> void
|
|
9
|
-
def generate_accessibility_feature: () -> void
|
|
10
|
-
def generate_accessibility_steps: () -> void
|
|
11
|
-
def template_name: () -> String
|
|
12
|
-
end
|
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
# Ruby Raider
|
|
2
|
-
|
|
3
|
-
<!-- PROJECT LOGO -->
|
|
4
|
-
<br />
|
|
5
|
-
<div align="center">
|
|
6
|
-
<a href="https://github.com/RubyRaider/ruby_raider">
|
|
7
|
-
<img src="https://www.ruby-raider.com/assets/icon-DYY74ofR.png" alt="Logo" style="width:200px;">
|
|
8
|
-
</a>
|
|
9
|
-
<p align="center">
|
|
10
|
-
<a href="https://github.com/RubyRaider/ruby_raider#getting-started"><strong>Explore the docs</strong></a>
|
|
11
|
-
<br />
|
|
12
|
-
<br />
|
|
13
|
-
<a href="https://rubygems.org/gems/ruby_raider">Rubygems</a>
|
|
14
|
-
·
|
|
15
|
-
<a href="https://github.com/RubyRaider/ruby_raider/issues">Report Bug</a>
|
|
16
|
-
·
|
|
17
|
-
<a href="https://github.com/RubyRaider/ruby_raider/issues">Request Feature</a>
|
|
18
|
-
</p>
|
|
19
|
-
<p align="center"> For more information and updates on releases, see <a href="https://ruby-raider.com">https://ruby-raider.com</a></p>
|
|
20
|
-
</div>
|
|
21
|
-
|
|
22
|
-
> **Deprecated:** Watir is deprecated and will be removed in the next major version of ruby_raider; new projects should use Selenium. Watir is only available through `-p automation:watir`. See [Migrating from Watir](https://github.com/RaiderHQ/ruby_raider#migrating-from-watir).
|
|
23
|
-
|
|
24
|
-
## What is Ruby Raider?
|
|
25
|
-
|
|
26
|
-
Ruby Raider is a generator and scaffolding gem to make UI test automation easier.
|
|
27
|
-
|
|
28
|
-
### Supported Frameworks
|
|
29
|
-
|
|
30
|
-
| Web Testing Framework | Mobile Testing Framework |
|
|
31
|
-
|-----------------------|------------------------------------|
|
|
32
|
-
| Cucumber and Selenium | Cucumber and Appium for iOS |
|
|
33
|
-
| RSpec and Selenium | RSpec and Appium for iOS |
|
|
34
|
-
| Cucumber and Watir | Cucumber and Appium for Android |
|
|
35
|
-
| RSpec and Watir | RSpec and Appium for Android |
|
|
36
|
-
| | Cucumber and Appium Cross-platform |
|
|
37
|
-
| | RSpec and Appium Cross-platform |
|
|
38
|
-
|
|
39
|
-
**Optional add-on for web projects:**
|
|
40
|
-
- **Accessibility testing (axe)**: `--accessibility` flag
|
|
41
|
-
|
|
42
|
-
***The web tests run against the [Raider Test Store](https://raider-test-site.onrender.com/).***
|
|
43
|
-
|
|
44
|
-
***To run Appium tests, download the example [app](https://github.com/RaiderHQ/raider_test_app) and start the server:***
|
|
45
|
-
|
|
46
|
-
```bash
|
|
47
|
-
raider u start_appium
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
This works on all platforms (Mac OS, Linux and Windows).
|
|
51
|
-
|
|
52
|
-
## Getting Started
|
|
53
|
-
|
|
54
|
-
```bash
|
|
55
|
-
gem install ruby_raider
|
|
56
|
-
raider new [name_of_project]
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
Or with parameters:
|
|
60
|
-
|
|
61
|
-
```bash
|
|
62
|
-
raider new [name_of_project] -p framework:[framework] automation:[automation_type]
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
### Commands
|
|
66
|
-
|
|
67
|
-
```
|
|
68
|
-
raider generate # Scaffolding commands
|
|
69
|
-
raider utility # Utility commands
|
|
70
|
-
raider new [NAME] # Create new project
|
|
71
|
-
raider version # Show version
|
|
72
|
-
raider help [COMMAND] # Describe commands
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
Shortcuts: `g` (generate), `n` (new), `u` (utility), `v` (version)
|
|
76
|
-
|
|
77
|
-
### Scaffolding
|
|
78
|
-
|
|
79
|
-
```
|
|
80
|
-
raider g page [NAME] # Create page object
|
|
81
|
-
raider g spec [NAME] # Create RSpec test
|
|
82
|
-
raider g feature [NAME] # Create Cucumber feature
|
|
83
|
-
raider g steps [NAME] # Create step definitions
|
|
84
|
-
raider g scaffold [NAME] # Create page + test + steps
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
## Reusing the login
|
|
88
|
-
|
|
89
|
-
Tag an example `:logged_in` (RSpec) or a scenario `@logged_in` (Cucumber) and the suite logs in once, saves the
|
|
90
|
-
session, and restores it for the next tagged example or run instead of filling in the login form again. The generated
|
|
91
|
-
account example shows it. If the saved session no longer works, the real login runs again and the state is saved anew.
|
|
92
|
-
|
|
93
|
-
For another role, call it yourself with its own name:
|
|
94
|
-
|
|
95
|
-
```ruby
|
|
96
|
-
SessionState.new(driver, name: 'admin').reuse(valid: -> { dashboard.tap(&:visit).admin? }) do
|
|
97
|
-
# the real login for the admin
|
|
98
|
-
end
|
|
99
|
-
```
|
|
100
|
-
|
|
101
|
-
With Watir, pass `browser.driver`, the Selenium driver underneath the browser.
|
|
102
|
-
|
|
103
|
-
- `login_state: max_age:` in `config/config.yml` is how many seconds a saved login stays valid (default 3600).
|
|
104
|
-
- `RAIDER_LOGIN_STATE=off` always does the real login and saves nothing; `RAIDER_LOGIN_STATE=refresh` ignores the saved
|
|
105
|
-
file, logs in and saves again.
|
|
106
|
-
- The state lives in `.raider/auth/` and is git-ignored. It holds live session tokens, so it must not be committed,
|
|
107
|
-
cached or uploaded as a CI artifact. Nothing in it is ever printed.
|
|
108
|
-
|
|
109
|
-
## Reporting
|
|
110
|
-
|
|
111
|
-
Every run writes machine-readable results to `raider-results/` (including `run.json`) and a browsable report,
|
|
112
|
-
`raider-results/index.html`. The reporter runs in plugin mode:
|
|
113
|
-
`features/support/env.rb` requires `raider_reporter/cucumber`, so no extra Cucumber formatter flag is needed.
|
|
114
|
-
|
|
115
|
-
To upload runs to Raider, set these environment variables before running the suite.
|
|
116
|
-
`RAIDER_TOKEN` and `RAIDER_ENDPOINT` come from your Raider Hideout server (its setup page, or `bin/rails hideout:setup` /
|
|
117
|
-
`hideout:token`):
|
|
118
|
-
|
|
119
|
-
```bash
|
|
120
|
-
export RAIDER_TOKEN=your-token
|
|
121
|
-
export RAIDER_ENDPOINT=https://hideout.example.com
|
|
122
|
-
```
|
|
123
|
-
|
|
124
|
-
Without `RAIDER_TOKEN`, nothing is uploaded and the suite output is unchanged. Failure screenshots are attached to the
|
|
125
|
-
report and to Raider. See the [raider_reporter README](https://github.com/RaiderHQ/raider_reporter) for details.
|
|
126
|
-
|
|
127
|
-
### Video replay
|
|
128
|
-
|
|
129
|
-
Every test is recorded, and the video is kept only for failing tests. It is attached
|
|
130
|
-
to the report as `video` and saved under `raider-results/attachments/`, next to the failure screenshot.
|
|
131
|
-
The video is a `video.webm` built from page screenshots with ffmpeg.
|
|
132
|
-
|
|
133
|
-
- Video is on by default: `video:` in `config/config.yml` (`enabled: true`, `fps: 5`, `max_width: 1280`).
|
|
134
|
-
- Turn it off for one run with `VIDEO=off bundle exec cucumber`, or for the project with
|
|
135
|
-
`raider u video off` (`raider u video on` turns it back on).
|
|
136
|
-
- ffmpeg is downloaded on first use, checked against a pinned SHA-256 and cached in `~/.cache/raider`
|
|
137
|
-
(`%LOCALAPPDATA%\raider` on Windows). `raider u video install` downloads it ahead of time (CI does this before the
|
|
138
|
-
tests and caches the folder), and `raider u video status` prints the binary in use.
|
|
139
|
-
- `RAIDER_FFMPEG_PATH` uses your own ffmpeg (it needs libvpx) instead of the download, and `RAIDER_CACHE_DIR` moves
|
|
140
|
-
the cache.
|
|
141
|
-
- The RaiderHQ `ffmpeg-7.1` release that the download comes from is not published yet. Until it is, set
|
|
142
|
-
`RAIDER_FFMPEG_PATH` to get videos; without it the suite runs as usual and prints one `[video]` line.
|
|
143
|
-
- If ffmpeg is missing or recording fails, the suite still runs and its exit code is unchanged; you get one `[video]`
|
|
144
|
-
line on stderr and no video.
|
|
145
|
-
- Known limits: a frame is taken after each page load, click and text change, plus one at the end of a failing test,
|
|
146
|
-
so changes the page makes on its own between actions show up in the next frame. There is one recorded driver per
|
|
147
|
-
process.
|
|
148
|
-
|
|
149
|
-
### Quarantine
|
|
150
|
-
|
|
151
|
-
CI runs the suite through `bundle exec raider-reporter exec -- …` with `RAIDER_QUARANTINE` set. Tests quarantined in
|
|
152
|
-
Raider still run and are still reported (as `quarantined`), and a build whose only failures are quarantined stays green.
|
|
153
|
-
Local runs keep quarantine off. To turn it off in CI, remove `RAIDER_QUARANTINE` from the pipeline.
|
|
154
|
-
|
|
155
|
-
### Quality gate
|
|
156
|
-
|
|
157
|
-
The `raider-gate` CI job runs `bundle exec raider-reporter gate` after the tests and
|
|
158
|
-
fails the pipeline when the Raider quality gate fails. It is off until you turn it on:
|
|
159
|
-
|
|
160
|
-
- set the CI variable `RAIDER_GATE=1` (a repository variable under Settings → Secrets and variables → Actions → Variables);
|
|
161
|
-
- turn on rules under the project's Gate page in Raider: a minimum pass rate, no new failures against the default
|
|
162
|
-
branch, no new flaky tests;
|
|
163
|
-
- optionally require the `raider/gate` check in branch protection.
|
|
164
|
-
|
|
165
|
-
`raider-reporter gate` exits 1 when the gate fails, naming the failed rules, and 2 when it gets no verdict (timeout,
|
|
166
|
-
Raider unreachable, token rejected, build not found). `RAIDER_GATE_TIMEOUT` sets how long it waits, in seconds
|
|
167
|
-
(default 600). The job stays off by default because a project without `RAIDER_TOKEN`, or a pull request from a fork,
|
|
168
|
-
would exit 2 on every run.
|
|
169
|
-
|
|
170
|
-
Parallel test jobs that upload to one build must each set `RAIDER_SHARD_TOTAL` (the number of jobs) and
|
|
171
|
-
`RAIDER_SHARD_INDEX` (1 to that number), so the gate waits for all of them instead of judging the first one to finish.
|
|
172
|
-
|
|
173
|
-
### Sponsors
|
|
174
|
-
|
|
175
|
-
This project is tested with BrowserStack.
|