ruby_raider 4.0.0 → 4.1.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.
Files changed (78) hide show
  1. checksums.yaml +4 -4
  2. data/.github/ffmpeg/build.sh +208 -0
  3. data/.github/ffmpeg/check.sh +72 -0
  4. data/.github/ffmpeg/frames.rb +34 -0
  5. data/.github/ffmpeg/probe.sh +17 -0
  6. data/.github/workflows/ffmpeg.yml +160 -0
  7. data/README.md +226 -33
  8. data/RELEASE.md +19 -0
  9. data/lib/commands/flow_commands.rb +104 -0
  10. data/lib/generators/templates/common/read_me.tt +6 -7
  11. data/lib/generators/templates/flows/flow_helper.tt +42 -0
  12. data/lib/generators/templates/flows/run.tt +332 -0
  13. data/lib/generators/templates/helpers/video_helper.tt +1 -2
  14. data/lib/ruby_raider/ffmpeg.rb +38 -11
  15. data/lib/ruby_raider.rb +16 -0
  16. data/lib/utilities/flows/next_run.rb +61 -0
  17. data/lib/utilities/flows/notifier.rb +76 -0
  18. data/lib/utilities/flows/os/command_runner.rb +73 -0
  19. data/lib/utilities/flows/os/cron.rb +137 -0
  20. data/lib/utilities/flows/os/launchd.rb +164 -0
  21. data/lib/utilities/flows/os/linux.rb +63 -0
  22. data/lib/utilities/flows/os/systemd.rb +178 -0
  23. data/lib/utilities/flows/os/task_scheduler.rb +179 -0
  24. data/lib/utilities/flows/project.rb +170 -0
  25. data/lib/utilities/flows/run_log.rb +61 -0
  26. data/lib/utilities/flows/runner.rb +206 -0
  27. data/lib/utilities/flows/schedule.rb +221 -0
  28. data/lib/utilities/flows/schedule_store.rb +135 -0
  29. data/lib/utilities/flows/scheduler.rb +187 -0
  30. data/lib/version +1 -1
  31. data/sig/commands/flow_commands.rbs +13 -0
  32. data/sig/ruby_raider/ffmpeg.rbs +1 -0
  33. data/sig/ruby_raider.rbs +2 -0
  34. data/sig/utilities/flows/next_run.rbs +15 -0
  35. data/sig/utilities/flows/notifier.rbs +29 -0
  36. data/sig/utilities/flows/os/command_runner.rbs +27 -0
  37. data/sig/utilities/flows/os/cron.rbs +34 -0
  38. data/sig/utilities/flows/os/launchd.rbs +45 -0
  39. data/sig/utilities/flows/os/linux.rbs +27 -0
  40. data/sig/utilities/flows/os/systemd.rbs +43 -0
  41. data/sig/utilities/flows/os/task_scheduler.rbs +53 -0
  42. data/sig/utilities/flows/project.rbs +46 -0
  43. data/sig/utilities/flows/run_log.rbs +22 -0
  44. data/sig/utilities/flows/runner.rbs +35 -0
  45. data/sig/utilities/flows/schedule.rbs +61 -0
  46. data/sig/utilities/flows/schedule_store.rbs +34 -0
  47. data/sig/utilities/flows/scheduler.rbs +42 -0
  48. data/spec/commands/flow_commands_spec.rb +128 -0
  49. data/spec/generators/flow_helper_spec.rb +40 -0
  50. data/spec/generators/video_helper_spec.rb +21 -4
  51. data/spec/integration/content/gemfile_content_spec.rb +2 -2
  52. data/spec/integration/content/readme_content_spec.rb +7 -2
  53. data/spec/integration/end_to_end_spec.rb +83 -8
  54. data/spec/integration/flows/flow_project.rb +62 -0
  55. data/spec/integration/flows/run_command_spec.rb +91 -0
  56. data/spec/integration/flows/run_lifecycle_spec.rb +383 -0
  57. data/spec/utilities/ffmpeg_spec.rb +80 -7
  58. data/spec/utilities/flows/next_run_spec.rb +119 -0
  59. data/spec/utilities/flows/notifier_spec.rb +121 -0
  60. data/spec/utilities/flows/os/command_runner_spec.rb +56 -0
  61. data/spec/utilities/flows/os/cron_spec.rb +287 -0
  62. data/spec/utilities/flows/os/launchd_spec.rb +293 -0
  63. data/spec/utilities/flows/os/linux_spec.rb +149 -0
  64. data/spec/utilities/flows/os/systemd_spec.rb +329 -0
  65. data/spec/utilities/flows/os/task_scheduler_spec.rb +505 -0
  66. data/spec/utilities/flows/project_spec.rb +178 -0
  67. data/spec/utilities/flows/run_log_spec.rb +47 -0
  68. data/spec/utilities/flows/runner_spec.rb +313 -0
  69. data/spec/utilities/flows/schedule_spec.rb +233 -0
  70. data/spec/utilities/flows/schedule_store_spec.rb +137 -0
  71. data/spec/utilities/flows/scheduler_spec.rb +329 -0
  72. data/spec/utilities/video_command_spec.rb +13 -0
  73. metadata +58 -7
  74. data/docs/superpowers/plans/2026-10-25-failure-video-replay.md +0 -400
  75. data/docs/superpowers/plans/2026-10-26-parity-cleanup.md +0 -233
  76. data/docs/superpowers/plans/2026-10-28-failure-card.md +0 -295
  77. data/docs/superpowers/specs/2026-10-25-failure-video-replay-design.md +0 -214
  78. data/docs/superpowers/specs/2026-10-28-failure-card-design.md +0 -210
data/README.md CHANGED
@@ -31,57 +31,243 @@ Ruby Raider is a CLI gem for scaffolding and generating UI test automation frame
31
31
 
32
32
  ## Supported Frameworks
33
33
 
34
+ Ruby Raider works on Mac OS, Linux and Windows.
35
+
34
36
  ### Web Testing
35
37
 
36
- | Test Framework | Selenium |
37
- |----------------|----------|
38
- | RSpec | ✅ |
38
+ Web projects use **Selenium and RSpec**. They get:
39
+
40
+ - Locators people see on the page (`label:`, `text:`, `by_role(...)` and more), with strict matching
41
+ - Automatic waiting for elements and actions: no implicit wait, no `sleep`
42
+ - Retrying RSpec matchers
43
+ - Login reuse, failure video, failure trace, network mocking and screenshot comparison
44
+ - Optional accessibility tests (axe) and a choice of GitHub Actions or Azure Pipelines
45
+
46
+ See [What's Included](#whats-included) for each one.
39
47
 
40
- ruby_raider 4.0 generates Selenium projects with RSpec only. Projects generated by 3.x (Cucumber, Watir) keep working on the 3.x line through the `ruby_raider` pin in their Gemfile (`~> 3.15` or an older `~> 3.x` requirement); 4.0 does not read or convert them.
48
+ ### Mobile Testing
41
49
 
42
- ### Mobile Testing (Appium)
50
+ Mobile projects use **Appium and RSpec**:
43
51
 
44
52
  | Test Framework | iOS | Android | Cross-Platform |
45
53
  |----------------|-----|---------|----------------|
46
54
  | RSpec | ✅ | ✅ | ✅ |
47
55
 
48
- ### Optional Add-on (Web Only)
56
+ They get:
57
+
58
+ - Appium locators: `accessibility_id:`, `id:`, `xpath:` and `class_name:`
59
+ - Automatic waiting: `find_element` waits for a match, and `click`, `send_keys` and `clear` wait until the element is displayed and enabled
60
+ - Retrying RSpec matchers
61
+ - Gestures: `swipe`, `scroll` and `scroll_to`, on iOS and Android
62
+ - Failure video from Appium's screen recording
63
+ - Raider reporting and a GitHub Actions workflow that starts a simulator or emulator and Appium
64
+
65
+ On native app screens, `find_element` returns the first match (strict matching is web only) and `submit` is not checked.
66
+
67
+ To run the examples, download the example [app](https://github.com/RaiderHQ/raider_test_app) and start the server:
68
+
69
+ ```bash
70
+ raider u start_appium
71
+ ```
72
+
73
+ ### Optional Add-ons
49
74
 
50
75
  | Add-on | Flag | Description |
51
76
  |--------|------|-------------|
52
- | Accessibility | `--accessibility` | Adds axe gem + example accessibility tests |
53
- | CI provider | `-p ci:azure` | Generates `azure-pipelines.yml` instead of the GitHub Actions workflow (default `ci:github`) |
54
-
55
- This works on all platforms (Mac OS, Linux and Windows).
77
+ | Accessibility (web) | `--accessibility` | Adds the axe gem and example accessibility tests |
78
+ | CI provider (web) | `-p ci:azure` | Generates `azure-pipelines.yml` instead of the GitHub Actions workflow (default `ci:github`) |
56
79
 
57
80
  ## What's Included
58
81
 
59
- Every generated project comes with:
60
-
61
- - **Page Object Model** — Base page and component classes with example pages
62
- - **Test examples** — Working login tests against the [Raider Test Store](https://raider-test-site.onrender.com/)
63
- - **Raider reporting** — Generated projects include [raider_reporter](https://github.com/RaiderHQ/raider_reporter), which writes results to `raider-results/` and uploads runs to your Raider Hideout server when `RAIDER_TOKEN` and `RAIDER_ENDPOINT` are set; generated CI runs the suite through `raider-reporter exec` with `RAIDER_QUARANTINE`, so quarantined tests do not fail the build; an opt-in `raider-gate` job (`RAIDER_GATE=1`) fails CI when the Raider quality gate fails
64
- - **Locators, waiting and assertions**: The runtime (`ruby_raider/runtime`), loaded by every generated project, adds waiting to Selenium and Appium themselves. Locators go beyond `id` and `css`: `label:`, `placeholder:`, `alt:`, `title:`, `text:`, `test_id:` and `by_role('button', name: 'Save')` find elements the way a person sees them, and `find_element` fails when a locator matches more than one. `find_element` and `find_elements` wait for a match, so there is no implicit wait and no `sleep`. Before an action the runtime waits until the element is ready: `click` waits until it is visible, enabled, not inert, stable and not covered; `send_keys` and `clear` until it is visible, enabled, editable and not inert; `submit` until it is visible, enabled and not inert (on native apps, displayed and enabled); `force: true` skips the checks for one call. `timeout`, `strict` and `actionability` in `config.yml` (or `RAIDER_TIMEOUT`, `RAIDER_STRICT`, `RAIDER_ACTIONABILITY`) set the rules. RSpec matchers (`have_text`, `have_value`, `have_attribute`, `have_css`, `have_xpath`, `be_visible`, `be_hidden`, `be_enabled`, `be_disabled`, `be_checked`, `have_count`, `have_title`, `have_url`, `have_element`) retry until the page matches, and a block expectation such as `expect { driver.find_element(id: 'status').text }.to eq('done')` retries with any value matcher
65
- - **Example tests or a skeleton (`examples:false`)** — start from the working login examples, or pass `examples:false` for an empty skeleton with the helpers, config, CI and README (see [Getting Started](#getting-started))
66
- - **Login reuse** — generated web projects (Selenium) log in once and restore the saved session for examples tagged `:logged_in`; `RAIDER_LOGIN_STATE=off|refresh` and `login_state: max_age:` control it, and the state stays in git-ignored `.raider/auth/`
67
- - **Failure video replay** — Every test is recorded and the video is kept only for failing tests, attached to the report as `video` (WebM from page screenshots for Selenium, Appium's own MP4 for mobile, which needs `ffmpeg` on the Appium server host for iOS and for Android recordings over 180 s). Turn it off per run with `VIDEO=off`, or per project with `raider u video off`; ffmpeg is downloaded once, SHA-256 checked and cached in `~/.cache/raider`. The RaiderHQ `ffmpeg-7.1` build that the download uses is not published yet, so for now set `RAIDER_FFMPEG_PATH` to an ffmpeg with libvpx to get web videos
68
- - **Failure trace replay** (Selenium) — Failing tests keep a step-by-step trace: each action with its locator and wait time, a screenshot and the page HTML after every step that changes the page, plus network requests and console messages on Chrome, Edge and Firefox. It is saved as `raider-results/attachments/<n>-trace.zip`, attached to the report as `trace` and opened in Raider Desktop or on Hideout. `TRACE=on` keeps passing tests too, `TRACE=off` captures nothing, and `raider u trace on|off` sets it for the project. Typed values in password fields and `RAIDER_SECRET_*` values are hidden; other typed values, page text and URLs are kept, so treat a trace like the video. Request headers, cookies and bodies are never captured
69
- - **Network mocking** (Selenium) — Answer a request with your own response or block it, from the test: `mock_request('**/api/users', json: { users: [] })`, `mock_request(url, status: 500)` and `block_request('**/*.png')`, with `calls` to check what the page asked for. It uses WebDriver BiDi on Chrome, Edge and Firefox (Safari and `BIDI=off` raise `NetworkHelper::Unavailable`), handles CORS for cross-origin mocks, clears mocks after each test, and marks mocked requests in the trace
70
- - **Screenshot comparison** (Selenium) — `match_screenshot('home')` compares the page, or an element with `element:`, with a baseline in `screenshots/baselines/<browser>/`. The first run saves the baseline; later runs fail on a difference and attach the expected, actual and diff pictures to the report and the trace. `SCREENSHOTS=update` rewrites baselines, a missing baseline fails on CI, and tolerances (`threshold`, `max_diff_pixels`, `max_diff_ratio`) go in `config/config.yml` under `screenshots:`. Generate baselines where CI runs: a Retina laptop makes 2x pictures
71
- - **GitHub Actions CI** — Ready-to-use test pipeline that caches ffmpeg for failure videos
72
- - **Rake tasks** — Default, smoke, and regression tasks with tag-based filtering
73
- - **Retry support** — RSpec retry with configurable retry count via `RETRY_COUNT` env var
74
- - **Re-run failed tests** — RSpec keeps `spec/examples.txt` for `--only-failures`
75
- - **Parallel execution** — parallel_tests and parallel_split_test gems included
76
- - **Configurable browser** — Chrome/Firefox with customizable arguments, viewport, timeout, and headless mode
77
- - **Linting** — RuboCop and Reek configs included
78
-
79
- For Appium projects, download the example [app](https://github.com/RaiderHQ/raider_test_app) and start the server:
82
+ Every generated project loads the Raider runtime (`ruby_raider/runtime`). It adds locators, waiting and assertions to Selenium and Appium themselves.
83
+
84
+ ### Locators
85
+
86
+ Find elements the way a person sees them, on top of Selenium's `id:`, `css:`, `xpath:`, `name:`, `class:` and `link_text:`:
87
+
88
+ | Key | Finds |
89
+ |-----|-------|
90
+ | `label:` | the field with that label, `aria-label` or `aria-labelledby` |
91
+ | `placeholder:` | the field with that placeholder |
92
+ | `alt:` | the element with that `alt` text |
93
+ | `title:` | the element with that `title` |
94
+ | `text:` | the innermost element whose text contains it |
95
+ | `test_id:` | the element whose `data-testid` equals it |
96
+ | `by_role(...)` | the element with that ARIA role and name |
97
+
98
+ ```ruby
99
+ driver.find_element(label: 'Email')
100
+ driver.find_element(label: ['Email', { exact: true }]) # whole text only
101
+ driver.find_element(by_role('button', name: 'Save'))
102
+ driver.find_element(by_role('heading', level: 1))
103
+ ```
104
+
105
+ - Text keys match part of the text and ignore extra spaces. Pass `{ exact: true }` for the whole text.
106
+ - `test_id:` reads another attribute with `Raider.test_id_attribute = 'data-qa'` or `RAIDER_TEST_ID_ATTRIBUTE`.
107
+ - **Strict matching:** `find_element` fails with `Raider::AmbiguousMatch` when a locator matches more than one element. `find_elements` never does. Turn it off with `raider u strict off`.
108
+
109
+ These keys are for web pages. Mobile projects use Appium's locators (see [Mobile Testing](#mobile-testing)).
110
+
111
+ ### Waiting and actionability
112
+
113
+ - `find_element` and `find_elements` wait for a match. There is no implicit wait and no `sleep`.
114
+ - Before an action, the runtime waits until the element is ready:
115
+
116
+ | Action | Waits until the element is |
117
+ |--------|----------------------------|
118
+ | `click` | visible, enabled, not inert, stable and not covered |
119
+ | `send_keys`, `clear` | visible, enabled, editable and not inert |
120
+ | `submit` | visible, enabled and not inert |
121
+
122
+ - `force: true` skips the checks for one call: `button.click(force: true)`.
123
+ - Set the rules with `timeout`, `strict` and `actionability` in `config/config.yml`, or `RAIDER_TIMEOUT`, `RAIDER_STRICT` and `RAIDER_ACTIONABILITY`.
124
+
125
+ ### Assertions
126
+
127
+ RSpec matchers retry until the page matches or `timeout` runs out:
128
+
129
+ `have_text`, `have_value`, `have_attribute`, `have_css`, `have_xpath`, `have_element`, `have_count`, `have_title`, `have_url`, `be_visible`, `be_hidden`, `be_enabled`, `be_disabled`, `be_checked`
130
+
131
+ ```ruby
132
+ expect { account_page.welcome_message }.to have_text('Welcome')
133
+ expect { driver.find_element(id: 'status').text }.to eq('done') # any value matcher retries in a block
134
+ ```
135
+
136
+ ### Raider reporting
137
+
138
+ Projects include [raider_reporter](https://github.com/RaiderHQ/raider_reporter).
139
+
140
+ - Results go to `raider-results/`.
141
+ - Runs upload to your Raider Hideout server when `RAIDER_TOKEN` and `RAIDER_ENDPOINT` are set.
142
+ - CI runs the suite through `raider-reporter exec` with `RAIDER_QUARANTINE`, so quarantined tests do not fail the build.
143
+ - Set the CI variable `RAIDER_GATE` to `1` to add a `raider-gate` job that fails CI when the Raider quality gate fails.
144
+
145
+ ### Failure video replay
146
+
147
+ Each test is recorded. The video is kept only when the test fails and attached to the report as `video`.
148
+
149
+ - **Web:** WebM built from page screenshots. ffmpeg is downloaded once, SHA-256 checked and cached in `~/.cache/raider`: an LGPL ffmpeg 7.1 build with libvpx for macOS (Apple silicon and Intel), Linux x64 and Windows x64, built by [`.github/workflows/ffmpeg.yml`](.github/workflows/ffmpeg.yml). On other platforms set `RAIDER_FFMPEG_PATH` to an ffmpeg with libvpx.
150
+ - **Mobile:** Appium's own MP4. iOS needs `ffmpeg` on the Appium server host. Android stops at 180 s by default, so it needs no ffmpeg; a longer `video.time_limit` needs ffmpeg too.
151
+ - Turn it off per run with `VIDEO=off`, or per project with `raider u video off`.
152
+
153
+ ### Failure trace replay (web)
154
+
155
+ Failing tests keep a step-by-step trace:
156
+
157
+ - each action with its locator and wait time
158
+ - a screenshot and the page HTML after every step that changes the page
159
+ - network requests and console messages on Chrome, Edge and Firefox
160
+
161
+ It is saved as `raider-results/attachments/<n>-trace.zip`, attached to the report as `trace`, and opens in [Raider Desktop](https://ruby-raider.com) or on Hideout.
162
+
163
+ - `TRACE=on` keeps passing tests too. `TRACE=off` captures nothing. `raider u trace on|off` sets it for the project.
164
+ - Password fields and `RAIDER_SECRET_*` values are hidden. Other typed values, page text and URLs are kept, so treat a trace like the video.
165
+ - Request headers, cookies and bodies are never captured.
166
+
167
+ ### Network mocking (web)
168
+
169
+ Answer a request with your own response, or block it:
170
+
171
+ ```ruby
172
+ mock_request('**/api/users', json: { users: [] })
173
+ mock_request(url, status: 500)
174
+ block_request('**/*.png')
175
+ ```
176
+
177
+ - `mock_request` returns the mock; `mock.calls` lists the requests it answered.
178
+ - Works through WebDriver BiDi on Chrome, Edge and Firefox. Safari and `BIDI=off` raise `NetworkHelper::Unavailable`.
179
+ - Handles CORS for cross-origin mocks, clears mocks after each test, and marks mocked requests in the trace.
180
+
181
+ ### Screenshot comparison (web)
182
+
183
+ ```ruby
184
+ match_screenshot('home')
185
+ ```
186
+
187
+ - Compares the page, or one element with `element:`, with a baseline in `screenshots/baselines/<browser>/`.
188
+ - The first run saves the baseline. Later runs fail on a difference and attach the expected, actual and diff pictures to the report and the trace.
189
+ - `SCREENSHOTS=update` rewrites baselines. A missing baseline fails on CI.
190
+ - Tolerances (`threshold`, `max_diff_pixels`, `max_diff_ratio`) go in `config/config.yml` under `screenshots:`.
191
+ - Generate baselines where CI runs: a Retina laptop makes 2x pictures.
192
+
193
+ ### Login reuse (web)
194
+
195
+ Example projects log in once and restore the saved session for examples tagged `:logged_in`.
196
+
197
+ - `RAIDER_LOGIN_STATE=off|refresh` and `login_state: max_age:` control it.
198
+ - The state stays in git-ignored `.raider/auth/`.
199
+ - Skeletons (`examples:false`) get `SessionState#reuse` to wire your own login.
200
+
201
+ ### Flows: run without assertions (web)
202
+
203
+ A flow is a recorded chore with no checks, such as logging in and downloading a report. It is done when every step ran. Flows are RSpec files under `flows/`, so they use the same driver, locators, waiting, screenshots, video and trace as your tests.
204
+
205
+ ```
206
+ raider flow init # adds flows/flow_helper.rb, flows/support/run.rb and .gitignore lines
207
+ raider flow run timesheet # runs flows/timesheet_flow.rb headless
208
+ raider flow run timesheet --headed --retries 2 --input hours=7
209
+ raider flow list [--json] # each flow and its last result
210
+ ```
211
+
212
+ ```ruby
213
+ # flows/timesheet_flow.rb
214
+ require_relative 'flow_helper'
215
+
216
+ RSpec.describe 'Fill the timesheet' do
217
+ it 'saves the hours' do
218
+ driver.navigate.to 'https://example.com/timesheet'
219
+ driver.find_element(label: 'Hours').send_keys(flow_input('hours', '8'))
220
+ driver.find_element(by_role('button', name: 'Save')).click
221
+ end
222
+ end
223
+ ```
224
+
225
+ - **Exit codes:** 0 completed, 1 a step failed, 2 setup failed (bundle, driver, missing helper), 3 the flow is already running. Each flow holds its own lock in `.raider/flows/`, and a second run exits 3 straight away.
226
+ - **Results:** each run gets its own `flow-results/<name>/<UTC time>/` (report, failure screenshot, video and trace), and `.raider/flows/<name>/runs.jsonl` gains one line: `started_at`, `finished_at`, `status` (`completed`, `failed`, `setup_error`, `busy`), `failed_step`, `attempt`, `trigger`, `results_dir`. The last 20 result folders and 50 lines are kept. Flow runs never touch `raider-results/`, and test runs never touch `flow-results/`.
227
+ - **Inputs:** `flow_input('name', 'default')` reads `--input name=value` (`RAIDER_INPUT_NAME`). Inputs show up in your shell history and process list, so keep secrets out of them.
228
+ - **Secrets:** put them in `.raider/flows/env` as `KEY=value` lines (`#` comments, no interpolation). The file is loaded only when you own it and it has permissions 600 (`chmod 600 .raider/flows/env`); otherwise the run warns and goes on without it. Values are never written to the run log (they are replaced with `[secret]`), but your flow's own output and errors are printed as they are. On Windows there are no permission bits, so the folder's access rules protect the file: keep the project in your user folder.
229
+ - **The same record every way:** `bundle exec rspec flows/timesheet_flow.rb` writes the same run log as `raider flow run`; `raider flow run` adds retries (whole flow, 30 s apart) and the exit codes. Set `RAIDER_FLOW_HEADED=1` to watch a plain rspec run (`headless: true` in `config/config.yml` still wins).
230
+ - Projects made with 4.0 can add flows: `raider flow init` raises the Gemfile's `ruby_raider` pin to `~> 4.1`; run `bundle install` after it.
231
+
232
+ ### Scheduling flows
233
+
234
+ Your computer's own scheduler runs the flow, so nothing needs to stay open. Scheduling never asks for sudo or admin rights.
80
235
 
81
236
  ```bash
82
- raider u start_appium
237
+ raider flow schedule timesheet --every weekday --at 17:30 --input hours=7 --notify
238
+ raider flow schedule backup --every hour --at :15
239
+ raider flow schedule report --every week --on fri --at 09:00 --retries 2
240
+ raider flow unschedule timesheet
241
+ raider flow schedules [--json] # each schedule, its next run, last result and OS state
83
242
  ```
84
243
 
244
+ - **Rules:** `--every hour|day|weekday|week`. `--at HH:MM` (24h, local time) is required for `day`, `weekday` and `week`; for `hour` use `--at :MM` (default `:00`). `--on mon|tue|wed|thu|fri|sat|sun` is required for `week` and refused otherwise. `--retries N` (0 to 3) and `--input name=value` are passed to `raider flow run`. Scheduling a flow again replaces its schedule.
245
+ - **Schedulers:** macOS uses launchd (`~/Library/LaunchAgents/dev.rubyraider.flow.<hash>.<name>.plist`). Windows uses Task Scheduler (a task in the `\RubyRaider\` folder). Linux uses a systemd user timer in `~/.config/systemd/user`, or, when `systemctl --user` does not answer, one tagged line in your crontab. Times are local time (cron uses the system time zone).
246
+ - **Missed runs:** launchd runs a run missed while the Mac slept once on wake. Task Scheduler runs it as soon as it can. systemd (`Persistent=true`) runs it once your user manager is back, at the next boot or login. cron skips it, and `raider flow schedules` says so.
247
+ - **Logged in:** on macOS (a launchd agent in your GUI session) and Windows (a task that runs only while you are logged on) a run happens only while you are logged in.
248
+ - **Linux:** systemd user timers stop when you log out unless lingering is on: `loginctl enable-linger $USER` (raider does not run it). A systemd schedule can only be removed from a session where `systemctl --user` works; until then `unschedule` refuses and keeps the entry.
249
+ - **Per machine:** schedules live in `.raider/flows/schedules.yml`, which `raider flow init` git-ignores, so a fresh clone has none. schedules.yml is the source of truth, and the next run is worked out from the rule. Each OS entry is tied to the project's path: unschedule before you move the project.
250
+ - **States:** `ok`, `missing from launchd` (or `Task Scheduler`, `systemd`, `cron`) when the OS entry is gone, `missing from schedules.yml` when the OS still runs a flow the file does not list, `Ruby not found: re-schedule`, `flow not found: unschedule` when `flows/<name>_flow.rb` was deleted or renamed, and `unknown (...)` when the scheduler could not be asked.
251
+ - **Ruby:** the OS entry runs the absolute `ruby` and `bundle` paths captured when you scheduled, plus `GEM_HOME` and `GEM_PATH` on macOS and Linux. After a Ruby upgrade or move, `schedules` says `Ruby not found: re-schedule`: run `raider flow schedule` again.
252
+ - **Logs:** on macOS and Linux the scheduler's output goes to `.raider/flows/<name>/scheduler.log`. Windows tasks run ruby.exe directly with your user environment and keep no scheduler.log; each run's result is in `runs.jsonl` as always.
253
+ - **Notify:** `--notify` shows a desktop notification only when a run ends failed or could not start (not when it completed, was already running, or was stopped). macOS uses `osascript`, Linux `notify-send`, Windows a PowerShell toast. When a run could not start, the notification points at `.raider/flows/<name>/scheduler.log` for a scheduled run on macOS and Linux, and at the run output otherwise. A notification that can't be shown prints a warning and never changes the exit code. On Linux `notify-send` needs your desktop session bus: under cron, and in a systemd user session that has not imported it, it usually can't show, and only the warning lands in scheduler.log. `raider flow run --notify` does the same for a manual run.
254
+ - **Secrets:** keep them in `.raider/flows/env`, never in `--input`: inputs are stored in plain text in the OS entry and in schedules.yml.
255
+ - **Windows refusals:** Task Scheduler expands `%NAME%` with no way to escape it, so an input or path holding `%...%` is refused. An argument holding both `'` and one of `* ? [ {` is refused too, because ruby.exe would glob it.
256
+ - **Tested on:** macOS (launchd) is tested against the real scheduler. Task Scheduler, systemd and cron are covered by unit tests with a fake scheduler only.
257
+
258
+ ### Also included
259
+
260
+ - **Page Object Model:** base page and component classes with example pages
261
+ - **Example tests:** working tests against the [Raider Test Store](https://raider-test-site.onrender.com/) (web) or the [Raider test app](https://github.com/RaiderHQ/raider_test_app) (mobile), or an empty skeleton with `examples:false` (see [Getting Started](#getting-started))
262
+ - **CI:** GitHub Actions, or Azure Pipelines for web. It caches ffmpeg and comments results on pull requests
263
+ - **Failure screenshots:** each failing test attaches a screenshot to the report
264
+ - **Rake tasks:** default, smoke and regression, filtered by tag
265
+ - **Retries:** RSpec retry, with the count set by `RETRY_COUNT`
266
+ - **Re-run failed tests:** RSpec keeps `spec/examples.txt` for `--only-failures`
267
+ - **Parallel execution:** `parallel_tests` and `parallel_split_test`
268
+ - **Configurable browser:** Chrome or Firefox, with arguments, viewport, timeout and headless mode
269
+ - **Linting:** RuboCop and Reek configs
270
+
85
271
  ## Getting Started
86
272
 
87
273
  Install the gem:
@@ -102,6 +288,12 @@ Or skip the menu with parameters:
102
288
  raider new [project_name] -p framework:rspec automation:selenium
103
289
  ```
104
290
 
291
+ Create a mobile project (`automation:ios`, `automation:android` or `automation:cross_platform`):
292
+
293
+ ```bash
294
+ raider new my_app -p framework:rspec automation:android
295
+ ```
296
+
105
297
  Add accessibility testing:
106
298
 
107
299
  ```bash
@@ -135,11 +327,12 @@ The skeleton keeps the helpers, config, CI and README, and its empty suite passe
135
327
  raider new [PROJECT_NAME] # Create a new framework project
136
328
  raider generate # Access scaffolding commands
137
329
  raider utility # Access utility commands
330
+ raider flow # Run flows: init, run, list, schedule
138
331
  raider version # Show current version
139
332
  raider help [COMMAND] # Describe available commands
140
333
  ```
141
334
 
142
- Shortcuts: `n` (new), `g` (generate), `u` (utility), `v` (version)
335
+ Shortcuts: `n` (new), `g` (generate), `u` (utility), `f` (flow), `v` (version)
143
336
 
144
337
  ### Scaffolding Commands
145
338
 
data/RELEASE.md CHANGED
@@ -2,6 +2,25 @@
2
2
 
3
3
  ## Release Notes
4
4
 
5
+ ### 4.1.0 (unreleased)
6
+
7
+ - Flows: recordings without assertions that run on their own. `raider flow init` adds `flows/flow_helper.rb` and `flows/support/run.rb` to a Selenium web project made with 4.0 or later (and raises a `~> 4.0` Gemfile pin to `~> 4.1`); mobile and 3.x projects are refused with exit 2.
8
+ - `raider flow run NAME` runs `flows/NAME_flow.rb` headless with `bundle exec rspec`, exiting 0 completed, 1 a step failed, 2 setup failed, 3 already running. `--headed`, `--retries N` (0 to 3, whole flow, 30 s apart), `--input name=value` (read with `flow_input`) and `--trigger manual|schedule|desktop`. `--project PATH` works from any folder.
9
+ - Each run takes a per-flow lock, writes its report, screenshot, video and trace to `flow-results/<name>/<UTC time>/` (never cleaned between runs, last 20 kept) and appends one line to `.raider/flows/<name>/runs.jsonl` (last 50 kept). Flow runs never touch `raider-results/`.
10
+ - Secrets for flows go in `.raider/flows/env` (`KEY=value`), loaded only from a file you own with permissions 600 and kept out of the run log.
11
+ - `raider flow list [--json]` shows each flow and its last result. `raider f` is short for `raider flow`.
12
+ - `raider flow schedule NAME --every hour|day|weekday|week [--at HH:MM | :MM] [--on mon..sun] [--retries N] [--input name=value] [--notify]` runs a flow with the computer's own scheduler: launchd on macOS, Task Scheduler (`\RubyRaider\` folder) on Windows, a systemd user timer on Linux, or a crontab line when `systemctl --user` does not answer. No sudo or admin rights. The entry stores the absolute ruby and bundle paths (and `GEM_HOME`/`GEM_PATH` on macOS and Linux) captured when you schedule.
13
+ - `raider flow unschedule NAME` removes the OS entry, then the `.raider/flows/schedules.yml` entry. `raider flow schedules [--json]` lists each schedule with its rule, next run, last result and OS state (`ok`, `missing from <scheduler>`, `missing from schedules.yml`, `Ruby not found: re-schedule`, `unknown`).
14
+ - `--notify` (on `schedule` and on `raider flow run`) shows a desktop notification when a run fails or can not start: osascript on macOS, notify-send on Linux, a PowerShell toast on Windows.
15
+ - Only launchd has been run for real (a scheduled run fired on macOS and was unscheduled cleanly). Task Scheduler, systemd and cron are covered by unit tests only: no real Windows or Linux run before this release.
16
+
17
+ ### 4.0.1
18
+
19
+ - Failure video works for web projects without `RAIDER_FFMPEG_PATH`: the RaiderHQ `ffmpeg-7.1` release is published and `RubyRaider::Ffmpeg::MANIFEST` pins the SHA-256 of its four binaries (macOS arm64 and x64, Linux x64, Windows x64). The first failing test, or `raider u video install`, downloads the one for your platform, checks it and caches it in `~/.cache/raider` (`%LOCALAPPDATA%\raider` on Windows).
20
+ - The binaries are FFmpeg 7.1.5 built from source by `.github/workflows/ffmpeg.yml` (`.github/ffmpeg/build.sh`): LGPL (no `--enable-gpl`, no `--enable-nonfree`), statically linked with libvpx 1.15.2 and zlib 1.3.1, with only the PNG input, scaling, VP8/VP9 encoding and WebM output that the video helper uses. The release carries the license texts, the source tarballs and the exact configure line. macOS binaries are ad-hoc signed, not notarized (`spctl` rejects them). Gatekeeper only checks files carrying the quarantine attribute, which a browser download gets and the gem's Net::HTTP download does not, so the gem's copy runs; a copy downloaded with a browser would be blocked.
21
+ - On other platforms (Linux arm64, for example) `RAIDER_FFMPEG_PATH` is still the way to get web videos; the `[video]` line now says so.
22
+ - Existing 4.0.0 projects need no change beyond `bundle update ruby_raider`.
23
+
5
24
  ### 4.0.0
6
25
 
7
26
  - Watir is removed: `automation:watir` is no longer a valid automation value.
@@ -0,0 +1,104 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'thor'
4
+ require 'json'
5
+ require_relative '../utilities/flows/runner'
6
+ require_relative '../utilities/flows/scheduler'
7
+
8
+ # raider flow: recordings without assertions that run on their own.
9
+ class FlowCommands < Thor
10
+ def self.exit_on_failure? = true
11
+
12
+ class_option :project, type: :string, desc: 'The project folder (default: the current folder)'
13
+
14
+ desc 'init', 'Adds flows/flow_helper.rb and the .gitignore lines to a Selenium web project'
15
+
16
+ def init
17
+ code = project.init
18
+ exit(code) unless code.zero?
19
+ rescue RubyRaider::Flows::Error => e
20
+ stop(e)
21
+ end
22
+
23
+ # `run` is a Thor reserved word, so the method has another name
24
+ desc 'run NAME', 'Runs flows/NAME_flow.rb headless with its own results folder and run log'
25
+ option :headed, type: :boolean, desc: 'Show the browser'
26
+ option :retries, type: :numeric, default: 0, desc: 'Re-run the whole flow up to N times (0-3), 30 s apart'
27
+ option :input, type: :array, desc: 'Flow inputs as name=value (read with flow_input)'
28
+ option :trigger, type: :string, default: 'manual', desc: 'manual, schedule or desktop'
29
+ option :notify, type: :boolean, desc: 'Show a desktop notification when the flow fails'
30
+
31
+ def run_flow(name)
32
+ runner = RubyRaider::Flows::Runner.new(project)
33
+ exit(runner.run(name, headed: options[:headed], retries: options[:retries], inputs: options[:input],
34
+ trigger: options[:trigger], notify: options[:notify] || false))
35
+ rescue RubyRaider::Flows::Error => e
36
+ stop(e)
37
+ end
38
+
39
+ map 'run' => :run_flow
40
+
41
+ desc 'list', 'Lists the flows with their last result'
42
+ option :json, type: :boolean, desc: 'Print JSON for the desktop app'
43
+
44
+ def list
45
+ summaries = RubyRaider::Flows::RunLog.summaries(project)
46
+ return puts(JSON.generate(summaries)) if options[:json]
47
+ return puts('No flows yet: write one in flows/<name>_flow.rb') if summaries.empty?
48
+
49
+ summaries.each { |flow| puts(list_line(flow)) }
50
+ rescue RubyRaider::Flows::Error => e
51
+ stop(e)
52
+ end
53
+
54
+ desc 'schedule NAME', 'Runs a flow on a schedule with the OS scheduler'
55
+ option :every, type: :string, desc: 'hour, day, weekday or week'
56
+ option :at, type: :string, desc: 'HH:MM (24h, local time); for every hour :MM'
57
+ option :on, type: :string, desc: 'mon to sun, for every week'
58
+ option :retries, type: :numeric, default: 0, desc: 'Re-run the whole flow up to N times (0-3)'
59
+ option :input, type: :array, desc: 'Flow inputs as name=value'
60
+ option :notify, type: :boolean, desc: 'Show a desktop notification when a scheduled run fails'
61
+
62
+ def schedule(name)
63
+ scheduler.schedule(name, every: options[:every], at: options[:at], on: options[:on], retries: options[:retries],
64
+ inputs: options[:input] || [], notify: options[:notify] || false)
65
+ rescue RubyRaider::Flows::Error => e
66
+ stop(e)
67
+ end
68
+
69
+ desc 'unschedule NAME', 'Removes the schedule of a flow'
70
+
71
+ def unschedule(name)
72
+ scheduler.unschedule(name)
73
+ rescue RubyRaider::Flows::Error => e
74
+ stop(e)
75
+ end
76
+
77
+ desc 'schedules', 'Lists the scheduled flows with their next run and last result'
78
+ option :json, type: :boolean, desc: 'Print JSON for the desktop app'
79
+
80
+ def schedules
81
+ scheduler.schedules(json: options[:json] || false)
82
+ rescue RubyRaider::Flows::Error => e
83
+ stop(e)
84
+ end
85
+
86
+ no_commands do
87
+ def project
88
+ RubyRaider::Flows::Project.new(options[:project] || Dir.pwd)
89
+ end
90
+
91
+ def scheduler = RubyRaider::Flows::Scheduler.new(project)
92
+
93
+ def list_line(flow)
94
+ last = flow['last']
95
+ result = last ? RubyRaider::Flows.printable("#{last['status']} #{last['finished_at']}") : 'never run'
96
+ "#{flow['name'].ljust(30)} #{result}"
97
+ end
98
+
99
+ def stop(error)
100
+ warn(error.message)
101
+ exit(error.exit_code)
102
+ end
103
+ end
104
+ end
@@ -746,17 +746,16 @@ The video is a `video.webm` built from page screenshots with ffmpeg.
746
746
  `raider u video off` (`raider u video on` turns it back on).
747
747
  <%- end -%>
748
748
  <%- unless mobile? -%>
749
- - ffmpeg is downloaded on first use, checked against a pinned SHA-256 and cached in `~/.cache/raider`
750
- (`%LOCALAPPDATA%\raider` on Windows). `raider u video install` downloads it ahead of time (CI does this before the
749
+ - ffmpeg 7.1 (an LGPL build with libvpx, from the RaiderHQ `ffmpeg-7.1` release) is downloaded on first use,
750
+ checked against a pinned SHA-256 and cached in `~/.cache/raider` (`%LOCALAPPDATA%\raider` on Windows). Builds exist
751
+ for macOS (Apple silicon and Intel), Linux x64 and Windows x64. `raider u video install` downloads it ahead of time (CI does this before the
751
752
  tests and caches the folder), and `raider u video status` prints the binary in use.
752
- - `RAIDER_FFMPEG_PATH` uses your own ffmpeg (it needs libvpx) instead of the download, and `RAIDER_CACHE_DIR` moves
753
- the cache.
753
+ - `RAIDER_FFMPEG_PATH` uses your own ffmpeg (it needs libvpx) instead of the download, for example on Linux arm64,
754
+ and `RAIDER_CACHE_DIR` moves the cache.
754
755
  <%- if azure? -%>
755
756
  - `azure-pipelines.yml` sets `RAIDER_CACHE_DIR` to `$(Pipeline.Workspace)/.cache/raider`, the folder its `Cache@2`
756
757
  step keeps between runs.
757
758
  <%- end -%>
758
- - The RaiderHQ `ffmpeg-7.1` release that the download comes from is not published yet. Until it is, set
759
- `RAIDER_FFMPEG_PATH` to get videos; without it the suite runs as usual and prints one `[video]` line.
760
759
  - If ffmpeg is missing or recording fails, the suite still runs and its exit code is unchanged; you get one `[video]`
761
760
  line on stderr and no video.
762
761
  - Known limits: a frame is taken after each page load, click and text change, plus one at the end of a failing test,
@@ -777,7 +776,7 @@ The video is a `video.webm` built from page screenshots with ffmpeg.
777
776
  than 180 s needs ffmpeg on the Appium host.
778
777
  - `raider u video install` and `raider u video status` manage the ffmpeg that web projects use, cached in
779
778
  `~/.cache/raider` (override with `RAIDER_FFMPEG_PATH` or `RAIDER_CACHE_DIR`); they do not install ffmpeg on the
780
- Appium host. The RaiderHQ `ffmpeg-7.1` release it comes from is not published yet.
779
+ Appium host.
781
780
  - If recording fails, the suite still runs and its exit code is unchanged; you get one `[video]` line on stderr and
782
781
  no video.
783
782
  <%- end -%>
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Every flow (flows/<name>_flow.rb) requires this file. A flow is an RSpec file without assertions:
4
+ # it completes when every step ran. Run one with `raider flow run <name>`, or `bundle exec rspec flows/<name>_flow.rb`.
5
+ # Generated by `raider flow init`.
6
+
7
+ require_relative 'support/run'
8
+
9
+ # Before the driver starts: take the flow's lock, pick its results folder, load .raider/flows/env, go headless.
10
+ # The report goes to this run's folder even when start! refuses the run, so a flow never cleans raider-results.
11
+ begin
12
+ RaiderFlows::Run.start!
13
+ ensure
14
+ RaiderFlows::Run.configure_reporter
15
+ end
16
+
17
+ require_relative '../helpers/spec_helper'
18
+
19
+ # Helpers available inside a flow.
20
+ module FlowHelper
21
+ # A value passed with `raider flow run <name> --input name=value`, or the recorded default.
22
+ def flow_input(name, default = nil)
23
+ key = name.to_s
24
+ raise ArgumentError, "invalid flow input name #{key.inspect}" unless RaiderFlows::Run::INPUT.match?(key)
25
+
26
+ ENV.fetch("RAIDER_INPUT_#{key.upcase}", default)
27
+ end
28
+ end
29
+
30
+ # Again now that spec_helper is surely loaded
31
+ RaiderFlows::Run.configure_reporter
32
+
33
+ RSpec.configure do |config|
34
+ config.include(FlowHelper)
35
+ # Flows don't touch spec/examples.txt, so `rspec --only-failures` stays about tests
36
+ config.example_status_persistence_file_path = nil
37
+ # A flow is not idempotent mid-way: never re-run it from step 1 inside one run (raider flow run --retries re-runs it whole)
38
+ config.default_retry_count = 0 if config.respond_to?(:default_retry_count=)
39
+ config.define_derived_metadata(file_path: %r{/flows/[^/]+_flow\.rb\z}) { |metadata| metadata[:flow] = true }
40
+ # Runs after spec_helper's hooks started the browser: a failure before this is a setup error, not a step
41
+ config.append_before(:each) { RaiderFlows::Run.steps_started! }
42
+ end