summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Lapierre <mlapierre@gitlab.com>2019-07-25 17:12:25 +1000
committerMark Lapierre <mlapierre@gitlab.com>2019-07-25 17:12:25 +1000
commit8c5a499cb099333d36501331baf11a43e245a834 (patch)
tree34a69f0b08110af0b44998ab41a32312daddd62e
parent631b499ad17e9363060856c1cf85fe396a11e63f (diff)
downloadgitlab-ce-qa-ml-parallel-tests-fix-failures.tar.gz
Assert SSH key was added before using itqa-ml-parallel-tests-fix-failures
The test would sometimes fail because it added an SSH key via the UI but tried to use it before the server had completed adding it. This also moves the code to delete the SSH key to an after hook so that it runs even if the test fails midway, e.g., if it fails during the push. It also adds an `element_text` method to wrap Capybara's `.text` in a method that we won't have to change later if we switch to a different framework. Finally, it adds an Assertions module that contains assertions we can use where `expect` is not appropriate (and wraps Capybara methods)
-rw-r--r--app/views/profiles/keys/_key_details.html.haml2
-rw-r--r--qa/qa.rb2
-rw-r--r--qa/qa/page/assertions.rb15
-rw-r--r--qa/qa/page/base.rb5
-rw-r--r--qa/qa/page/profile/ssh_key.rb17
-rw-r--r--qa/qa/specs/features/browser_ui/3_create/repository/use_ssh_key_spec.rb22
6 files changed, 55 insertions, 8 deletions
diff --git a/app/views/profiles/keys/_key_details.html.haml b/app/views/profiles/keys/_key_details.html.haml
index 0ef01dec493..df9908f7bb3 100644
--- a/app/views/profiles/keys/_key_details.html.haml
+++ b/app/views/profiles/keys/_key_details.html.haml
@@ -19,7 +19,7 @@
= form_errors(@key, type: 'key') unless @key.valid?
%p
%span.light= _('Fingerprint:')
- %code.key-fingerprint= @key.fingerprint
+ %code.key-fingerprint{ data: { qa_selector: 'key_fingerprint_code' }}= @key.fingerprint
%pre.well-pre
= @key.key
.col-md-12
diff --git a/qa/qa.rb b/qa/qa.rb
index be73776425b..47070fec78a 100644
--- a/qa/qa.rb
+++ b/qa/qa.rb
@@ -126,6 +126,7 @@ module QA
# Needed to execute click-driven-only black-box tests.
#
module Page
+ autoload :Assertions, 'qa/page/assertions'
autoload :Base, 'qa/page/base'
autoload :View, 'qa/page/view'
autoload :Element, 'qa/page/element'
@@ -268,6 +269,7 @@ module QA
autoload :Menu, 'qa/page/profile/menu'
autoload :PersonalAccessTokens, 'qa/page/profile/personal_access_tokens'
autoload :SSHKeys, 'qa/page/profile/ssh_keys'
+ autoload :SSHKey, 'qa/page/profile/ssh_key'
end
module Issuable
diff --git a/qa/qa/page/assertions.rb b/qa/qa/page/assertions.rb
new file mode 100644
index 00000000000..f6ecf0cb061
--- /dev/null
+++ b/qa/qa/page/assertions.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+require 'capybara/dsl'
+
+module QA
+ module Page
+ module Assertions
+ include Capybara::DSL
+
+ def assert_no_content(text)
+ assert_no_text(text)
+ end
+ end
+ end
+end
diff --git a/qa/qa/page/base.rb b/qa/qa/page/base.rb
index 45496c6b245..fab2017379c 100644
--- a/qa/qa/page/base.rb
+++ b/qa/qa/page/base.rb
@@ -8,6 +8,7 @@ module QA
prepend Support::Page::Logging if Runtime::Env.debug?
include Capybara::DSL
include Scenario::Actable
+ include Assertions
extend Validatable
extend SingleForwardable
@@ -69,6 +70,10 @@ module QA
page.evaluate_script('xhr.status') == 200
end
+ def element_text(name)
+ find_element(name).text
+ end
+
def find_element(name, **kwargs)
find(element_selector_css(name), kwargs)
end
diff --git a/qa/qa/page/profile/ssh_key.rb b/qa/qa/page/profile/ssh_key.rb
new file mode 100644
index 00000000000..62db892588b
--- /dev/null
+++ b/qa/qa/page/profile/ssh_key.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+module QA
+ module Page
+ module Profile
+ class SSHKey < Page::Base
+ view 'app/views/profiles/keys/_key_details.html.haml' do
+ element :key_fingerprint_code
+ end
+
+ def fingerprint
+ element_text(:key_fingerprint_code)
+ end
+ end
+ end
+ end
+end
diff --git a/qa/qa/specs/features/browser_ui/3_create/repository/use_ssh_key_spec.rb b/qa/qa/specs/features/browser_ui/3_create/repository/use_ssh_key_spec.rb
index a0251e1c385..191b6dd8001 100644
--- a/qa/qa/specs/features/browser_ui/3_create/repository/use_ssh_key_spec.rb
+++ b/qa/qa/specs/features/browser_ui/3_create/repository/use_ssh_key_spec.rb
@@ -8,6 +8,17 @@ module QA
let(:key_title) { "key for ssh tests #{Time.now.to_f}" }
+ after do
+ Page::Main::Menu.perform(&:click_settings_link)
+ Page::Profile::Menu.perform(&:click_ssh_keys)
+
+ Page::Profile::SSHKeys.perform do |ssh_keys|
+ ssh_keys.remove_key(key_title)
+
+ ssh_keys.assert_no_content(key_title)
+ end
+ end
+
it 'user adds an ssh key and pushes code to the repository' do
Runtime::Browser.visit(:gitlab, Page::Main::Login)
Page::Main::Login.perform(&:sign_in_using_credentials)
@@ -16,6 +27,10 @@ module QA
resource.title = key_title
end
+ Page::Profile::SSHKey.perform do |sshkey|
+ expect(sshkey.fingerprint).to eq(key.fingerprint)
+ end
+
project_push = Resource::Repository::ProjectPush.fabricate! do |push|
push.ssh_key = key
push.file_name = 'README.md'
@@ -27,13 +42,6 @@ module QA
expect(page).to have_content('README.md')
expect(page).to have_content('Test Use SSH Key')
-
- Page::Main::Menu.perform(&:click_settings_link)
- Page::Profile::Menu.perform(&:click_ssh_keys)
-
- Page::Profile::SSHKeys.perform do |ssh_keys|
- ssh_keys.remove_key(key_title)
- end
end
end
end