summaryrefslogtreecommitdiff
path: root/doc/development/testing_guide/end_to_end
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-10-31 09:06:29 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2019-10-31 09:06:29 +0000
commit6026bddcd51eca573c530240c421392045172b89 (patch)
tree30cb1134ac00a336e6cfaa81bbafe6cd1360f58f /doc/development/testing_guide/end_to_end
parentb7c776f95d5f41ac00986073563ad0c1de4bad44 (diff)
downloadgitlab-ce-6026bddcd51eca573c530240c421392045172b89.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'doc/development/testing_guide/end_to_end')
-rw-r--r--doc/development/testing_guide/end_to_end/best_practices.md20
1 files changed, 20 insertions, 0 deletions
diff --git a/doc/development/testing_guide/end_to_end/best_practices.md b/doc/development/testing_guide/end_to_end/best_practices.md
index 042879b47aa..e73c6a61fb1 100644
--- a/doc/development/testing_guide/end_to_end/best_practices.md
+++ b/doc/development/testing_guide/end_to_end/best_practices.md
@@ -65,3 +65,23 @@ This library [saves the screenshots in the RSpec's `after` hook](https://github.
Given this fact, we should limit the use of `before(:all)` to only those operations where a screenshot is not
necessary in case of failure and QA logs would be enough for debugging.
+
+## Ensure tests do not leave the browser logged in
+
+All QA tests expect to be able to log in at the start of the test.
+
+That's not possible if a test leaves the browser logged in when it finishes. Normally this isn't a problem because [Capybara resets the session after each test](https://github.com/teamcapybara/capybara/blob/9ebc5033282d40c73b0286e60217515fd1bb0b5d/lib/capybara/rspec.rb#L18). But Capybara does that in an `after` block, so when a test logs in in an `after(:context)` block, the browser returns to a logged in state *after* Capybara had logged it out. And so the next test will fail.
+
+For an example see: <https://gitlab.com/gitlab-org/gitlab/issues/34736>
+
+Ideally, any actions peformed in an `after(:context)` (or [`before(:context)`](#limit-the-use-of-beforeall-hook)) block would be performed via the API. But if it's necessary to do so via the UI (e.g., if API functionality doesn't exist), make sure to log out at the end of the block.
+
+```ruby
+after(:all) do
+ login unless Page::Main::Menu.perform(&:signed_in?)
+
+ # Do something while logged in
+
+ Page::Main::Menu.perform(&:sign_out)
+end
+```