Reduce duplication in QA page elements-related code

This commit is contained in:
Grzegorz Bizon 2018-01-09 14:28:10 +01:00
parent 65615776eb
commit 7725a7071d
4 changed files with 14 additions and 3 deletions

View File

@ -41,7 +41,7 @@ module QA
end
def click_element(name)
find("qa-#{name.tr('_', '-')}").click
find(Page::Element.new(name).selector).click
end
def self.path

View File

@ -5,7 +5,11 @@ module QA
def initialize(name, pattern = nil)
@name = name
@pattern = pattern || "qa-#{@name.to_s.tr('_', '-')}"
@pattern = pattern || selector
end
def selector
"qa-#{@name.to_s.tr('_', '-')}"
end
def expression

View File

@ -17,7 +17,7 @@ module QA
STDERR.puts <<~EOS
GitLab QA sanity selectors validation test detected problems
your merge request!
with your merge request!
The purpose of this test is to make sure that GitLab QA tests,
that are entirely black-box, click-driven scenarios, do match

View File

@ -1,4 +1,11 @@
describe QA::Page::Element do
describe '#selector' do
it 'transform element name into QA-specific selector' do
expect(described_class.new(:sign_in_button).selector)
.to eq 'qa-sign-in-button'
end
end
context 'when pattern is an expression' do
subject { described_class.new(:something, /button 'Sign in'/) }