cypress-on-rails 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +6 -6
  3. data/CHANGELOG.md +4 -0
  4. data/README.md +61 -27
  5. data/lib/cypress_dev/version.rb +1 -1
  6. data/lib/generators/cypress_dev/install_generator.rb +7 -5
  7. data/lib/generators/cypress_dev/templates/spec/cypress/app_commands/activerecord_fixtures.rb +21 -0
  8. data/lib/generators/cypress_dev/templates/spec/cypress/app_commands/clean.rb +1 -0
  9. data/lib/generators/cypress_dev/templates/spec/cypress/app_commands/scenarios/basic.rb +2 -1
  10. data/lib/generators/cypress_dev/templates/spec/cypress/fixtures/example.json +5 -0
  11. data/lib/generators/cypress_dev/templates/spec/cypress/integration/examples/actions.spec.js +272 -0
  12. data/lib/generators/cypress_dev/templates/spec/cypress/integration/examples/aliasing.spec.js +42 -0
  13. data/lib/generators/cypress_dev/templates/spec/cypress/integration/examples/assertions.spec.js +63 -0
  14. data/lib/generators/cypress_dev/templates/spec/cypress/integration/examples/connectors.spec.js +55 -0
  15. data/lib/generators/cypress_dev/templates/spec/cypress/integration/examples/cookies.spec.js +78 -0
  16. data/lib/generators/cypress_dev/templates/spec/cypress/integration/examples/cypress_api.spec.js +211 -0
  17. data/lib/generators/cypress_dev/templates/spec/cypress/integration/examples/files.spec.js +86 -0
  18. data/lib/generators/cypress_dev/templates/spec/cypress/integration/examples/local_storage.spec.js +52 -0
  19. data/lib/generators/cypress_dev/templates/spec/cypress/integration/examples/location.spec.js +32 -0
  20. data/lib/generators/cypress_dev/templates/spec/cypress/integration/examples/misc.spec.js +68 -0
  21. data/lib/generators/cypress_dev/templates/spec/cypress/integration/examples/navigation.spec.js +54 -0
  22. data/lib/generators/cypress_dev/templates/spec/cypress/integration/examples/network_requests.spec.js +108 -0
  23. data/lib/generators/cypress_dev/templates/spec/cypress/integration/examples/querying.spec.js +65 -0
  24. data/lib/generators/cypress_dev/templates/spec/cypress/integration/examples/spies_stubs_clocks.spec.js +62 -0
  25. data/lib/generators/cypress_dev/templates/spec/cypress/integration/examples/traversal.spec.js +121 -0
  26. data/lib/generators/cypress_dev/templates/spec/cypress/integration/examples/utilities.spec.js +89 -0
  27. data/lib/generators/cypress_dev/templates/spec/cypress/integration/examples/viewport.spec.js +59 -0
  28. data/lib/generators/cypress_dev/templates/spec/cypress/integration/examples/waiting.spec.js +34 -0
  29. data/lib/generators/cypress_dev/templates/spec/cypress/integration/examples/window.spec.js +22 -0
  30. data/lib/generators/cypress_dev/templates/spec/cypress/integration/rails_examples/other_spec.js +25 -0
  31. data/lib/generators/cypress_dev/templates/spec/cypress/integration/rails_examples/using_factory_bot.js +31 -0
  32. data/lib/generators/cypress_dev/templates/spec/cypress/integration/rails_examples/using_fixtures.js +33 -0
  33. data/lib/generators/cypress_dev/templates/spec/cypress/integration/rails_examples/using_scenarios_spec.js +26 -0
  34. data/lib/generators/cypress_dev/templates/spec/cypress/support/on-rails.js +7 -3
  35. data/spec/integrations/cypress.json +5 -0
  36. data/spec/integrations/rails_3_2/app/models/post.rb +4 -0
  37. data/spec/integrations/rails_3_2/app/views/welcome/index.html.erb +24 -5
  38. data/spec/integrations/rails_3_2/test.sh +9 -3
  39. data/spec/integrations/rails_4_2/.gitignore +5 -5
  40. data/spec/integrations/rails_4_2/app/models/post.rb +4 -0
  41. data/spec/integrations/rails_4_2/app/views/welcome/index.html.erb +24 -5
  42. data/spec/integrations/rails_4_2/test.sh +11 -4
  43. data/spec/integrations/rails_5_2/.gitignore +7 -5
  44. data/spec/integrations/rails_5_2/Gemfile +2 -0
  45. data/spec/integrations/rails_5_2/app/assets/javascripts/posts.js +2 -0
  46. data/spec/integrations/rails_5_2/app/assets/stylesheets/posts.css +4 -0
  47. data/spec/integrations/rails_5_2/app/assets/stylesheets/scaffold.css +80 -0
  48. data/spec/integrations/rails_5_2/app/controllers/posts_controller.rb +58 -0
  49. data/spec/integrations/rails_5_2/app/helpers/posts_helper.rb +2 -0
  50. data/spec/integrations/rails_5_2/app/models/application_record.rb +3 -0
  51. data/spec/integrations/rails_5_2/app/models/post.rb +1 -12
  52. data/spec/integrations/rails_5_2/app/views/posts/_form.html.erb +32 -0
  53. data/spec/integrations/rails_5_2/app/views/posts/edit.html.erb +6 -0
  54. data/spec/integrations/rails_5_2/app/views/posts/index.html.erb +31 -0
  55. data/spec/integrations/rails_5_2/app/views/posts/new.html.erb +5 -0
  56. data/spec/integrations/rails_5_2/app/views/posts/show.html.erb +19 -0
  57. data/spec/integrations/rails_5_2/config/application.rb +2 -2
  58. data/spec/integrations/rails_5_2/config/database.yml +15 -0
  59. data/spec/integrations/rails_5_2/config/routes.rb +2 -1
  60. data/spec/integrations/rails_5_2/db/migrate/20180621085832_create_posts.rb +11 -0
  61. data/spec/integrations/rails_5_2/test.sh +14 -5
  62. data/spec/integrations/rails_5_2/test/controllers/posts_controller_test.rb +48 -0
  63. data/spec/integrations/rails_5_2/test/cypress_fixtures/posts.yml +11 -0
  64. data/spec/integrations/rails_5_2/test/fixtures/posts.yml +11 -0
  65. data/spec/integrations/rails_5_2/test/models/post_test.rb +7 -0
  66. metadata +45 -4
  67. data/lib/generators/cypress_dev/templates/spec/cypress/integration/on_rails_spec.js +0 -33
  68. data/spec/integrations/rails_5_2/app/controllers/welcome_controller.rb +0 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aae2ee8af5bc58f866014195d209fe1c79f38782abd34d9754fab0dd1e0d6339
4
- data.tar.gz: 9b996dccb18d1ee0aa677d6f2cdd3956077ac5f769b41bcccc262c197fefbf4b
3
+ metadata.gz: a0b54d8af351f5f44e1da67e4c75540a40f529b03434ed24a50e8e145e456084
4
+ data.tar.gz: 599595f9a60941b3b23696d1867fb4c687eaa24b656392df4c98650ba6786558
5
5
  SHA512:
6
- metadata.gz: c846da7db38f8b685aa9777851b16b03425410b10e6699d7ac995ce9a2840cc43659774d41550266752e80d3b49ed90bf44c3fe0bcaa35ce45e369bca26d50e6
7
- data.tar.gz: b33a157691f8cb4629d9f853aa26d3dfec134ae3aefa598f44d5100be3d376340563778753c0a62e193a70990f17140fb622ee561100677d0aca39419802956e
6
+ metadata.gz: 05ebe6824bea9027f18f5e02425aa7f15979e6e8e36af99a3dd3112df3715d7a5d456ecd85b9a307486c873b9af5029bc7f1b6a0f75ae544670c18efe13182ae
7
+ data.tar.gz: d831d9abb63c8b89fad1eb5367c4ad95489f6dfc83c739da0e8508ede8a13723ef0204ad5dba80b9625f47f2d96306ec1d484f13acd77015c9a1eb3671013a34
@@ -2,12 +2,12 @@ language: ruby
2
2
  rvm:
3
3
  - 2.2
4
4
 
5
- addons:
6
- artifacts:
7
- s3_region: "ap-southeast-2"
8
- paths:
9
- - $(ls spec/integrations/*/*/cypress/{screenshots,videos}/* | tr "\n" ":")
10
- - $(ls spec/integrations/rails_3_2/cypress/{screenshots,videos}/* | tr "\n" ":")
5
+ #addons:
6
+ # artifacts:
7
+ # s3_region: "ap-southeast-2"
8
+ # paths:
9
+ # - $(ls spec/integrations/*/*/cypress/{screenshots,videos}/* | tr "\n" ":")
10
+ # - $(ls spec/integrations/rails_3_2/cypress/{screenshots,videos}/* | tr "\n" ":")
11
11
 
12
12
  cache:
13
13
  directories:
@@ -1,3 +1,7 @@
1
+ ### Tasks
2
+ * add cypress examples to install generator
3
+ * add active record integration specs
4
+
1
5
  ## 1.0.1
2
6
  ### Fixed
3
7
  * install generator adding on-rails.js to import.js
data/README.md CHANGED
@@ -12,6 +12,12 @@ Do things like:
12
12
  * use factory_bot to setup data
13
13
  * create scenario files used for specific tests
14
14
 
15
+ Has examples of setting up state with:
16
+ * factory_bot
17
+ * rails test fixtures
18
+ * scenarios
19
+ * custom commands
20
+
15
21
  This gem is based off https://github.com/konvenit/cypress-on-rails
16
22
 
17
23
  ## Getting started
@@ -64,46 +70,49 @@ cd spec
64
70
  yarn run cypress open
65
71
  ```
66
72
 
67
- ### Example of using scenarios
68
-
69
- Scenarios are named `before` blocks that you can reference in your test.
73
+ ### Example of using factory bot
74
+ You can run your [factory_bot](https://github.com/thoughtbot/factory_bot) directly as well
70
75
 
71
- You define a scenario in the `spec/cypress/app_commands/scenarios` directory:
72
76
  ```ruby
73
77
  # spec/cypress/app_commands/scenarios/basic.rb
74
- Profile.create name: "Cypress Hill"
78
+ require 'cypress_dev/smart_factory_wrapper'
75
79
 
76
- # or if you have factory_bot enabled in your cypress_helper
77
- CypressDev::SmartFactoryWrapper.create(:profile, name: "Cypress Hill")
80
+ CypressDev::SmartFactoryWrapper.configure(
81
+ always_reload: !Rails.configuration.cache_classes,
82
+ factory: FactoryBot,
83
+ files: Dir['./spec/factories/**/*.rb']
84
+ )
78
85
  ```
79
86
 
80
- Then reference the scenario in your test:
81
87
  ```js
82
- // spec/cypress/integrations/scenario_example_spec.js
88
+ // spec/cypress/integrations/simple_spec.js
83
89
  describe('My First Test', function() {
84
90
  it('visit root', function() {
85
91
  // This calls to the backend to prepare the application state
86
- cy.appScenario('basic')
92
+ cy.appFactories([
93
+ ['create_list', 'post', 10],
94
+ ['create', 'post', {title: 'Hello World'} ]
95
+ ])
87
96
 
88
- cy.visit('/profiles')
97
+ // Visit the application under test
98
+ cy.visit('/')
89
99
 
90
- cy.contains("Cypress Hill")
100
+ cy.contains("Hello World")
91
101
  })
92
102
  })
93
103
  ```
94
104
 
95
- ### Example of using factory bot
96
- You can run your [factory_bot](https://github.com/thoughtbot/factory_bot) directly as well
97
-
105
+ ### Example of loading rails test fixtures
98
106
  ```ruby
99
- # spec/cypress/app_commands/scenarios/basic.rb
100
- require 'cypress_dev/smart_factory_wrapper'
107
+ # spec/cypress/app_commands/activerecord_fixtures.rb
108
+ require "active_record/fixtures"
101
109
 
102
- CypressDev::SmartFactoryWrapper.configure(
103
- always_reload: !Rails.configuration.cache_classes,
104
- factory: FactoryBot,
105
- files: Dir['./spec/factories/**/*.rb']
106
- )
110
+ fixtures_dir = ActiveRecord::Tasks::DatabaseTasks.fixtures_path
111
+ fixture_files = Dir["#{fixtures_dir}/**/*.yml"].map { |f| f[(fixtures_dir.size + 1)..-5] }
112
+
113
+ logger.debug "loading fixtures: { dir: #{fixtures_dir}, files: #{fixture_files} }"
114
+ ActiveRecord::FixtureSet.reset_cache
115
+ ActiveRecord::FixtureSet.create_fixtures(fixtures_dir, fixture_files)
107
116
  ```
108
117
 
109
118
  ```js
@@ -111,12 +120,9 @@ CypressDev::SmartFactoryWrapper.configure(
111
120
  describe('My First Test', function() {
112
121
  it('visit root', function() {
113
122
  // This calls to the backend to prepare the application state
114
- cy.appFactories([
115
- ['create_list', 'post', 10],
116
- ['create', 'post', {title: 'Hello World'} ]
117
- ])
123
+ cy.appFixtures()
118
124
 
119
- // The application unter test is available at SERVER_PORT
125
+ // Visit the application under test
120
126
  cy.visit('/')
121
127
 
122
128
  cy.contains("Hello World")
@@ -124,6 +130,34 @@ describe('My First Test', function() {
124
130
  })
125
131
  ```
126
132
 
133
+ ### Example of using scenarios
134
+
135
+ Scenarios are named `before` blocks that you can reference in your test.
136
+
137
+ You define a scenario in the `spec/cypress/app_commands/scenarios` directory:
138
+ ```ruby
139
+ # spec/cypress/app_commands/scenarios/basic.rb
140
+ Profile.create name: "Cypress Hill"
141
+
142
+ # or if you have factory_bot enabled in your cypress_helper
143
+ CypressDev::SmartFactoryWrapper.create(:profile, name: "Cypress Hill")
144
+ ```
145
+
146
+ Then reference the scenario in your test:
147
+ ```js
148
+ // spec/cypress/integrations/scenario_example_spec.js
149
+ describe('My First Test', function() {
150
+ it('visit root', function() {
151
+ // This calls to the backend to prepare the application state
152
+ cy.appScenario('basic')
153
+
154
+ cy.visit('/profiles')
155
+
156
+ cy.contains("Cypress Hill")
157
+ })
158
+ })
159
+ ```
160
+
127
161
  ### Example of using app commands
128
162
 
129
163
  create a ruby file in `spec/cypress/app_commands` directory:
@@ -1,3 +1,3 @@
1
1
  module CypressDev
2
- VERSION = '1.0.1'
2
+ VERSION = '1.1.0'
3
3
  end
@@ -2,6 +2,7 @@ module CypressDev
2
2
  class InstallGenerator < Rails::Generators::Base
3
3
  class_option :cypress_folder, type: :string, default: 'spec/cypress'
4
4
  class_option :install_cypress_with, type: :string, default: 'yarn'
5
+ class_option :install_cypress_examples, type: :boolean, default: true
5
6
  source_root File.expand_path('../templates', __FILE__)
6
7
 
7
8
  def install_cypress
@@ -19,6 +20,10 @@ module CypressDev
19
20
  say command
20
21
  fail 'failed to install cypress' unless system(command)
21
22
  end
23
+ if options.install_cypress_examples
24
+ directory 'spec/cypress/integration/examples', "#{options.cypress_folder}/integration/examples"
25
+ directory 'spec/cypress/fixtures', "#{options.cypress_folder}/fixtures"
26
+ end
22
27
  copy_file "spec/cypress/support/index.js", "#{options.cypress_folder}/support/index.js"
23
28
  copy_file "spec/cypress/support/commands.js", "#{options.cypress_folder}/support/commands.js"
24
29
  copy_file "spec/cypress.json", "#{options.cypress_folder}/../cypress.json"
@@ -28,12 +33,9 @@ module CypressDev
28
33
  def add_initial_files
29
34
  template "config/initializers/cypress_dev.rb.erb", "config/initializers/cypress_dev.rb"
30
35
  copy_file "spec/cypress/cypress_helper.rb", "#{options.cypress_folder}/cypress_helper.rb"
31
- copy_file "spec/cypress/integration/on_rails_spec.js", "#{options.cypress_folder}/integration/on_rails_spec.js"
32
36
  copy_file "spec/cypress/support/on-rails.js", "#{options.cypress_folder}/support/on-rails.js"
33
- copy_file "spec/cypress/app_commands/scenarios/basic.rb", "#{options.cypress_folder}/app_commands/scenarios/basic.rb"
34
- copy_file "spec/cypress/app_commands/clean.rb", "#{options.cypress_folder}/app_commands/clean.rb"
35
- copy_file "spec/cypress/app_commands/eval.rb", "#{options.cypress_folder}/app_commands/eval.rb"
36
- copy_file "spec/cypress/app_commands/factory_bot.rb", "#{options.cypress_folder}/app_commands/factory_bot.rb"
37
+ directory 'spec/cypress/app_commands', "#{options.cypress_folder}/app_commands"
38
+ directory 'spec/cypress/integration/rails_examples', "#{options.cypress_folder}/integration/rails_examples"
37
39
  end
38
40
 
39
41
  def update_files
@@ -0,0 +1,21 @@
1
+ # you can delete this file if you don't use Rails Test Fixtures
2
+
3
+ fixtures_dir = command_options.try(:[], 'fixtures_dir')
4
+ fixture_files = command_options.try(:[], 'fixtures')
5
+
6
+ if defined?(ActiveRecord)
7
+ require "active_record/fixtures"
8
+
9
+ fixtures_dir ||= ActiveRecord::Tasks::DatabaseTasks.fixtures_path
10
+ fixture_files ||= Dir["#{fixtures_dir}/**/*.yml"].map { |f| f[(fixtures_dir.size + 1)..-5] }
11
+
12
+ logger.debug "loading fixtures: { dir: #{fixtures_dir}, files: #{fixture_files} }"
13
+ ActiveRecord::FixtureSet.reset_cache
14
+ ActiveRecord::FixtureSet.create_fixtures(fixtures_dir, fixture_files)
15
+ else # this else part can be removed
16
+ logger.error "Looks like activerecord_fixtures has to be modified to suite your need"
17
+ Post.create(title: 'MyCypressFixtures')
18
+ Post.create(title: 'MyCypressFixtures2')
19
+ Post.create(title: 'MyRailsFixtures')
20
+ Post.create(title: 'MyRailsFixtures2')
21
+ end
@@ -4,4 +4,5 @@ if defined?(DatabaseCleaner)
4
4
  DatabaseCleaner.clean
5
5
  else
6
6
  logger.warn "add database_cleaner or update clean_db"
7
+ Post.delete_all if defined?(Post)
7
8
  end
@@ -1,2 +1,3 @@
1
1
  # You can setup your Rails state here
2
- # MyModel.create name: 'something'
2
+ # MyModel.create name: 'something'
3
+ Post.create(title: 'I am a Postman')
@@ -0,0 +1,5 @@
1
+ {
2
+ "name": "Using fixtures to represent data",
3
+ "email": "hello@cypress.io",
4
+ "body": "Fixtures are a great way to mock data for responses to routes"
5
+ }
@@ -0,0 +1,272 @@
1
+ /// <reference types="Cypress" />
2
+
3
+ context('Actions', () => {
4
+ beforeEach(() => {
5
+ cy.visit('https://example.cypress.io/commands/actions')
6
+ })
7
+
8
+ // https://on.cypress.io/interacting-with-elements
9
+
10
+ it('.type() - type into a DOM element', () => {
11
+ // https://on.cypress.io/type
12
+ cy.get('.action-email')
13
+ .type('fake@email.com').should('have.value', 'fake@email.com')
14
+
15
+ // .type() with special character sequences
16
+ .type('{leftarrow}{rightarrow}{uparrow}{downarrow}')
17
+ .type('{del}{selectall}{backspace}')
18
+
19
+ // .type() with key modifiers
20
+ .type('{alt}{option}') //these are equivalent
21
+ .type('{ctrl}{control}') //these are equivalent
22
+ .type('{meta}{command}{cmd}') //these are equivalent
23
+ .type('{shift}')
24
+
25
+ // Delay each keypress by 0.1 sec
26
+ .type('slow.typing@email.com', { delay: 100 })
27
+ .should('have.value', 'slow.typing@email.com')
28
+
29
+ cy.get('.action-disabled')
30
+ // Ignore error checking prior to type
31
+ // like whether the input is visible or disabled
32
+ .type('disabled error checking', { force: true })
33
+ .should('have.value', 'disabled error checking')
34
+ })
35
+
36
+ it('.focus() - focus on a DOM element', () => {
37
+ // https://on.cypress.io/focus
38
+ cy.get('.action-focus').focus()
39
+ .should('have.class', 'focus')
40
+ .prev().should('have.attr', 'style', 'color: orange;')
41
+ })
42
+
43
+ it('.blur() - blur off a DOM element', () => {
44
+ // https://on.cypress.io/blur
45
+ cy.get('.action-blur').type('About to blur').blur()
46
+ .should('have.class', 'error')
47
+ .prev().should('have.attr', 'style', 'color: red;')
48
+ })
49
+
50
+ it('.clear() - clears an input or textarea element', () => {
51
+ // https://on.cypress.io/clear
52
+ cy.get('.action-clear').type('Clear this text')
53
+ .should('have.value', 'Clear this text')
54
+ .clear()
55
+ .should('have.value', '')
56
+ })
57
+
58
+ it('.submit() - submit a form', () => {
59
+ // https://on.cypress.io/submit
60
+ cy.get('.action-form')
61
+ .find('[type="text"]').type('HALFOFF')
62
+ cy.get('.action-form').submit()
63
+ .next().should('contain', 'Your form has been submitted!')
64
+ })
65
+
66
+ it('.click() - click on a DOM element', () => {
67
+ // https://on.cypress.io/click
68
+ cy.get('.action-btn').click()
69
+
70
+ // You can click on 9 specific positions of an element:
71
+ // -----------------------------------
72
+ // | topLeft top topRight |
73
+ // | |
74
+ // | |
75
+ // | |
76
+ // | left center right |
77
+ // | |
78
+ // | |
79
+ // | |
80
+ // | bottomLeft bottom bottomRight |
81
+ // -----------------------------------
82
+
83
+ // clicking in the center of the element is the default
84
+ cy.get('#action-canvas').click()
85
+
86
+ cy.get('#action-canvas').click('topLeft')
87
+ cy.get('#action-canvas').click('top')
88
+ cy.get('#action-canvas').click('topRight')
89
+ cy.get('#action-canvas').click('left')
90
+ cy.get('#action-canvas').click('right')
91
+ cy.get('#action-canvas').click('bottomLeft')
92
+ cy.get('#action-canvas').click('bottom')
93
+ cy.get('#action-canvas').click('bottomRight')
94
+
95
+ // .click() accepts an x and y coordinate
96
+ // that controls where the click occurs :)
97
+
98
+ cy.get('#action-canvas')
99
+ .click(80, 75) // click 80px on x coord and 75px on y coord
100
+ .click(170, 75)
101
+ .click(80, 165)
102
+ .click(100, 185)
103
+ .click(125, 190)
104
+ .click(150, 185)
105
+ .click(170, 165)
106
+
107
+ // click multiple elements by passing multiple: true
108
+ cy.get('.action-labels>.label').click({ multiple: true })
109
+
110
+ // Ignore error checking prior to clicking
111
+ cy.get('.action-opacity>.btn').click({ force: true })
112
+ })
113
+
114
+ it('.dblclick() - double click on a DOM element', () => {
115
+ // https://on.cypress.io/dblclick
116
+
117
+ // Our app has a listener on 'dblclick' event in our 'scripts.js'
118
+ // that hides the div and shows an input on double click
119
+ cy.get('.action-div').dblclick().should('not.be.visible')
120
+ cy.get('.action-input-hidden').should('be.visible')
121
+ })
122
+
123
+ it('.check() - check a checkbox or radio element', () => {
124
+ // https://on.cypress.io/check
125
+
126
+ // By default, .check() will check all
127
+ // matching checkbox or radio elements in succession, one after another
128
+ cy.get('.action-checkboxes [type="checkbox"]').not('[disabled]')
129
+ .check().should('be.checked')
130
+
131
+ cy.get('.action-radios [type="radio"]').not('[disabled]')
132
+ .check().should('be.checked')
133
+
134
+ // .check() accepts a value argument
135
+ cy.get('.action-radios [type="radio"]')
136
+ .check('radio1').should('be.checked')
137
+
138
+ // .check() accepts an array of values
139
+ cy.get('.action-multiple-checkboxes [type="checkbox"]')
140
+ .check(['checkbox1', 'checkbox2']).should('be.checked')
141
+
142
+ // Ignore error checking prior to checking
143
+ cy.get('.action-checkboxes [disabled]')
144
+ .check({ force: true }).should('be.checked')
145
+
146
+ cy.get('.action-radios [type="radio"]')
147
+ .check('radio3', { force: true }).should('be.checked')
148
+ })
149
+
150
+ it('.uncheck() - uncheck a checkbox element', () => {
151
+ // https://on.cypress.io/uncheck
152
+
153
+ // By default, .uncheck() will uncheck all matching
154
+ // checkbox elements in succession, one after another
155
+ cy.get('.action-check [type="checkbox"]')
156
+ .not('[disabled]')
157
+ .uncheck().should('not.be.checked')
158
+
159
+ // .uncheck() accepts a value argument
160
+ cy.get('.action-check [type="checkbox"]')
161
+ .check('checkbox1')
162
+ .uncheck('checkbox1').should('not.be.checked')
163
+
164
+ // .uncheck() accepts an array of values
165
+ cy.get('.action-check [type="checkbox"]')
166
+ .check(['checkbox1', 'checkbox3'])
167
+ .uncheck(['checkbox1', 'checkbox3']).should('not.be.checked')
168
+
169
+ // Ignore error checking prior to unchecking
170
+ cy.get('.action-check [disabled]')
171
+ .uncheck({ force: true }).should('not.be.checked')
172
+ })
173
+
174
+ it('.select() - select an option in a <select> element', () => {
175
+ // https://on.cypress.io/select
176
+
177
+ // Select option(s) with matching text content
178
+ cy.get('.action-select').select('apples')
179
+
180
+ cy.get('.action-select-multiple')
181
+ .select(['apples', 'oranges', 'bananas'])
182
+
183
+ // Select option(s) with matching value
184
+ cy.get('.action-select').select('fr-bananas')
185
+
186
+ cy.get('.action-select-multiple')
187
+ .select(['fr-apples', 'fr-oranges', 'fr-bananas'])
188
+ })
189
+
190
+ it('.scrollIntoView() - scroll an element into view', () => {
191
+ // https://on.cypress.io/scrollintoview
192
+
193
+ // normally all of these buttons are hidden,
194
+ // because they're not within
195
+ // the viewable area of their parent
196
+ // (we need to scroll to see them)
197
+ cy.get('#scroll-horizontal button')
198
+ .should('not.be.visible')
199
+
200
+ // scroll the button into view, as if the user had scrolled
201
+ cy.get('#scroll-horizontal button').scrollIntoView()
202
+ .should('be.visible')
203
+
204
+ cy.get('#scroll-vertical button')
205
+ .should('not.be.visible')
206
+
207
+ // Cypress handles the scroll direction needed
208
+ cy.get('#scroll-vertical button').scrollIntoView()
209
+ .should('be.visible')
210
+
211
+ cy.get('#scroll-both button')
212
+ .should('not.be.visible')
213
+
214
+ // Cypress knows to scroll to the right and down
215
+ cy.get('#scroll-both button').scrollIntoView()
216
+ .should('be.visible')
217
+ })
218
+
219
+ it('cy.scrollTo() - scroll the window or element to a position', () => {
220
+
221
+ // https://on.cypress.io/scrollTo
222
+
223
+ // You can scroll to 9 specific positions of an element:
224
+ // -----------------------------------
225
+ // | topLeft top topRight |
226
+ // | |
227
+ // | |
228
+ // | |
229
+ // | left center right |
230
+ // | |
231
+ // | |
232
+ // | |
233
+ // | bottomLeft bottom bottomRight |
234
+ // -----------------------------------
235
+
236
+ // if you chain .scrollTo() off of cy, we will
237
+ // scroll the entire window
238
+ cy.scrollTo('bottom')
239
+
240
+ cy.get('#scrollable-horizontal').scrollTo('right')
241
+
242
+ // or you can scroll to a specific coordinate:
243
+ // (x axis, y axis) in pixels
244
+ cy.get('#scrollable-vertical').scrollTo(250, 250)
245
+
246
+ // or you can scroll to a specific percentage
247
+ // of the (width, height) of the element
248
+ cy.get('#scrollable-both').scrollTo('75%', '25%')
249
+
250
+ // control the easing of the scroll (default is 'swing')
251
+ cy.get('#scrollable-vertical').scrollTo('center', { easing: 'linear' })
252
+
253
+ // control the duration of the scroll (in ms)
254
+ cy.get('#scrollable-both').scrollTo('center', { duration: 2000 })
255
+ })
256
+
257
+ it('.trigger() - trigger an event on a DOM element', () => {
258
+ // https://on.cypress.io/trigger
259
+
260
+ // To interact with a range input (slider)
261
+ // we need to set its value & trigger the
262
+ // event to signal it changed
263
+
264
+ // Here, we invoke jQuery's val() method to set
265
+ // the value and trigger the 'change' event
266
+ cy.get('.trigger-input-range')
267
+ .invoke('val', 25)
268
+ .trigger('change')
269
+ .get('input[type=range]').siblings('p')
270
+ .should('have.text', '25')
271
+ })
272
+ })