cypress-on-rails 1.13.1 → 1.15.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +8 -2
- data/CHANGELOG.md +19 -1
- data/README.md +156 -72
- data/docs/authentication.md +12 -10
- data/docs/factory_bot_associations.md +11 -11
- data/lib/cypress_on_rails/command_executor.rb +9 -5
- data/lib/cypress_on_rails/configuration.rb +14 -2
- data/lib/cypress_on_rails/middleware.rb +8 -5
- data/lib/cypress_on_rails/vcr_middleware.rb +3 -3
- data/lib/cypress_on_rails/version.rb +1 -1
- data/lib/generators/cypress_on_rails/install_generator.rb +44 -20
- data/lib/generators/cypress_on_rails/templates/config/initializers/cypress_on_rails.rb.erb +2 -1
- data/lib/generators/cypress_on_rails/templates/spec/cypress/e2e/rails_examples/advance_factory_bot.cy.js +1 -1
- data/lib/generators/cypress_on_rails/templates/spec/cypress/e2e/rails_examples/other.cy.js +1 -1
- data/lib/generators/cypress_on_rails/templates/spec/cypress/e2e/rails_examples/using_factory_bot.cy.js +1 -1
- data/lib/generators/cypress_on_rails/templates/spec/cypress/e2e/rails_examples/using_fixtures.cy.js +1 -1
- data/lib/generators/cypress_on_rails/templates/spec/cypress/e2e/rails_examples/using_scenarios.cy.js +1 -1
- data/lib/generators/cypress_on_rails/templates/spec/cypress/e2e/rails_examples/using_vcr.cy.js +1 -1
- data/lib/generators/cypress_on_rails/templates/spec/cypress/support/on-rails.js +2 -2
- data/lib/generators/cypress_on_rails/templates/spec/playwright/e2e/rails_examples/using_scenarios.spec.js +12 -0
- data/lib/generators/cypress_on_rails/templates/spec/playwright/support/index.js.erb +21 -0
- data/lib/generators/cypress_on_rails/templates/spec/playwright/support/on-rails.js +37 -0
- data/lib/generators/cypress_on_rails/templates/spec/playwright.config.js +79 -0
- data/lib/generators/cypress_on_rails/update_generator.rb +14 -3
- data/plugin/support/index.js +2 -2
- data/spec/cypress_on_rails/command_executor_spec.rb +1 -1
- data/spec/cypress_on_rails/configuration_spec.rb +6 -3
- data/spec/cypress_on_rails/middleware_spec.rb +20 -20
- data/spec/cypress_on_rails/vcr_middleware_spec.rb +5 -5
- data/specs_e2e/playwright.config.js +79 -0
- data/specs_e2e/rails_3_2/test.sh +6 -1
- data/specs_e2e/rails_4_2/test.sh +11 -6
- data/specs_e2e/rails_5_2/test.sh +9 -4
- data/tmp/pids/.gitkeep +0 -0
- metadata +19 -13
- /data/lib/generators/cypress_on_rails/templates/spec/{cypress → e2e}/app_commands/activerecord_fixtures.rb +0 -0
- /data/lib/generators/cypress_on_rails/templates/spec/{cypress → e2e}/app_commands/clean.rb +0 -0
- /data/lib/generators/cypress_on_rails/templates/spec/{cypress → e2e}/app_commands/eval.rb +0 -0
- /data/lib/generators/cypress_on_rails/templates/spec/{cypress → e2e}/app_commands/factory_bot.rb +0 -0
- /data/lib/generators/cypress_on_rails/templates/spec/{cypress → e2e}/app_commands/log_fail.rb +0 -0
- /data/lib/generators/cypress_on_rails/templates/spec/{cypress → e2e}/app_commands/scenarios/basic.rb +0 -0
- /data/lib/generators/cypress_on_rails/templates/spec/{cypress/cypress_helper.rb.erb → e2e/e2e_helper.rb.erb} +0 -0
- /data/spec/cypress_on_rails/command_executor/{cypress_helper.rb → e2e_helper.rb} +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bc763de97980a2be63d8eac1ca850d9695c7e1778c8678d83cec0de7c8270b37
|
4
|
+
data.tar.gz: 9c830d9c70faebc8aac3891caa6ab3547cdf66fe9c89d3eda131248086ff55a2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 88104bb87f1ab6933c17495ff3cbe112a27fc8daa5ee97752eb25e72e46d1ca6e2b54b907857650d49455ca3cb30534e6a6e4d02a6d5f240ddc69ea9d9c5cdac
|
7
|
+
data.tar.gz: 61f547751df2b0500d15b3480732823916a6b3ce0a768cbed696764ec9ddb3853b0d4919e9f2a8249803830b70334f0914c8075d0eb97d84abf68c9835747d1a
|
data/.github/workflows/ruby.yml
CHANGED
@@ -16,13 +16,15 @@ jobs:
|
|
16
16
|
uses: ruby/setup-ruby@v1
|
17
17
|
with:
|
18
18
|
ruby-version: 2.3
|
19
|
-
bundler-cache: true
|
19
|
+
bundler-cache: true
|
20
20
|
- name: Run tests
|
21
21
|
run: bundle exec rake
|
22
22
|
- run: gem uninstall -v '>= 2' -ax bundler || true
|
23
23
|
- run: gem install bundler -v '< 2'
|
24
24
|
- name: Run interaction tests
|
25
25
|
run: ./specs_e2e/rails_3_2/test.sh
|
26
|
+
env:
|
27
|
+
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
|
26
28
|
|
27
29
|
rails_4_2:
|
28
30
|
runs-on: ubuntu-latest
|
@@ -40,6 +42,8 @@ jobs:
|
|
40
42
|
- run: gem install bundler -v '< 2'
|
41
43
|
- name: Run interaction tests
|
42
44
|
run: ./specs_e2e/rails_4_2/test.sh
|
45
|
+
env:
|
46
|
+
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
|
43
47
|
|
44
48
|
rails_5_2:
|
45
49
|
runs-on: ubuntu-latest
|
@@ -50,8 +54,10 @@ jobs:
|
|
50
54
|
uses: ruby/setup-ruby@v1
|
51
55
|
with:
|
52
56
|
ruby-version: 2.6
|
53
|
-
bundler-cache: true
|
57
|
+
bundler-cache: true
|
54
58
|
- name: Run tests
|
55
59
|
run: bundle exec rake
|
56
60
|
- name: Run interaction tests
|
57
61
|
run: ./specs_e2e/rails_5_2/test.sh
|
62
|
+
env:
|
63
|
+
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,21 @@
|
|
1
|
+
## [1.15.0]
|
2
|
+
[Compare]: https://github.com/shakacode/cypress-on-rails/compare/v1.14.0...v1.15.0
|
3
|
+
|
4
|
+
### Changed
|
5
|
+
* Add support for any e2e testing framewrok starting with Playwright [PR 131](https://github.com/shakacode/cypress-on-rails/pull/131) by [KhaledEmaraDev]
|
6
|
+
|
7
|
+
## [1.14.0]
|
8
|
+
[Compare]: https://github.com/shakacode/cypress-on-rails/compare/v1.13.1...v1.14.0
|
9
|
+
|
10
|
+
### Changed
|
11
|
+
* Add support for proxy routes through `api_prefix` [PR 130](https://github.com/shakacode/cypress-on-rails/pull/130) by [RomainEndelin]
|
12
|
+
|
13
|
+
### Fixed
|
14
|
+
* Properly copies the cypress_helper file when running the update generator [PR 117](https://github.com/shakacode/cypress-on-rails/pull/117) by [alvincrespo]
|
15
|
+
|
16
|
+
### Tasks
|
17
|
+
* pass cypress record key to github action [PR 110](https://github.com/shakacode/cypress-on-rails/pull/110)
|
18
|
+
|
1
19
|
## [1.13.1]
|
2
20
|
[Compare]: https://github.com/shakacode/cypress-on-rails/compare/v1.13.0...v1.13.1
|
3
21
|
|
@@ -34,7 +52,7 @@
|
|
34
52
|
[Compare]: https://github.com/shakacode/cypress-on-rails/compare/v1.10.1...v1.11.0
|
35
53
|
|
36
54
|
### Changed
|
37
|
-
* improve app command logging on cypress
|
55
|
+
* improve app command logging on cypress
|
38
56
|
* Allow build and build_list commands to be executed against factory bot [PR 87](https://github.com/shakacode/cypress-on-rails/pull/87) by [Alexander-Blair]
|
39
57
|
|
40
58
|
## [1.10.1]
|
data/README.md
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
# CypressOnRails
|
2
2
|
|
3
3
|
![Build Status](https://github.com/shakacode/cypress-on-rails/actions/workflows/ruby.yml/badge.svg)
|
4
|
+
[![cypress-on-rails](https://img.shields.io/endpoint?url=https://dashboard.cypress.io/badge/simple/2b6cjr/master&style=plastic&logo=cypress)](https://dashboard.cypress.io/projects/2b6cjr/runs)
|
4
5
|
[![Gem Version](https://badge.fury.io/rb/cypress-on-rails.svg)](https://badge.fury.io/rb/cypress-on-rails)
|
5
6
|
|
6
7
|
----
|
7
8
|
|
8
|
-
This project is sponsored by the software consulting firm [ShakaCode](https://www.shakacode.com), creator of the [React on Rails Gem](https://github.com/shakacode/react_on_rails). We focus on React (with TS or ReScript) front-ends, often with Ruby on Rails or Gatsby. See [our recent work](https://www.shakacode.com/recent-work) and [client engagement model](https://www.shakacode.com/blog/client-engagement-model/). Feel free to engage in discussions around this gem at our [Slack Channel](https://join.slack.com/t/reactrails/shared_invite/enQtNjY3NTczMjczNzYxLTlmYjdiZmY3MTVlMzU2YWE0OWM0MzNiZDI0MzdkZGFiZTFkYTFkOGVjODBmOWEyYWQ3MzA2NGE1YWJjNmVlMGE) or our [forum category for Cypress](https://forum.shakacode.com/c/cypress-on-rails/55).
|
9
|
+
This project is sponsored by the software consulting firm [ShakaCode](https://www.shakacode.com), creator of the [React on Rails Gem](https://github.com/shakacode/react_on_rails). We focus on React (with TS or ReScript) front-ends, often with Ruby on Rails or Gatsby. See [our recent work](https://www.shakacode.com/recent-work) and [client engagement model](https://www.shakacode.com/blog/client-engagement-model/). Feel free to engage in discussions around this gem at our [Slack Channel](https://join.slack.com/t/reactrails/shared_invite/enQtNjY3NTczMjczNzYxLTlmYjdiZmY3MTVlMzU2YWE0OWM0MzNiZDI0MzdkZGFiZTFkYTFkOGVjODBmOWEyYWQ3MzA2NGE1YWJjNmVlMGE) or our [forum category for Cypress](https://forum.shakacode.com/c/cypress-on-rails/55).
|
9
10
|
|
10
11
|
Interested in joining a small team that loves open source? Check our [careers page](https://www.shakacode.com/career/).
|
11
12
|
|
@@ -18,12 +19,16 @@ Suggest you first learn the basics of Cypress before attempting to integrate wit
|
|
18
19
|
|
19
20
|
* [Good start Here](https://docs.cypress.io/examples/examples/tutorials.html#Best-Practices)
|
20
21
|
|
22
|
+
# Totally new to Playwright?
|
23
|
+
Suggest you first learn the basics of Playwright before attempting to integrate with Ruby on Rails
|
24
|
+
|
25
|
+
* [Good start Here](https://playwright.dev/docs/writing-tests)
|
26
|
+
|
21
27
|
## Overview
|
22
28
|
|
23
|
-
Gem for using [cypress.io](http://github.com/cypress-io/) in Rails and
|
24
|
-
with the goal of controlling State as mentioned in [Cypress Best Practices](https://docs.cypress.io/guides/references/best-practices.html#Organizing-Tests-Logging-In-Controlling-State)
|
29
|
+
Gem for using [cypress.io](http://github.com/cypress-io/) or [playwright.dev](https://playwright.dev/) in Rails and Ruby Rack applications with the goal of controlling state as mentioned in [Cypress Best Practices](https://docs.cypress.io/guides/references/best-practices.html#Organizing-Tests-Logging-In-Controlling-State)
|
25
30
|
|
26
|
-
It allows to run code in the application context when executing cypress tests.
|
31
|
+
It allows you to run code in the application context when executing cypress or playwright tests.
|
27
32
|
Do things like:
|
28
33
|
* use database_cleaner before each test
|
29
34
|
* seed the database with default data for each test
|
@@ -42,7 +47,7 @@ Has examples of setting up state with:
|
|
42
47
|
|
43
48
|
## Installation
|
44
49
|
|
45
|
-
Add this to your Gemfile
|
50
|
+
Add this to your `Gemfile`:
|
46
51
|
|
47
52
|
```ruby
|
48
53
|
group :test, :development do
|
@@ -53,11 +58,21 @@ end
|
|
53
58
|
Generate the boilerplate code using:
|
54
59
|
|
55
60
|
```shell
|
61
|
+
# by default installs only cypress
|
56
62
|
bin/rails g cypress_on_rails:install
|
57
63
|
|
58
64
|
# if you have/want a different cypress folder (default is cypress)
|
59
65
|
bin/rails g cypress_on_rails:install --cypress_folder=spec/cypress
|
60
66
|
|
67
|
+
# to install both cypress and playwright
|
68
|
+
bin/rails g cypress_on_rails:install --install_cypress --install_playwright --playwright_folder=playwright
|
69
|
+
|
70
|
+
# to change where the Ruby files reside (default is e2e)
|
71
|
+
bin/rails g cypress_on_rails:install --install_folder=test/e2e
|
72
|
+
|
73
|
+
# if you target the Rails server with a path prefix to your URL
|
74
|
+
bin/rails g cypress_on_rails:install --api_prefix=/api
|
75
|
+
|
61
76
|
# if you want to install cypress with npm
|
62
77
|
bin/rails g cypress_on_rails:install --install_cypress_with=npm
|
63
78
|
|
@@ -69,27 +84,27 @@ bin/rails g cypress_on_rails:update
|
|
69
84
|
```
|
70
85
|
|
71
86
|
The generator modifies/adds the following files/directory in your application:
|
72
|
-
* `config/
|
73
|
-
* `config/initializers/cypress_on_rails` used to configure CypressDev
|
87
|
+
* `config/initializers/cypress_on_rails.rb` used to configure Cypress on Rails
|
74
88
|
* `spec/cypress/e2e/` contains your cypress tests
|
75
|
-
* `spec/
|
76
|
-
* `spec/cypress/
|
77
|
-
* `spec/
|
89
|
+
* `spec/playwright/e2e/` contains your playwright tests
|
90
|
+
* `spec/cypress/support/on-rails.js` contains Cypress on Rails support code
|
91
|
+
* `spec/playwright/support/on-rails.js` contains Playwright on Rails support code
|
92
|
+
* `spec/e2e/app_commands/scenarios/` contains your Cypress on Rails scenario definitions
|
93
|
+
* `spec/e2e/cypress_helper.rb` contains helper code for Cypress on Rails app commands
|
78
94
|
|
79
|
-
|
80
|
-
|
95
|
+
If you are not using `database_cleaner` look at `spec/e2e/app_commands/clean.rb`.
|
96
|
+
If you are not using `factory_bot` look at `spec/e2e/app_commands/factory_bot.rb`.
|
81
97
|
|
82
|
-
Now you can create scenarios and commands that are plain
|
98
|
+
Now you can create scenarios and commands that are plain Ruby files that get loaded through middleware, the ruby sky is your limit.
|
83
99
|
|
84
100
|
### Update your database.yml
|
85
101
|
|
86
|
-
When
|
87
|
-
make are picked up without having to restart the server.
|
88
|
-
It's
|
102
|
+
When running `cypress test` or `playwright test` on your local computer it's recommended to start your server in development mode so that changes you
|
103
|
+
make are picked up without having to restart the server.
|
104
|
+
It's recommended you update your `database.yml` to check if the `CYPRESS` environment variable is set and switch it to the test database
|
89
105
|
otherwise cypress will keep clearing your development database.
|
90
106
|
|
91
|
-
|
92
|
-
|
107
|
+
For example:
|
93
108
|
```yaml
|
94
109
|
development:
|
95
110
|
<<: *default
|
@@ -112,11 +127,15 @@ Getting started on your local environment
|
|
112
127
|
CYPRESS=1 bin/rails server -p 5017
|
113
128
|
|
114
129
|
# in separate window start cypress
|
115
|
-
yarn cypress open
|
130
|
+
yarn cypress open
|
116
131
|
# or for npm
|
117
|
-
node_modules/.bin/cypress open
|
132
|
+
node_modules/.bin/cypress open
|
118
133
|
# or if you changed the cypress folder to spec/cypress
|
119
134
|
yarn cypress open --project ./spec
|
135
|
+
# or for playwright
|
136
|
+
yarn playwright test --ui
|
137
|
+
# or using npm
|
138
|
+
npx playwright test --ui
|
120
139
|
```
|
121
140
|
|
122
141
|
How to run cypress on CI
|
@@ -127,7 +146,7 @@ How to run cypress on CI
|
|
127
146
|
|
128
147
|
yarn run cypress run
|
129
148
|
# or for npm
|
130
|
-
|
149
|
+
npx cypress run
|
131
150
|
```
|
132
151
|
|
133
152
|
### Example of using factory bot
|
@@ -136,8 +155,8 @@ You can run your [factory_bot](https://github.com/thoughtbot/factory_bot) direct
|
|
136
155
|
|
137
156
|
```js
|
138
157
|
// spec/cypress/e2e/simple.cy.js
|
139
|
-
describe('My First Test',
|
140
|
-
it('visit root',
|
158
|
+
describe('My First Test', () => {
|
159
|
+
it('visit root', () => {
|
141
160
|
// This calls to the backend to prepare the application state
|
142
161
|
cy.appFactories([
|
143
162
|
['create_list', 'post', 10],
|
@@ -148,7 +167,7 @@ describe('My First Test', function() {
|
|
148
167
|
// Visit the application under test
|
149
168
|
cy.visit('/')
|
150
169
|
|
151
|
-
cy.contains(
|
170
|
+
cy.contains('Hello World')
|
152
171
|
|
153
172
|
// Accessing result
|
154
173
|
cy.appFactories([['create', 'invoice', { paid: false }]]).then((records) => {
|
@@ -157,9 +176,9 @@ describe('My First Test', function() {
|
|
157
176
|
})
|
158
177
|
})
|
159
178
|
```
|
160
|
-
You can check the [association
|
179
|
+
You can check the [association docs](docs/factory_bot_associations.md) on more ways to setup association with the correct data.
|
161
180
|
|
162
|
-
In some cases, using static Cypress fixtures may not provide sufficient flexibility when mocking HTTP response bodies
|
181
|
+
In some cases, using static Cypress fixtures may not provide sufficient flexibility when mocking HTTP response bodies. It's possible to use `FactoryBot.build` to generate Ruby hashes that can then be used as mock JSON responses:
|
163
182
|
```ruby
|
164
183
|
FactoryBot.define do
|
165
184
|
factory :some_web_response, class: Hash do
|
@@ -171,13 +190,13 @@ FactoryBot.define do
|
|
171
190
|
end
|
172
191
|
end
|
173
192
|
|
174
|
-
FactoryBot.build(:some_web_response
|
193
|
+
FactoryBot.build(:some_web_response => { 'id' => 123, 'name' => 'Mr Blobby', 'occupation' => 'Evil pink clown' })
|
175
194
|
```
|
176
195
|
|
177
196
|
This can then be combined with Cypress mocks:
|
178
197
|
```js
|
179
|
-
describe('My First Test',
|
180
|
-
it('visit root',
|
198
|
+
describe('My First Test', () => {
|
199
|
+
it('visit root', () => {
|
181
200
|
// This calls to the backend to generate the mocked response
|
182
201
|
cy.appFactories([
|
183
202
|
['build', 'some_web_response', { name: 'Baby Blobby' }]
|
@@ -190,14 +209,14 @@ describe('My First Test', function() {
|
|
190
209
|
cy.visit('/')
|
191
210
|
})
|
192
211
|
|
193
|
-
cy.contains(
|
212
|
+
cy.contains('Hello World')
|
194
213
|
})
|
195
214
|
})
|
196
215
|
```
|
197
216
|
|
198
|
-
### Example of loading
|
217
|
+
### Example of loading Rails test fixtures
|
199
218
|
```ruby
|
200
|
-
# spec/
|
219
|
+
# spec/e2e/app_commands/activerecord_fixtures.rb
|
201
220
|
require "active_record/fixtures"
|
202
221
|
|
203
222
|
fixtures_dir = ActiveRecord::Tasks::DatabaseTasks.fixtures_path
|
@@ -210,15 +229,15 @@ ActiveRecord::FixtureSet.create_fixtures(fixtures_dir, fixture_files)
|
|
210
229
|
|
211
230
|
```js
|
212
231
|
// spec/cypress/e2e/simple.cy.js
|
213
|
-
describe('My First Test',
|
214
|
-
it('visit root',
|
232
|
+
describe('My First Test', () => {
|
233
|
+
it('visit root', () => {
|
215
234
|
// This calls to the backend to prepare the application state
|
216
235
|
cy.appFixtures()
|
217
236
|
|
218
237
|
// Visit the application under test
|
219
238
|
cy.visit('/')
|
220
239
|
|
221
|
-
cy.contains(
|
240
|
+
cy.contains('Hello World')
|
222
241
|
})
|
223
242
|
})
|
224
243
|
```
|
@@ -227,7 +246,7 @@ describe('My First Test', function() {
|
|
227
246
|
|
228
247
|
Scenarios are named `before` blocks that you can reference in your test.
|
229
248
|
|
230
|
-
You define a scenario in the `spec/
|
249
|
+
You define a scenario in the `spec/e2e/app_commands/scenarios` directory:
|
231
250
|
```ruby
|
232
251
|
# spec/cypress/app_commands/scenarios/basic.rb
|
233
252
|
Profile.create name: "Cypress Hill"
|
@@ -239,33 +258,33 @@ CypressOnRails::SmartFactoryWrapper.create(:profile, name: "Cypress Hill")
|
|
239
258
|
Then reference the scenario in your test:
|
240
259
|
```js
|
241
260
|
// spec/cypress/e2e/scenario_example.cy.js
|
242
|
-
describe('My First Test',
|
243
|
-
it('visit root',
|
261
|
+
describe('My First Test', () => {
|
262
|
+
it('visit root', () => {
|
244
263
|
// This calls to the backend to prepare the application state
|
245
264
|
cy.appScenario('basic')
|
246
265
|
|
247
266
|
cy.visit('/profiles')
|
248
267
|
|
249
|
-
cy.contains(
|
268
|
+
cy.contains('Cypress Hill')
|
250
269
|
})
|
251
270
|
})
|
252
271
|
```
|
253
272
|
|
254
273
|
### Example of using app commands
|
255
274
|
|
256
|
-
|
275
|
+
Create a Ruby file in the `spec/e2e/app_commands` directory:
|
257
276
|
```ruby
|
258
|
-
# spec/
|
277
|
+
# spec/e2e/app_commands/load_seed.rb
|
259
278
|
load "#{Rails.root}/db/seeds.rb"
|
260
279
|
```
|
261
280
|
|
262
281
|
Then reference the command in your test with `cy.app('load_seed')`:
|
263
282
|
```js
|
264
283
|
// spec/cypress/e2e/simple.cy.js
|
265
|
-
describe('My First Test',
|
284
|
+
describe('My First Test', () => {
|
266
285
|
beforeEach(() => { cy.app('load_seed') })
|
267
286
|
|
268
|
-
it('visit root',
|
287
|
+
it('visit root', () => {
|
269
288
|
cy.visit('/')
|
270
289
|
|
271
290
|
cy.contains("Seeds")
|
@@ -273,11 +292,42 @@ describe('My First Test', function() {
|
|
273
292
|
})
|
274
293
|
```
|
275
294
|
|
276
|
-
|
295
|
+
### Example of using scenario with Playwright
|
277
296
|
|
278
|
-
|
297
|
+
Scenarios are named `before` blocks that you can reference in your test.
|
279
298
|
|
280
|
-
|
299
|
+
You define a scenario in the `spec/e2e/app_commands/scenarios` directory:
|
300
|
+
```ruby
|
301
|
+
# spec/e2e/app_commands/scenarios/basic.rb
|
302
|
+
Profile.create name: "Cypress Hill"
|
303
|
+
|
304
|
+
# or if you have factory_bot enabled in your cypress_helper
|
305
|
+
CypressOnRails::SmartFactoryWrapper.create(:profile, name: "Cypress Hill")
|
306
|
+
```
|
307
|
+
|
308
|
+
Then reference the scenario in your test:
|
309
|
+
```js
|
310
|
+
// spec/playwright/e2e/scenario_example.spec.js
|
311
|
+
import { test, expect } from "@playwright/test";
|
312
|
+
import { app, appScenario } from '../../support/on-rails';
|
313
|
+
|
314
|
+
test.describe("Rails using scenarios examples", () => {
|
315
|
+
test.beforeEach(async ({ page }) => {
|
316
|
+
await app('clean');
|
317
|
+
});
|
318
|
+
|
319
|
+
test("setup basic scenario", async ({ page }) => {
|
320
|
+
await appScenario('basic');
|
321
|
+
await page.goto("/");
|
322
|
+
});
|
323
|
+
});
|
324
|
+
```
|
325
|
+
|
326
|
+
## Experimental Features (matching npm package)
|
327
|
+
|
328
|
+
Please test and give feedback.
|
329
|
+
|
330
|
+
Add the npm package:
|
281
331
|
|
282
332
|
```
|
283
333
|
yarn add cypress-on-rails --dev
|
@@ -285,7 +335,7 @@ yarn add cypress-on-rails --dev
|
|
285
335
|
|
286
336
|
### for VCR
|
287
337
|
|
288
|
-
This only works when you start the
|
338
|
+
This only works when you start the Rails server with a single worker and single thread
|
289
339
|
|
290
340
|
#### setup
|
291
341
|
|
@@ -298,13 +348,13 @@ VCR.configure do |config|
|
|
298
348
|
end
|
299
349
|
```
|
300
350
|
|
301
|
-
Add to
|
351
|
+
Add to your `cypress/support/index.js`:
|
302
352
|
|
303
353
|
```js
|
304
354
|
import 'cypress-on-rails/support/index'
|
305
355
|
```
|
306
356
|
|
307
|
-
Add to
|
357
|
+
Add to your `cypress/app_commands/clean.rb`:
|
308
358
|
|
309
359
|
```ruby
|
310
360
|
VCR.eject_cassette # make sure we no cassettes inserted before the next test starts
|
@@ -312,7 +362,7 @@ VCR.turn_off!
|
|
312
362
|
WebMock.disable! if defined?(WebMock)
|
313
363
|
```
|
314
364
|
|
315
|
-
Add to
|
365
|
+
Add to your `config/cypress_on_rails.rb`:
|
316
366
|
|
317
367
|
```ruby
|
318
368
|
c.use_vcr_middleware = !Rails.env.production? && ENV['CYPRESS'].present?
|
@@ -324,11 +374,11 @@ You have `vcr_insert_cassette` and `vcr_eject_cassette` available. https://www.r
|
|
324
374
|
|
325
375
|
|
326
376
|
```js
|
327
|
-
describe('My First Test',
|
377
|
+
describe('My First Test', () => {
|
328
378
|
beforeEach(() => { cy.app('load_seed') })
|
329
379
|
|
330
|
-
it('visit root',
|
331
|
-
cy.app('clean') // have a look at
|
380
|
+
it('visit root', () => {
|
381
|
+
cy.app('clean') // have a look at e2e/app_commands/clean.rb
|
332
382
|
|
333
383
|
cy.vcr_insert_cassette('cats', { record: "new_episodes" })
|
334
384
|
cy.visit('/using_vcr/index')
|
@@ -336,7 +386,7 @@ describe('My First Test', function() {
|
|
336
386
|
cy.get('a').contains('Cats').click()
|
337
387
|
cy.contains('Wikipedia has a recording of a cat meowing, because why not?')
|
338
388
|
|
339
|
-
cy.vcr_eject_cassette()
|
389
|
+
cy.vcr_eject_cassette()
|
340
390
|
|
341
391
|
cy.vcr_insert_cassette('cats')
|
342
392
|
cy.visit('/using_vcr/record_cats')
|
@@ -362,30 +412,30 @@ use CypressOnRails::Middleware
|
|
362
412
|
run MyApp
|
363
413
|
```
|
364
414
|
|
365
|
-
add the following file to
|
415
|
+
add the following file to Cypress
|
366
416
|
|
367
417
|
```js
|
368
418
|
// test/cypress/support/on-rails.js
|
369
|
-
// CypressOnRails:
|
370
|
-
Cypress.Commands.add('appCommands',
|
419
|
+
// CypressOnRails: don't remove these commands
|
420
|
+
Cypress.Commands.add('appCommands', (body) => {
|
371
421
|
cy.request({
|
372
422
|
method: 'POST',
|
373
|
-
url:
|
423
|
+
url: '/__cypress__/command',
|
374
424
|
body: JSON.stringify(body),
|
375
425
|
log: true,
|
376
426
|
failOnStatusCode: true
|
377
427
|
})
|
378
428
|
});
|
379
429
|
|
380
|
-
Cypress.Commands.add('app',
|
430
|
+
Cypress.Commands.add('app', (name, command_options) => {
|
381
431
|
cy.appCommands({name: name, options: command_options})
|
382
432
|
});
|
383
433
|
|
384
|
-
Cypress.Commands.add('appScenario',
|
434
|
+
Cypress.Commands.add('appScenario', (name) => {
|
385
435
|
cy.app('scenarios/' + name)
|
386
436
|
});
|
387
437
|
|
388
|
-
Cypress.Commands.add('appFactories',
|
438
|
+
Cypress.Commands.add('appFactories', (options) => {
|
389
439
|
cy.app('factory_bot', options)
|
390
440
|
});
|
391
441
|
// CypressOnRails: end
|
@@ -396,6 +446,17 @@ beforeEach(() => {
|
|
396
446
|
});
|
397
447
|
```
|
398
448
|
|
449
|
+
## API Prefix
|
450
|
+
|
451
|
+
If your Rails server is exposed under a proxy, typically https://my-local.dev/api, you can use the `api_prefix` option.
|
452
|
+
In `config/initializers/cypress_on_rails.rb`, add this line:
|
453
|
+
```ruby
|
454
|
+
CypressOnRails.configure do |c|
|
455
|
+
# ...
|
456
|
+
c.api_prefix = '/api'
|
457
|
+
end
|
458
|
+
```
|
459
|
+
|
399
460
|
## Contributing
|
400
461
|
|
401
462
|
1. Fork it ( https://github.com/shakacode/cypress-on-rails/fork )
|
@@ -404,14 +465,37 @@ beforeEach(() => {
|
|
404
465
|
4. Push to the branch (`git push origin my-new-feature`)
|
405
466
|
5. Create a new Pull Request
|
406
467
|
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
468
|
+
## Supporters
|
469
|
+
|
470
|
+
<a href="https://www.jetbrains.com">
|
471
|
+
<img src="https://user-images.githubusercontent.com/4244251/184881139-42e4076b-024b-4b30-8c60-c3cd0e758c0a.png" alt="JetBrains" height="120px">
|
472
|
+
</a>
|
473
|
+
<a href="https://scoutapp.com">
|
474
|
+
<picture>
|
475
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://user-images.githubusercontent.com/4244251/184881147-0d077438-3978-40da-ace9-4f650d2efe2e.png">
|
476
|
+
<source media="(prefers-color-scheme: light)" srcset="https://user-images.githubusercontent.com/4244251/184881152-9f2d8fba-88ac-4ba6-873b-22387f8711c5.png">
|
477
|
+
<img alt="ScoutAPM" src="https://user-images.githubusercontent.com/4244251/184881152-9f2d8fba-88ac-4ba6-873b-22387f8711c5.png" height="120px">
|
478
|
+
</picture>
|
479
|
+
</a>
|
480
|
+
<br />
|
481
|
+
<a href="https://www.browserstack.com">
|
482
|
+
<picture>
|
483
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://user-images.githubusercontent.com/4244251/184881122-407dcc29-df78-4b20-a9ad-f597b56f6cdb.png">
|
484
|
+
<source media="(prefers-color-scheme: light)" srcset="https://user-images.githubusercontent.com/4244251/184881129-e1edf4b7-3ae1-4ea8-9e6d-3595cf01609e.png">
|
485
|
+
<img alt="BrowserStack" src="https://user-images.githubusercontent.com/4244251/184881129-e1edf4b7-3ae1-4ea8-9e6d-3595cf01609e.png" height="55px">
|
486
|
+
</picture>
|
487
|
+
</a>
|
488
|
+
<a href="https://railsautoscale.com">
|
489
|
+
<img src="https://user-images.githubusercontent.com/4244251/184881144-95c2c25c-9879-4069-864d-4e67d6ed39d2.png" alt="Rails Autoscale" height="55px">
|
490
|
+
</a>
|
491
|
+
<a href="https://www.honeybadger.io">
|
492
|
+
<img src="https://user-images.githubusercontent.com/4244251/184881133-79ee9c3c-8165-4852-958e-31687b9536f4.png" alt="Honeybadger" height="55px">
|
493
|
+
</a>
|
494
|
+
<a href="https://reviewable.io">
|
495
|
+
<img src="https://user-images.githubusercontent.com/20628911/230848305-c94510a4-82d7-468f-bf9f-eeb81d3f2ce0.png" alt="Reviewable" height="55px">
|
496
|
+
</a>
|
497
|
+
|
498
|
+
<br />
|
499
|
+
<br />
|
500
|
+
|
501
|
+
The following companies support our open source projects, and ShakaCode uses their products!
|
data/docs/authentication.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Example for Authenticating a User
|
2
2
|
|
3
|
-
|
3
|
+
In `config/routes.rb`:
|
4
4
|
```rb
|
5
5
|
Rails.application.routes.draw do
|
6
6
|
# ...... your other routes
|
@@ -12,7 +12,7 @@ Rails.application.routes.draw do
|
|
12
12
|
end
|
13
13
|
```
|
14
14
|
|
15
|
-
app/controllers/cypress_controller.rb
|
15
|
+
`app/controllers/cypress_controller.rb`:
|
16
16
|
```rb
|
17
17
|
class CypressController < ApplicationController
|
18
18
|
skip_before_action :verify_authenticity_token
|
@@ -29,21 +29,23 @@ class CypressController < ApplicationController
|
|
29
29
|
end
|
30
30
|
```
|
31
31
|
|
32
|
-
|
32
|
+
In `cypress/support/on-rails.js`:
|
33
33
|
```js
|
34
|
-
Cypress.Commands.add(
|
35
|
-
if(!details)
|
34
|
+
Cypress.Commands.add('forceLogin', (details) => {
|
35
|
+
if (!details) {
|
36
36
|
details = {}
|
37
|
+
}
|
37
38
|
|
38
|
-
if(!details.redirect_to)
|
39
|
+
if (!details.redirect_to) {
|
39
40
|
details.redirect_to = '/'
|
41
|
+
}
|
40
42
|
|
41
|
-
cy.visit(
|
42
|
-
{ method:
|
43
|
-
})
|
43
|
+
cy.visit('__cypress__/forceLogin',
|
44
|
+
{ method: 'POST', body: { email: details.email, redirect_to: details.redirect_to } })
|
45
|
+
})
|
44
46
|
```
|
45
47
|
|
46
|
-
|
48
|
+
Examples of usage in Cypress specs:
|
47
49
|
```js
|
48
50
|
cy.forceLogin()
|
49
51
|
cy.forceLogin({redirect_to: '/profile'})
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# Setting up associations with the correct data
|
2
2
|
|
3
|
-
You cannot access associations directly from Cypress like you can do with
|
3
|
+
You cannot access associations directly from Cypress like you can do with Ruby tests.
|
4
4
|
So setting up associations has to be done differently from within Cypress.
|
5
5
|
|
6
6
|
There are a few ways you can setup associations with the correct data using Cypress and FactoryBot.
|
@@ -27,7 +27,7 @@ You can do the following:
|
|
27
27
|
|
28
28
|
## 1. Setting the foreign keys
|
29
29
|
|
30
|
-
factories.rb
|
30
|
+
`factories.rb`:
|
31
31
|
```rb
|
32
32
|
FactoryBot.define do
|
33
33
|
factory :author do
|
@@ -45,13 +45,13 @@ then in Cypress
|
|
45
45
|
```js
|
46
46
|
// example with overriding the defaults
|
47
47
|
cy.appFactories([['create', 'author', { name: 'James' }]]).then((records) => {
|
48
|
-
cy.appFactories([['create', 'post', { title: 'Cypress is cool', author_id: records[0].id }]]
|
49
|
-
})
|
48
|
+
cy.appFactories([['create', 'post', { title: 'Cypress is cool', author_id: records[0].id }]])
|
49
|
+
})
|
50
50
|
|
51
51
|
// example without overriding anything
|
52
52
|
cy.appFactories([['create', 'author']]).then((records) => {
|
53
|
-
cy.appFactories([['create', 'post', { author_id: records[0].id }]]
|
54
|
-
})
|
53
|
+
cy.appFactories([['create', 'post', { author_id: records[0].id }]])
|
54
|
+
})
|
55
55
|
```
|
56
56
|
|
57
57
|
## 2. Using transient attributes
|
@@ -75,10 +75,10 @@ end
|
|
75
75
|
then in Cypress
|
76
76
|
```js
|
77
77
|
// example with overriding the defaults
|
78
|
-
cy.appFactories([['create', 'post', { title: 'Cypress is cool', author_name: 'James' }]]
|
78
|
+
cy.appFactories([['create', 'post', { title: 'Cypress is cool', author_name: 'James' }]])
|
79
79
|
|
80
80
|
// example without overriding
|
81
|
-
cy.appFactories([['create', 'post']]
|
81
|
+
cy.appFactories([['create', 'post']])
|
82
82
|
```
|
83
83
|
|
84
84
|
## 3. Using Nested Attributes
|
@@ -99,11 +99,11 @@ end
|
|
99
99
|
then in Cypress
|
100
100
|
```js
|
101
101
|
// example with overriding the defaults
|
102
|
-
cy.appFactories([['create', 'post', { title: 'Cypress is cool', author_attributes: { name: 'James' } }]]
|
102
|
+
cy.appFactories([['create', 'post', { title: 'Cypress is cool', author_attributes: { name: 'James' } }]])
|
103
103
|
|
104
104
|
// example without overriding
|
105
|
-
cy.appFactories([['create', 'post']]
|
105
|
+
cy.appFactories([['create', 'post']])
|
106
106
|
|
107
107
|
// example of creating author with multiple posts
|
108
|
-
cy.appFactories([['create', 'author', { name: 'James', posts_attributes: [{ name: 'Cypress is cool' }, {name: 'Rails is awesome' }] ]]
|
108
|
+
cy.appFactories([['create', 'author', { name: 'James', posts_attributes: [{ name: 'Cypress is cool' }, {name: 'Rails is awesome' }] }]])
|
109
109
|
```
|