playwright-on-rails 0.7.1
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 +7 -0
- data/.github/workflows/main.yml +21 -0
- data/.gitignore +8 -0
- data/.standard.yml +5 -0
- data/.travis.yml +7 -0
- data/CHANGELOG.md +115 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +155 -0
- data/LICENSE.txt +25 -0
- data/README.md +241 -0
- data/Rakefile +11 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/exe/playwright-on-rails +17 -0
- data/lib/playwright-on-rails/config.rb +41 -0
- data/lib/playwright-on-rails/env.rb +14 -0
- data/lib/playwright-on-rails/finds_bin.rb +16 -0
- data/lib/playwright-on-rails/init.rb +93 -0
- data/lib/playwright-on-rails/initializer_hooks.rb +53 -0
- data/lib/playwright-on-rails/launches_playwright.rb +63 -0
- data/lib/playwright-on-rails/manages_transactions.rb +78 -0
- data/lib/playwright-on-rails/open.rb +14 -0
- data/lib/playwright-on-rails/railtie.rb +12 -0
- data/lib/playwright-on-rails/rake.rb +18 -0
- data/lib/playwright-on-rails/resets_state.rb +20 -0
- data/lib/playwright-on-rails/run.rb +14 -0
- data/lib/playwright-on-rails/server/checker.rb +42 -0
- data/lib/playwright-on-rails/server/middleware.rb +67 -0
- data/lib/playwright-on-rails/server/puma.rb +31 -0
- data/lib/playwright-on-rails/server/timer.rb +24 -0
- data/lib/playwright-on-rails/server.rb +121 -0
- data/lib/playwright-on-rails/starts_rails_server.rb +34 -0
- data/lib/playwright-on-rails/tracks_resets.rb +26 -0
- data/lib/playwright-on-rails/version.rb +3 -0
- data/lib/playwright-on-rails.rb +11 -0
- data/playwright_rails.gemspec +32 -0
- data/script/test +21 -0
- data/script/test_example_app +21 -0
- metadata +166 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4c645ee1541e81fa978f7119b904a694f25e762c7a969ac3a3a4c0cd357f2d07
|
4
|
+
data.tar.gz: 516fb66ff81bae53fdae42429843d4728b25624e6a19215a208dad3d4293da35
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 11e29411f55d355d4389ce5b7b3f6bd7c96b3719dc54249260c867f167df7c888bcb4cc00a855ced8d1e4c754258a3fc5daf216f7ea22d7add2d7882885e2c69
|
7
|
+
data.tar.gz: 751d9e0631f4ec11a7ec327dbc48ad9aaa26fddcfa937e7ea4af8aff47b3bccd1ad8dcaf4cae696ad8a2ec9e0171199d5b0154a33fa5a93f5110b2dfc23cb7c9
|
@@ -0,0 +1,21 @@
|
|
1
|
+
name: CI
|
2
|
+
|
3
|
+
on: [push, pull_request, workflow_dispatch]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
build:
|
7
|
+
runs-on: ubuntu-latest
|
8
|
+
|
9
|
+
strategy:
|
10
|
+
matrix:
|
11
|
+
ruby-version: ['3.0', '3.3']
|
12
|
+
|
13
|
+
steps:
|
14
|
+
- uses: actions/checkout@v2
|
15
|
+
- uses: ruby/setup-ruby@v1
|
16
|
+
with:
|
17
|
+
ruby-version: ${{ matrix.ruby-version }}
|
18
|
+
bundler-cache: true
|
19
|
+
|
20
|
+
- name: Run tests
|
21
|
+
run: ./script/test
|
data/.gitignore
ADDED
data/.standard.yml
ADDED
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
# CHANGELOG
|
2
|
+
|
3
|
+
## 0.7.0
|
4
|
+
git
|
5
|
+
* Add a `CYPRESS_RAILS_CYPRESS_DIR` option for cases where
|
6
|
+
the cypress tests live outside the CYPRESS_RAILS_DIR [#159](https://github.com/testdouble/cypress-rails/pull/159)
|
7
|
+
|
8
|
+
## 0.6.1
|
9
|
+
|
10
|
+
* Fix a deprecation warning in Rails
|
11
|
+
[#157](https://github.com/testdouble/cypress-rails/pull/157)
|
12
|
+
|
13
|
+
## 0.6.0
|
14
|
+
|
15
|
+
* Update initializer task to generate valid Cypress v10+ configurations
|
16
|
+
[#156](https://github.com/testdouble/cypress-rails/pull/156)
|
17
|
+
|
18
|
+
## 0.5.5
|
19
|
+
|
20
|
+
* Add Puma 6 support
|
21
|
+
[#136](https://github.com/testdouble/cypress-rails/pull/136)
|
22
|
+
|
23
|
+
## 0.5.4
|
24
|
+
|
25
|
+
* Fix Rails 5 support
|
26
|
+
[#126](https://github.com/testdouble/cypress-rails/pull/126)
|
27
|
+
|
28
|
+
## 0.5.3
|
29
|
+
|
30
|
+
* Fix 2.5 & 2.6 compatibility
|
31
|
+
[#100](https://github.com/testdouble/cypress-rails/issues/100)
|
32
|
+
|
33
|
+
## 0.5.2
|
34
|
+
|
35
|
+
* Fixes a puma deprecation warning
|
36
|
+
[#95](https://github.com/testdouble/cypress-rails/pull/95)
|
37
|
+
|
38
|
+
## 0.5.1
|
39
|
+
|
40
|
+
* Sprinkles two instance variables to the custom transaction manager that cribs
|
41
|
+
its implementation from ActiveRecord::TestFixtures (see f75f280)
|
42
|
+
[#88](https://github.com/testdouble/cypress-rails/issues/88)
|
43
|
+
[#89](https://github.com/testdouble/cypress-rails/pull/89)
|
44
|
+
|
45
|
+
## 0.5.0
|
46
|
+
|
47
|
+
* Add hook `after_server_start`
|
48
|
+
[#63](https://github.com/testdouble/cypress-rails/pull/63)
|
49
|
+
* Fix namespace bug
|
50
|
+
[#64](https://github.com/testdouble/cypress-rails/pull/64)
|
51
|
+
|
52
|
+
## 0.4.2
|
53
|
+
|
54
|
+
* Add support to Rails 6.1 ([#52](https://github.com/testdouble/cypress-rails/issue/52))
|
55
|
+
|
56
|
+
## 0.4.1
|
57
|
+
|
58
|
+
* Add backcompat for Ruby 2.4
|
59
|
+
([#47](https://github.com/testdouble/cypress-rails/pull/47))
|
60
|
+
|
61
|
+
## 0.4.0
|
62
|
+
|
63
|
+
* Add a `CYPRESS_RAILS_HOST` option that allows a hostname to be specified (as
|
64
|
+
opposed to 127.0.0.1). Puma will still bind to 127.0.0.1, but Cypress will use
|
65
|
+
the hostname in its `baseUrl`, which may be necessary for some folks' tests to
|
66
|
+
work
|
67
|
+
|
68
|
+
## 0.3.0
|
69
|
+
|
70
|
+
* Add a `CYPRESS_RAILS_BASE_PATH` option which will be appended to the
|
71
|
+
`CYPRESS_BASE_URL` option that cypress-rails sets when launching cypress
|
72
|
+
commands. Apps that set `baseUrl` to something other than "/" can set this env
|
73
|
+
var to match for consistent behavior (or else set it using Cypress.config in a
|
74
|
+
support file)
|
75
|
+
|
76
|
+
## 0.2.0
|
77
|
+
|
78
|
+
* If `RAILS_ENV` has been explicitly set when the CLI or rake task is run,
|
79
|
+
respect that set value instead of overriding it to "test"
|
80
|
+
|
81
|
+
## 0.1.3
|
82
|
+
|
83
|
+
* Improve behavior of SIGINT (Ctrl-C) so a traceback isn't printed and stdout
|
84
|
+
isn't flushed after the program exits
|
85
|
+
|
86
|
+
## 0.1.2
|
87
|
+
|
88
|
+
* Drop the hard deps on capybara and selenium-webdrivers (instead inlining
|
89
|
+
portions of the Capybara server logic). Additionally, add a hard dep on puma
|
90
|
+
since this gem is useless without it
|
91
|
+
|
92
|
+
## 0.1.1
|
93
|
+
|
94
|
+
* Fix the `before_server_stop` hook by rolling back transactions first so that
|
95
|
+
it can clean out test data
|
96
|
+
|
97
|
+
## 0.1.0
|
98
|
+
|
99
|
+
* **[Breaking]** Remove `CypressRails::TestCase`. Use `rake cypress:run` instead
|
100
|
+
* **[Breaking]** cypress-rails now starts a transaction immediately after
|
101
|
+
launching the server, which could result in other processes not being able
|
102
|
+
to observe your changes. To revert to the old behavior, set the env var
|
103
|
+
`CYPRESS_RAILS_TRANSACTIONAL_SERVER=false`
|
104
|
+
* Add configuration variables `CYPRESS_RAILS_DIR`,
|
105
|
+
`CYPRESS_RAILS_TRANSACTIONAL_SERVER`. Rename port and Cypress CLI forwarding
|
106
|
+
to `CYPRESS_RAILS_PORT` and `CYPRESS_RAILS_CYPRESS_OPTS`
|
107
|
+
* Add test data configuration hooks (to be run in an initializer):
|
108
|
+
* `CypressRails.hooks.before_server_start`
|
109
|
+
* `CypressRails.hooks.after_transaction_start`
|
110
|
+
* `CypressRails.hooks.after_state_reset` - after a transaction rollback
|
111
|
+
* `CypressRails.hooks.before_server_stop` - called in an `at_exit` hook
|
112
|
+
|
113
|
+
## 0.0.4
|
114
|
+
|
115
|
+
* Started a changelog
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,155 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
playwright-on-rails (0.7.0)
|
5
|
+
puma (>= 3.8.0)
|
6
|
+
railties (>= 5.2.0)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
actionpack (7.1.3)
|
12
|
+
actionview (= 7.1.3)
|
13
|
+
activesupport (= 7.1.3)
|
14
|
+
nokogiri (>= 1.8.5)
|
15
|
+
racc
|
16
|
+
rack (>= 2.2.4)
|
17
|
+
rack-session (>= 1.0.1)
|
18
|
+
rack-test (>= 0.6.3)
|
19
|
+
rails-dom-testing (~> 2.2)
|
20
|
+
rails-html-sanitizer (~> 1.6)
|
21
|
+
actionview (7.1.3)
|
22
|
+
activesupport (= 7.1.3)
|
23
|
+
builder (~> 3.1)
|
24
|
+
erubi (~> 1.11)
|
25
|
+
rails-dom-testing (~> 2.2)
|
26
|
+
rails-html-sanitizer (~> 1.6)
|
27
|
+
activesupport (7.1.3)
|
28
|
+
base64
|
29
|
+
bigdecimal
|
30
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
31
|
+
connection_pool (>= 2.2.5)
|
32
|
+
drb
|
33
|
+
i18n (>= 1.6, < 2)
|
34
|
+
minitest (>= 5.1)
|
35
|
+
mutex_m
|
36
|
+
tzinfo (~> 2.0)
|
37
|
+
ast (2.4.2)
|
38
|
+
base64 (0.2.0)
|
39
|
+
bigdecimal (3.1.6)
|
40
|
+
builder (3.2.4)
|
41
|
+
concurrent-ruby (1.2.3)
|
42
|
+
connection_pool (2.4.1)
|
43
|
+
crass (1.0.6)
|
44
|
+
drb (2.2.0)
|
45
|
+
ruby2_keywords
|
46
|
+
erubi (1.12.0)
|
47
|
+
i18n (1.14.1)
|
48
|
+
concurrent-ruby (~> 1.0)
|
49
|
+
io-console (0.7.2)
|
50
|
+
irb (1.11.2)
|
51
|
+
rdoc
|
52
|
+
reline (>= 0.4.2)
|
53
|
+
json (2.7.1)
|
54
|
+
language_server-protocol (3.17.0.3)
|
55
|
+
lint_roller (1.1.0)
|
56
|
+
loofah (2.22.0)
|
57
|
+
crass (~> 1.0.2)
|
58
|
+
nokogiri (>= 1.12.0)
|
59
|
+
mini_portile2 (2.8.5)
|
60
|
+
minitest (5.22.2)
|
61
|
+
mutex_m (0.2.0)
|
62
|
+
nio4r (2.7.0)
|
63
|
+
nokogiri (1.16.2)
|
64
|
+
mini_portile2 (~> 2.8.2)
|
65
|
+
racc (~> 1.4)
|
66
|
+
parallel (1.24.0)
|
67
|
+
parser (3.3.0.5)
|
68
|
+
ast (~> 2.4.1)
|
69
|
+
racc
|
70
|
+
psych (5.1.2)
|
71
|
+
stringio
|
72
|
+
puma (6.4.2)
|
73
|
+
nio4r (~> 2.0)
|
74
|
+
racc (1.7.3)
|
75
|
+
rack (3.0.9)
|
76
|
+
rack-session (2.0.0)
|
77
|
+
rack (>= 3.0.0)
|
78
|
+
rack-test (2.1.0)
|
79
|
+
rack (>= 1.3)
|
80
|
+
rackup (2.1.0)
|
81
|
+
rack (>= 3)
|
82
|
+
webrick (~> 1.8)
|
83
|
+
rails-dom-testing (2.2.0)
|
84
|
+
activesupport (>= 5.0.0)
|
85
|
+
minitest
|
86
|
+
nokogiri (>= 1.6)
|
87
|
+
rails-html-sanitizer (1.6.0)
|
88
|
+
loofah (~> 2.21)
|
89
|
+
nokogiri (~> 1.14)
|
90
|
+
railties (7.1.3)
|
91
|
+
actionpack (= 7.1.3)
|
92
|
+
activesupport (= 7.1.3)
|
93
|
+
irb
|
94
|
+
rackup (>= 1.0.0)
|
95
|
+
rake (>= 12.2)
|
96
|
+
thor (~> 1.0, >= 1.2.2)
|
97
|
+
zeitwerk (~> 2.6)
|
98
|
+
rainbow (3.1.1)
|
99
|
+
rake (13.1.0)
|
100
|
+
rdoc (6.6.2)
|
101
|
+
psych (>= 4.0.0)
|
102
|
+
regexp_parser (2.9.0)
|
103
|
+
reline (0.4.2)
|
104
|
+
io-console (~> 0.5)
|
105
|
+
rexml (3.2.6)
|
106
|
+
rubocop (1.59.0)
|
107
|
+
json (~> 2.3)
|
108
|
+
language_server-protocol (>= 3.17.0)
|
109
|
+
parallel (~> 1.10)
|
110
|
+
parser (>= 3.2.2.4)
|
111
|
+
rainbow (>= 2.2.2, < 4.0)
|
112
|
+
regexp_parser (>= 1.8, < 3.0)
|
113
|
+
rexml (>= 3.2.5, < 4.0)
|
114
|
+
rubocop-ast (>= 1.30.0, < 2.0)
|
115
|
+
ruby-progressbar (~> 1.7)
|
116
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
117
|
+
rubocop-ast (1.30.0)
|
118
|
+
parser (>= 3.2.1.0)
|
119
|
+
rubocop-performance (1.20.2)
|
120
|
+
rubocop (>= 1.48.1, < 2.0)
|
121
|
+
rubocop-ast (>= 1.30.0, < 2.0)
|
122
|
+
ruby-progressbar (1.13.0)
|
123
|
+
ruby2_keywords (0.0.5)
|
124
|
+
standard (1.33.0)
|
125
|
+
language_server-protocol (~> 3.17.0.2)
|
126
|
+
lint_roller (~> 1.0)
|
127
|
+
rubocop (~> 1.59.0)
|
128
|
+
standard-custom (~> 1.0.0)
|
129
|
+
standard-performance (~> 1.3)
|
130
|
+
standard-custom (1.0.2)
|
131
|
+
lint_roller (~> 1.0)
|
132
|
+
rubocop (~> 1.50)
|
133
|
+
standard-performance (1.3.1)
|
134
|
+
lint_roller (~> 1.1)
|
135
|
+
rubocop-performance (~> 1.20.2)
|
136
|
+
stringio (3.1.0)
|
137
|
+
thor (1.3.0)
|
138
|
+
tzinfo (2.0.6)
|
139
|
+
concurrent-ruby (~> 1.0)
|
140
|
+
unicode-display_width (2.5.0)
|
141
|
+
webrick (1.8.1)
|
142
|
+
zeitwerk (2.6.13)
|
143
|
+
|
144
|
+
PLATFORMS
|
145
|
+
ruby
|
146
|
+
|
147
|
+
DEPENDENCIES
|
148
|
+
bundler
|
149
|
+
minitest (~> 5.0)
|
150
|
+
playwright-on-rails!
|
151
|
+
rake (~> 13.0)
|
152
|
+
standard (>= 0.2.0)
|
153
|
+
|
154
|
+
BUNDLED WITH
|
155
|
+
2.3.13
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019-2020 Test Double, LLC
|
4
|
+
|
5
|
+
Portions of the CypressRails::Server component:
|
6
|
+
Copyright (c) 2009-2018 Thomas Walpole, Jonas Nicklas
|
7
|
+
|
8
|
+
|
9
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
10
|
+
of this software and associated documentation files (the "Software"), to deal
|
11
|
+
in the Software without restriction, including without limitation the rights
|
12
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
13
|
+
copies of the Software, and to permit persons to whom the Software is
|
14
|
+
furnished to do so, subject to the following conditions:
|
15
|
+
|
16
|
+
The above copyright notice and this permission notice shall be included in
|
17
|
+
all copies or substantial portions of the Software.
|
18
|
+
|
19
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
20
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
21
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
22
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
23
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
24
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
25
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,241 @@
|
|
1
|
+
# playwright-on-rails
|
2
|
+
|
3
|
+
**This is a downstream copy of [cypress-rails](https://github.com/testdouble/cypress-rails), adapted to support Playwright instead of [Cypress](http://cypress.io). All credit goes to [them](https://github.com/testdouble/cypress-rails). Changes here will be kept at a minimum, and suggestions should probably be sent to that project.**
|
4
|
+
|
5
|
+
This is a simple gem to make it easier to start writing browser tests with
|
6
|
+
[Playwright](https://playwright.dev/) for your [Rails](https://rubyonrails.org) apps,
|
7
|
+
regardless of whether your app is server-side rendered HTML, completely
|
8
|
+
client-side JavaScript, or something in-between.
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
**tl;dr**:
|
13
|
+
|
14
|
+
1. Install the npm package `playwright`
|
15
|
+
2. Install this gem `playwright-on-rails`
|
16
|
+
3. Run `rake playwright:init`
|
17
|
+
|
18
|
+
### Installing Playwright itself
|
19
|
+
|
20
|
+
The first step is making sure Playwright is installed (that's up to you, this
|
21
|
+
library doesn't install Playwright, it just provides a little Rails-specific glue).
|
22
|
+
|
23
|
+
If you're on newer versions of Rails and using
|
24
|
+
[webpacker](https://www.github.com/rails/webpacker) for your front-end assets,
|
25
|
+
then you're likely already using yarn to manage your JavaScript dependencies. If
|
26
|
+
that's the case, you can add Playwright with:
|
27
|
+
|
28
|
+
```sh
|
29
|
+
$ yarn add --dev playwright
|
30
|
+
```
|
31
|
+
|
32
|
+
If you're not using yarn in conjunction with your Rails app, check out the
|
33
|
+
Playwright docs on getting it installed. At the end of the day, this gem just needs
|
34
|
+
the `playwright` binary to exist either in `./node_modules/.bin/playwright` or on your
|
35
|
+
`PATH`.
|
36
|
+
|
37
|
+
### Installing the playwright-on-rails gem
|
38
|
+
|
39
|
+
Now, to install the playwright-on-rails gem, you'll want to add it to your development
|
40
|
+
& test gem groups of your Gemfile, so that you have easy access to its rake
|
41
|
+
tasks:
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
group :development, :test do
|
45
|
+
gem "playwright-on-rails"
|
46
|
+
end
|
47
|
+
```
|
48
|
+
|
49
|
+
Once installed, you'll want to run:
|
50
|
+
|
51
|
+
```sh
|
52
|
+
$ rake playwright:init
|
53
|
+
```
|
54
|
+
|
55
|
+
This will override a few configurations in your `playwright.config.js` configuration
|
56
|
+
file.
|
57
|
+
|
58
|
+
## Usage
|
59
|
+
|
60
|
+
### Develop tests interactively with `playwright open`
|
61
|
+
|
62
|
+
When writing tests with Playwright, you'll find the most pleasant experience (by
|
63
|
+
way of a faster feedback loop and an interactive, easy-to-inspect test runner)
|
64
|
+
using the `playwright open` command.
|
65
|
+
|
66
|
+
When using Rails, however, you'll also want your Rails test server to be running
|
67
|
+
so that there's something for Playwright to interact with. `playwright-on-rails` provides
|
68
|
+
a wrapper for running `playwright open` with a dedicated Rails test server.
|
69
|
+
|
70
|
+
So, by running:
|
71
|
+
|
72
|
+
```sh
|
73
|
+
$ rake playwright:open
|
74
|
+
```
|
75
|
+
|
76
|
+
Any JavaScript files added to `playwright/tests` will be identified by
|
77
|
+
Playwright as tests. Simply click a test file in the Playwright application window to
|
78
|
+
launch the test in a browser. Each time you save the test file, it will re-run
|
79
|
+
itself.
|
80
|
+
|
81
|
+
### Run tests headlessly with `playwright run`
|
82
|
+
|
83
|
+
To run your tests headlessly (e.g. when you're in CI), you'll want the `run`
|
84
|
+
command:
|
85
|
+
|
86
|
+
```sh
|
87
|
+
$ rake playwright:run
|
88
|
+
```
|
89
|
+
|
90
|
+
## Managing your test data
|
91
|
+
|
92
|
+
The tricky thing about browser tests is that they usually depend on some test
|
93
|
+
data being available with which to exercise the app efficiently. Because playwright
|
94
|
+
is a JavaScript-based tool and can't easily manipulate your Rails app directly,
|
95
|
+
playwright-on-rails provides a number of hooks that you can use to manage your test
|
96
|
+
data.
|
97
|
+
|
98
|
+
Here's what a `config/initializers/playwright-on-rails.rb` initializer might look
|
99
|
+
like:
|
100
|
+
|
101
|
+
```ruby
|
102
|
+
return unless Rails.env.test?
|
103
|
+
|
104
|
+
PlaywrightOnRails.hooks.before_server_start do
|
105
|
+
# Called once, before either the transaction or the server is started
|
106
|
+
end
|
107
|
+
|
108
|
+
PlaywrightOnRails.hooks.after_transaction_start do
|
109
|
+
# Called after the transaction is started (at launch and after each reset)
|
110
|
+
end
|
111
|
+
|
112
|
+
PlaywrightOnRails.hooks.after_state_reset do
|
113
|
+
# Triggered after `/playwright-on-rails_reset_state` is called
|
114
|
+
end
|
115
|
+
|
116
|
+
PlaywrightOnRails.hooks.before_server_stop do
|
117
|
+
# Called once, at_exit
|
118
|
+
end
|
119
|
+
```
|
120
|
+
|
121
|
+
(You can find [an example initializer](/example/config/initializers/playwright-on-rails_initializer.rb)
|
122
|
+
in this repo.)
|
123
|
+
|
124
|
+
The gem also provides a special route on the test server:
|
125
|
+
`/playwright-on-rails_reset_state`. Each time it's called, playwright-on-rails will do
|
126
|
+
two things at the beginning of the next request received by the Rails app:
|
127
|
+
|
128
|
+
* If `PLAYWRIGHT_RAILS_TRANSACTIONAL_SERVER` is enabled, roll back the transaction,
|
129
|
+
effectively resetting the application state to whatever it was at the start of
|
130
|
+
the test run
|
131
|
+
|
132
|
+
* Trigger any `after_state_reset` hooks you've configured (regardless of the
|
133
|
+
transactional server setting)
|
134
|
+
|
135
|
+
This way, you can easily instruct the server to reset its test state from your
|
136
|
+
Playwright tests like so:
|
137
|
+
|
138
|
+
```js
|
139
|
+
beforeEach(() => {
|
140
|
+
cy.request('/playwright-on-rails_reset_state')
|
141
|
+
})
|
142
|
+
```
|
143
|
+
|
144
|
+
(Remember, in Playwright, `before` is a before-all hook and `beforeEach` is run
|
145
|
+
between each test case!)
|
146
|
+
|
147
|
+
## Configuration
|
148
|
+
|
149
|
+
### Environment variables
|
150
|
+
|
151
|
+
The playwright-on-rails gem is configured entirely via environment variables. If you
|
152
|
+
find yourself repeating a number of verbose environment variables as you run
|
153
|
+
your tests, consider invoking the gem from a custom script or setting your
|
154
|
+
preferred environment variables project-wide using a tool like
|
155
|
+
[dotenv](https://github.com/bkeepers/dotenv).
|
156
|
+
|
157
|
+
|
158
|
+
* **PLAYWRIGHT_RAILS_DIR** (default: `Dir.pwd`) the directory of your Rails project
|
159
|
+
* **PLAYWRIGHT_RAILS_PLAYWRIGHT_DIR** (default: _same value as `rails_dir`_) the directory of your Playwright project
|
160
|
+
* **PLAYWRIGHT_RAILS_HOST** (default: `"127.0.0.1"`) the hostname to bind to
|
161
|
+
* **PLAYWRIGHT_RAILS_PORT** (default: _a random available port_) the port to run
|
162
|
+
the Rails test server on
|
163
|
+
* **PLAYWRIGHT_RAILS_BASE_PATH** (default: `"/"`) the base path for all Playwright's
|
164
|
+
requests to the app (e.g. via `cy.visit()`). If you've customized your
|
165
|
+
`baseUrl` setting (e.g. in `playwright.config.js`), you'll need to duplicate it with
|
166
|
+
this environment variable
|
167
|
+
* **PLAYWRIGHT_RAILS_TRANSACTIONAL_SERVER** (default: `true`) when true, will start
|
168
|
+
a transaction on all database connections before launching the server. In
|
169
|
+
general this means anything done during `playwright open` or `playwright run` will
|
170
|
+
be rolled back on exit (similar to running a Rails System test)
|
171
|
+
* **PLAYWRIGHT_RAILS_PLAYWRIGHT_OPTS** (default: _none_) any options you want to
|
172
|
+
forward to the Playwright CLI when running its `open` or `run` commands.
|
173
|
+
|
174
|
+
#### Example: Running a single spec from the command line
|
175
|
+
|
176
|
+
It's a little verbose, but an example of using the above options to run a single
|
177
|
+
Playwright test would look like this:
|
178
|
+
|
179
|
+
```
|
180
|
+
$ PLAYWRIGHT_RAILS_PLAYWRIGHT_OPTS="playwright/integration/a_test.js" bin/rake playwright:run
|
181
|
+
```
|
182
|
+
|
183
|
+
### Initializer hooks
|
184
|
+
|
185
|
+
### before_server_start
|
186
|
+
|
187
|
+
Pass a block to `PlaywrightOnRails.hooks.before_server_start` to register a hook that
|
188
|
+
will execute before the server or any transaction has been started. If you use
|
189
|
+
Rails fixtures, it may make sense to load them here, so they don't need to be
|
190
|
+
re-inserted for each request
|
191
|
+
|
192
|
+
### after_server_start
|
193
|
+
|
194
|
+
Pass a block to `PlaywrightOnRails.hooks.after_server_start` to register a hook that
|
195
|
+
will execute after the server has booted.
|
196
|
+
|
197
|
+
### after_transaction_start
|
198
|
+
|
199
|
+
If there's any custom behavior or state management you want to do inside the
|
200
|
+
transaction (so that it's also rolled back each time a reset is triggered),
|
201
|
+
pass a block to `PlaywrightOnRails.hooks.after_transaction_start`.
|
202
|
+
|
203
|
+
### after_state_reset
|
204
|
+
|
205
|
+
Every time the test server receives an HTTP request at
|
206
|
+
`/playwright-on-rails_reset_state`, the transaction will be rolled back (if
|
207
|
+
`PLAYWRIGHT_RAILS_TRANSACTIONAL_SERVER` is enabled) and the `after_state_reset`
|
208
|
+
hook will be triggered. To set up the hook, pass a block to
|
209
|
+
`PlaywrightOnRails.hooks.after_state_reset`.
|
210
|
+
|
211
|
+
### before_server_stop
|
212
|
+
|
213
|
+
In case you've made any permanent changes to your test database that could
|
214
|
+
pollute other test suites or scripts, you can use the `before_server_stop` to
|
215
|
+
(assuming everything exits gracefully) clean things up and restore the state
|
216
|
+
of your test database. To set up the hook, pass a block to
|
217
|
+
`PlaywrightOnRails.hooks.before_server_stop`.
|
218
|
+
|
219
|
+
## Configuring Rails
|
220
|
+
|
221
|
+
Beyond the configuration options above, you'll probably also want to disable caching
|
222
|
+
in your Rails app's [config/environments/test.rb](/example/config/environments/test.rb#L9)
|
223
|
+
file, so that changes to your Ruby code are reflected in your tests while you
|
224
|
+
work on them with `rake playwright:open`. (If either option is set to
|
225
|
+
`true`, any changes to your Ruby code will require a server restart to be reflected as you work
|
226
|
+
on your tests.)
|
227
|
+
|
228
|
+
To illustrate, here's what that might look like in `config/environments/test.rb`:
|
229
|
+
|
230
|
+
```ruby
|
231
|
+
config.cache_classes = false
|
232
|
+
config.action_view.cache_template_loading = false
|
233
|
+
```
|
234
|
+
|
235
|
+
## Setting up continuous integration
|
236
|
+
|
237
|
+
See [original](https://github.com/testdouble/cypress-rails/tree/main?tab=readme-ov-file#setting-up-continuous-integration).
|
238
|
+
|
239
|
+
## Why use this?
|
240
|
+
|
241
|
+
See [original](https://github.com/testdouble/cypress-rails/tree/main?tab=readme-ov-file#why-use-this).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "playwright-on-rails"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
ENV["RAILS_ENV"] ||= "test"
|
4
|
+
require "pathname"
|
5
|
+
require "playwright-on-rails"
|
6
|
+
require Pathname.new(PlaywrightOnRails::Config.new.rails_dir).join("config/environment")
|
7
|
+
|
8
|
+
command = ARGV[0]
|
9
|
+
case command
|
10
|
+
when "init"
|
11
|
+
PlaywrightOnRails::Init.new.call
|
12
|
+
when "open"
|
13
|
+
PlaywrightOnRails::Open.new.call
|
14
|
+
when "run"
|
15
|
+
passed = PlaywrightOnRails::Run.new.call
|
16
|
+
exit 1 unless passed
|
17
|
+
end
|