Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
gitlab-ce
Commits
407a8004
Commit
407a8004
authored
Apr 23, 2018
by
Michael Kozono
Committed by
Stan Hu
Apr 23, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Capybara debugging methods to docs
parent
c4ccd776
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
0 deletions
+31
-0
doc/development/testing_guide/best_practices.md
doc/development/testing_guide/best_practices.md
+31
-0
No files found.
doc/development/testing_guide/best_practices.md
View file @
407a8004
...
@@ -63,6 +63,8 @@ writing one](testing_levels.md#consider-not-writing-a-system-test)!
...
@@ -63,6 +63,8 @@ writing one](testing_levels.md#consider-not-writing-a-system-test)!
Sometimes you may need to debug Capybara tests by observing browser behavior.
Sometimes you may need to debug Capybara tests by observing browser behavior.
#### Live debug
You can pause Capybara and view the website on the browser by using the
You can pause Capybara and view the website on the browser by using the
`live_debug`
method in your spec. The current page will be automatically opened
`live_debug`
method in your spec. The current page will be automatically opened
in your default browser.
in your default browser.
...
@@ -90,6 +92,35 @@ Finished in 34.51 seconds (files took 0.76702 seconds to load)
...
@@ -90,6 +92,35 @@ Finished in 34.51 seconds (files took 0.76702 seconds to load)
Note:
`live_debug`
only works on javascript enabled specs.
Note:
`live_debug`
only works on javascript enabled specs.
#### Run `:js` spec in a visible browser
Run the spec with
`CHROME_HEADLESS=0`
, e.g.:
```
CHROME_HEADLESS=0 bundle exec rspec some_spec.rb
```
The test will go by quickly, but this will give you an idea of what's happening.
You can also add
`byebug`
or
`binding.pry`
to pause execution and step through
the test.
#### Screenshots
We use the
`capybara-screenshot`
gem to automatically take a screenshot on
failure. In CI you can download these files as job artifacts.
Also, you can manually take screenshots at any point in a test by adding the
methods below. Be sure to remove them when they are no longer needed! See
https://github.com/mattheworiordan/capybara-screenshot#manual-screenshots for
more.
Add
`screenshot_and_save_page`
in a
`:js`
spec to screenshot what Capybara
"sees", and save the page source.
Add
`screenshot_and_open_image`
in a
`:js`
spec to screenshot what Capybara
"sees", and automatically open the image.
### Fast unit tests
### Fast unit tests
Some classes are well-isolated from Rails and you should be able to test them
Some classes are well-isolated from Rails and you should be able to test them
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment