summaryrefslogtreecommitdiff
path: root/qa
diff options
context:
space:
mode:
Diffstat (limited to 'qa')
-rw-r--r--qa/qa.rb1
-rw-r--r--qa/qa/flow/login.rb3
-rw-r--r--qa/qa/page/base.rb30
-rw-r--r--qa/qa/page/main/login.rb8
-rw-r--r--qa/qa/page/main/terms.rb21
-rw-r--r--qa/qa/page/project/web_ide/edit.rb2
-rw-r--r--qa/qa/page/validatable.rb4
-rw-r--r--qa/qa/specs/features/browser_ui/3_create/web_ide/review_merge_request_spec.rb3
-rw-r--r--qa/spec/page/base_spec.rb72
9 files changed, 138 insertions, 6 deletions
diff --git a/qa/qa.rb b/qa/qa.rb
index ed425e205e3..af418033252 100644
--- a/qa/qa.rb
+++ b/qa/qa.rb
@@ -168,6 +168,7 @@ module QA
autoload :Menu, 'qa/page/main/menu'
autoload :OAuth, 'qa/page/main/oauth'
autoload :SignUp, 'qa/page/main/sign_up'
+ autoload :Terms, 'qa/page/main/terms'
end
module Settings
diff --git a/qa/qa/flow/login.rb b/qa/qa/flow/login.rb
index 5505fabd4ae..8ad303df4de 100644
--- a/qa/qa/flow/login.rb
+++ b/qa/qa/flow/login.rb
@@ -10,9 +10,10 @@ module QA
sign_in(as: as, address: address)
- yield
+ result = yield
Page::Main::Menu.perform(&:sign_out)
+ result
end
def while_signed_in_as_admin(address: :gitlab)
diff --git a/qa/qa/page/base.rb b/qa/qa/page/base.rb
index 4ccf9e2f168..42208f05c89 100644
--- a/qa/qa/page/base.rb
+++ b/qa/qa/page/base.rb
@@ -14,6 +14,20 @@ module QA
ElementNotFound = Class.new(RuntimeError)
+ class NoRequiredElementsError < RuntimeError
+ def initialize(page_class)
+ @page_class = page_class
+ super
+ end
+
+ def to_s
+ <<~MSG.strip % { page: @page_class }
+ %{page} has no required elements.
+ See https://docs.gitlab.com/ee/development/testing_guide/end_to_end/dynamic_element_validation.html#required-elements
+ MSG
+ end
+ end
+
def_delegators :evaluator, :view, :views
def initialize
@@ -250,6 +264,8 @@ module QA
end
def element_selector_css(name, *attributes)
+ return name.selector_css if name.is_a? Page::Element
+
Page::Element.new(name, *attributes).selector_css
end
@@ -296,10 +312,24 @@ module QA
views.flat_map(&:elements)
end
+ def self.required_elements
+ elements.select(&:required?)
+ end
+
def send_keys_to_element(name, keys)
find_element(name).send_keys(keys)
end
+ def visible?
+ raise NoRequiredElementsError.new(self.class) if self.class.required_elements.empty?
+
+ self.class.required_elements.each do |required_element|
+ return false if has_no_element? required_element
+ end
+
+ true
+ end
+
class DSL
attr_reader :views
diff --git a/qa/qa/page/main/login.rb b/qa/qa/page/main/login.rb
index 0638097a7b7..8eb28eb53e7 100644
--- a/qa/qa/page/main/login.rb
+++ b/qa/qa/page/main/login.rb
@@ -159,7 +159,13 @@ module QA
fill_element :login_field, user.username
fill_element :password_field, user.password
- click_element :sign_in_button, !skip_page_validation && Page::Main::Menu
+ click_element :sign_in_button
+
+ Page::Main::Terms.perform do |terms|
+ terms.accept_terms if terms.visible?
+ end
+
+ Page::Main::Menu.validate_elements_present! unless skip_page_validation
end
def set_initial_password_if_present
diff --git a/qa/qa/page/main/terms.rb b/qa/qa/page/main/terms.rb
new file mode 100644
index 00000000000..a4928f24397
--- /dev/null
+++ b/qa/qa/page/main/terms.rb
@@ -0,0 +1,21 @@
+# frozen_string_literal: true
+
+module QA
+ module Page::Main
+ class Terms < Page::Base
+ view 'app/views/layouts/terms.html.haml' do
+ element :user_avatar, required: true
+ end
+
+ view 'app/views/users/terms/index.html.haml' do
+ element :terms_content, required: true
+
+ element :accept_terms_button
+ end
+
+ def accept_terms
+ click_element :accept_terms_button, Page::Main::Menu
+ end
+ end
+ end
+end
diff --git a/qa/qa/page/project/web_ide/edit.rb b/qa/qa/page/project/web_ide/edit.rb
index a9b82ac6046..7809f9246ec 100644
--- a/qa/qa/page/project/web_ide/edit.rb
+++ b/qa/qa/page/project/web_ide/edit.rb
@@ -120,10 +120,12 @@ module QA
def add_to_modified_content(content)
finished_loading?
+ modified_text_area.click
modified_text_area.set content
end
def modified_text_area
+ wait_for_animated_element(:editor_container)
within_element(:editor_container) do
find('.modified textarea.inputarea')
end
diff --git a/qa/qa/page/validatable.rb b/qa/qa/page/validatable.rb
index f09a9aa9943..31ac6f71790 100644
--- a/qa/qa/page/validatable.rb
+++ b/qa/qa/page/validatable.rb
@@ -10,9 +10,7 @@ module QA
base_page.wait_if_retry_later
- elements.each do |element|
- next unless element.required?
-
+ required_elements.each do |element|
unless base_page.has_element?(element.name, wait: QA::Support::Repeater::DEFAULT_MAX_WAIT_TIME)
raise Validatable::PageValidationError, "#{element.name} did not appear on #{self.name} as expected"
end
diff --git a/qa/qa/specs/features/browser_ui/3_create/web_ide/review_merge_request_spec.rb b/qa/qa/specs/features/browser_ui/3_create/web_ide/review_merge_request_spec.rb
index c37ad6d4318..8ea1534492c 100644
--- a/qa/qa/specs/features/browser_ui/3_create/web_ide/review_merge_request_spec.rb
+++ b/qa/qa/specs/features/browser_ui/3_create/web_ide/review_merge_request_spec.rb
@@ -4,12 +4,13 @@ module QA
context 'Create', quarantine: { type: :new } do
describe 'Review a merge request in Web IDE' do
let(:new_file) { 'awesome_new_file.txt' }
+ let(:original_text) { 'Text' }
let(:review_text) { 'Reviewed ' }
let(:merge_request) do
Resource::MergeRequest.fabricate_via_api! do |mr|
mr.file_name = new_file
- mr.file_content = 'Text'
+ mr.file_content = original_text
end
end
diff --git a/qa/spec/page/base_spec.rb b/qa/spec/page/base_spec.rb
index f6080bcad49..0cbb0a2b12e 100644
--- a/qa/spec/page/base_spec.rb
+++ b/qa/spec/page/base_spec.rb
@@ -107,4 +107,76 @@ describe QA::Page::Base do
end
end
end
+
+ context 'elements' do
+ subject do
+ Class.new(described_class) do
+ view 'path/to/some/view.html.haml' do
+ element :something, required: true
+ element :something_else
+ end
+ end
+ end
+
+ describe '#elements' do
+ it 'returns all elements' do
+ expect(subject.elements.size).to eq(2)
+ end
+ end
+
+ describe '#required_elements' do
+ it 'returns only required elements' do
+ expect(subject.required_elements.size).to eq(1)
+ end
+ end
+
+ describe '#visible?', 'Page is currently visible' do
+ let(:page) { subject.new }
+
+ context 'with elements' do
+ context 'on the page' do
+ before do
+ # required elements not there, meaning not on page
+ allow(page).to receive(:has_no_element?).and_return(false)
+ end
+
+ it 'is visible' do
+ expect(page).to be_visible
+ end
+ end
+
+ context 'not on the page' do
+ before do
+ # required elements are not on the page
+ allow(page).to receive(:has_no_element?).and_return(true)
+ end
+
+ it 'is not visible' do
+ expect(page).not_to be_visible
+ end
+ end
+
+ it 'does not raise error if page has elements' do
+ expect { page.visible? }.not_to raise_error
+ end
+ end
+
+ context 'no elements' do
+ subject do
+ Class.new(described_class) do
+ view 'path/to/some/view.html.haml' do
+ element :something
+ element :something_else
+ end
+ end
+ end
+
+ let(:page) { subject.new }
+
+ it 'raises error if page has no required elements' do
+ expect { page.visible? }.to raise_error(described_class::NoRequiredElementsError)
+ end
+ end
+ end
+ end
end