From 77d636cc164eebeb119943f62b7ca1b837f878a8 Mon Sep 17 00:00:00 2001 From: Fatih Acet Date: Thu, 12 Oct 2017 21:29:32 +0000 Subject: Add debugging section to testing_guide/best_practices.md. --- doc/development/testing_guide/best_practices.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'doc/development') diff --git a/doc/development/testing_guide/best_practices.md b/doc/development/testing_guide/best_practices.md index 613423dbd9a..b3ce2133161 100644 --- a/doc/development/testing_guide/best_practices.md +++ b/doc/development/testing_guide/best_practices.md @@ -267,6 +267,20 @@ RSpec.configure do |config| end ``` +### Debugging + +If you need to debug Capybara tests, using the following lines, +you can get the current URL of Capybara server, logged in user email. Then you +can add some arbitrary sleep to halt the test and go check out the page. + +Default user password is `12345678`. + +``` +puts current_url +puts user.email +sleep(200) +``` + --- [Return to Testing documentation](index.md) -- cgit v1.2.1 From 88bd5fa274d0b9d9ccd8be26f83d422517880fe3 Mon Sep 17 00:00:00 2001 From: Clement Ho Date: Thu, 12 Oct 2017 21:38:52 +0000 Subject: Update best_practices.md --- doc/development/testing_guide/best_practices.md | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'doc/development') diff --git a/doc/development/testing_guide/best_practices.md b/doc/development/testing_guide/best_practices.md index b3ce2133161..386fe2a35eb 100644 --- a/doc/development/testing_guide/best_practices.md +++ b/doc/development/testing_guide/best_practices.md @@ -267,15 +267,20 @@ RSpec.configure do |config| end ``` -### Debugging +### Debugging Capybara -If you need to debug Capybara tests, using the following lines, -you can get the current URL of Capybara server, logged in user email. Then you -can add some arbitrary sleep to halt the test and go check out the page. +Sometimes you may need to debug Capybara tests by observing browser behavior. -Default user password is `12345678`. +You can stall capybara and view the website on the browser by adding a long sleep command in your spec and then opening your browser +to the capybara url. -``` +You can get the capybara url by doing `puts current_url`. +You can also get the user's email by doing `puts user.email`. + +The default password for the user is `12345678`. + +Example: +```ruby puts current_url puts user.email sleep(200) -- cgit v1.2.1 From 9bccea6e3438e26479e0f38e7833286daa10ed5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Coutable?= Date: Mon, 16 Oct 2017 10:37:53 +0200 Subject: Add LiveDebugger#live_debug to debug Capybara in feature tests. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Rémy Coutable --- doc/development/testing_guide/best_practices.md | 49 +++++++++++++++---------- 1 file changed, 30 insertions(+), 19 deletions(-) (limited to 'doc/development') diff --git a/doc/development/testing_guide/best_practices.md b/doc/development/testing_guide/best_practices.md index 386fe2a35eb..d07a368abfd 100644 --- a/doc/development/testing_guide/best_practices.md +++ b/doc/development/testing_guide/best_practices.md @@ -58,6 +58,36 @@ writing one](testing_levels.md#consider-not-writing-a-system-test)! - It's ok to look for DOM elements but don't abuse it since it makes the tests more brittle +#### Debugging Capybara + +Sometimes you may need to debug Capybara tests by observing browser behavior. + +You can stall Capybara and view the website on the browser by using the +`live_debug` method in your spec. The current page will be automatically opened +in your default browser. +You may need to sign-in first (the current user's credentials are displayed in +the terminal). + +To resume the test run, you only need to press `c`. + +For example: + +```ruby +$ bin/rspec spec/features/auto_deploy_spec.rb:34 +Running via Spring preloader in process 8999 +Run options: include {:locations=>{"./spec/features/auto_deploy_spec.rb"=>[34]}} + +Current example is paused for live debugging +The current user credentials are: user2 / 12345678 +Press 'c' to continue the execution of the example +Please press 'c' to continue the execution of the example! ;) <- I pressed `d` here +Back to the example! +. + +Finished in 34.51 seconds (files took 0.76702 seconds to load) +1 example, 0 failures +``` + ### `let` variables GitLab's RSpec suite has made extensive use of `let` variables to reduce @@ -267,25 +297,6 @@ RSpec.configure do |config| end ``` -### Debugging Capybara - -Sometimes you may need to debug Capybara tests by observing browser behavior. - -You can stall capybara and view the website on the browser by adding a long sleep command in your spec and then opening your browser -to the capybara url. - -You can get the capybara url by doing `puts current_url`. -You can also get the user's email by doing `puts user.email`. - -The default password for the user is `12345678`. - -Example: -```ruby -puts current_url -puts user.email -sleep(200) -``` - --- [Return to Testing documentation](index.md) -- cgit v1.2.1 From a3368a988d9ed90dfe67b34017782d45b5897574 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Coutable?= Date: Tue, 17 Oct 2017 17:42:21 +0200 Subject: Improve the LiveDebugger exit handler and documentation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Rémy Coutable --- doc/development/testing_guide/best_practices.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'doc/development') diff --git a/doc/development/testing_guide/best_practices.md b/doc/development/testing_guide/best_practices.md index d07a368abfd..12e6ec169e0 100644 --- a/doc/development/testing_guide/best_practices.md +++ b/doc/development/testing_guide/best_practices.md @@ -62,10 +62,10 @@ writing one](testing_levels.md#consider-not-writing-a-system-test)! Sometimes you may need to debug Capybara tests by observing browser behavior. -You can stall 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 in your default browser. -You may need to sign-in first (the current user's credentials are displayed in +You may need to sign in first (the current user's credentials are displayed in the terminal). To resume the test run, you only need to press `c`. -- cgit v1.2.1 From 1c17ddba662872bf6ad9a9fe04137023476df50c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Coutable?= Date: Thu, 26 Oct 2017 18:03:33 +0200 Subject: Simplify the live debugger resume mechanism: press any key MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Rémy Coutable --- doc/development/testing_guide/best_practices.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'doc/development') diff --git a/doc/development/testing_guide/best_practices.md b/doc/development/testing_guide/best_practices.md index 12e6ec169e0..bbdeee05579 100644 --- a/doc/development/testing_guide/best_practices.md +++ b/doc/development/testing_guide/best_practices.md @@ -68,7 +68,7 @@ in your default browser. You may need to sign in first (the current user's credentials are displayed in the terminal). -To resume the test run, you only need to press `c`. +To resume the test run, press any key. For example: @@ -79,8 +79,7 @@ Run options: include {:locations=>{"./spec/features/auto_deploy_spec.rb"=>[34]}} Current example is paused for live debugging The current user credentials are: user2 / 12345678 -Press 'c' to continue the execution of the example -Please press 'c' to continue the execution of the example! ;) <- I pressed `d` here +Press any key to resume the execution of the example! Back to the example! . -- cgit v1.2.1 From 0364e074479ac8204365fa6b6109011042431575 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Coutable?= Date: Thu, 2 Nov 2017 12:02:51 +0100 Subject: Address Douwe's feedback MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Rémy Coutable --- doc/development/testing_guide/best_practices.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'doc/development') diff --git a/doc/development/testing_guide/best_practices.md b/doc/development/testing_guide/best_practices.md index bbdeee05579..a165a17f5db 100644 --- a/doc/development/testing_guide/best_practices.md +++ b/doc/development/testing_guide/best_practices.md @@ -72,7 +72,7 @@ To resume the test run, press any key. For example: -```ruby +``` $ bin/rspec spec/features/auto_deploy_spec.rb:34 Running via Spring preloader in process 8999 Run options: include {:locations=>{"./spec/features/auto_deploy_spec.rb"=>[34]}} -- cgit v1.2.1