Skip to content

Use let to initialise key to avoid reusing same key name on retry

John McDonnell requested to merge jmd-fix-ssh-key-support-spec-retry into master

What does this MR do and why?

Fixes: #370107 (closed) #327651 (closed)

Currently if this spec fails for some reason, when it retries the test it will reuse the same key_title. While this may allow the 'user can add an SSH key' spec to pass - it them causes failures in can delete an ssh key

Ambiguous match, found 2 elements matching visible link "E2E test key: key for ssh tests 1660046708.1086028"

We should instead use let to create this key_title so if the test fails, we can rerun it with a new name to avoid the ambiguous errors.

How to set up and validate locally

We need to force the spec to fail the first time it runs - I found it easiest to test this by manually adding a sleep, and then when the test was waiting, I manually navigated away to a random page http://gdk.test/abc/def so the assertion failed the first time. I then let it run as normal for the 'retry'.

      it 'user can add an SSH key', testcase: 'https://gitlab.com/gitlab-org/gitlab/-/quality/test_cases/347819' do
        key = Resource::SSHKey.fabricate_via_browser_ui! do |resource|
          resource.title = key_title
        end
        sleep 10
        expect(page).to have_content(key.title)
        expect(page).to have_content(key.sha256_fingerprint)
      end
  1. export CI=true (to allow rerunning tests)
  2. Run the test with export WEBDRIVER_HEADLESS=false
  3. Run with bundle exec bin/qa Test::Instance::All http://gdk.test:3000 -- qa/specs/features/browser_ui/3_create/repository/ssh_key_support_spec.rb
  4. When the test fails, it should retry - note prior to this change the key title is reused causing Ambiguous errors. With this change a new key title is used for the retry attempt.

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by John McDonnell

Merge request reports

Loading