diff options
author | ddavison <ddavison@gitlab.com> | 2019-05-30 02:47:53 +0300 |
---|---|---|
committer | ddavison <ddavison@gitlab.com> | 2019-07-11 02:09:43 +0300 |
commit | 390e0d8906c066996e8bbb14aa5824643f9798f8 (patch) | |
tree | 8b220d1d2e0770bc96cc958ce624043e1ae0885e /qa | |
parent | 48fa47e07d54979b70704beb16ea55548f2190c4 (diff) |
Introduce data-qa-selector to supplant .qa-class
In order to break away from using CSS classes as
our primary method of element identification, we
need to provide the ability to search for data
attributes.
Make Test::Sanity::Selectors now work
Utilize regex to match on literal strings of the element name
Suggest the data-qa-selector pattern vs the qa-
Add data-qa-selector to login page to start
We need a page that is heavily used in order to be
confident that this functionality works. Let's start
with the Login page
Use appropriate HAML data tag practices
Diffstat (limited to 'qa')
-rw-r--r-- | qa/qa/page/element.rb | 4 | ||||
-rw-r--r-- | qa/spec/page/element_spec.rb | 13 |
2 files changed, 14 insertions, 3 deletions
diff --git a/qa/qa/page/element.rb b/qa/qa/page/element.rb index 7a01320901d..f9aa9cc6377 100644 --- a/qa/qa/page/element.rb +++ b/qa/qa/page/element.rb @@ -28,7 +28,7 @@ module QA end def selector_css - ".#{selector}" + "[data-qa-selector='#{@name}'],.#{selector}" end def expression @@ -40,7 +40,7 @@ module QA end def matches?(line) - !!(line =~ expression) + !!(line =~ /["']#{name}['"]|#{expression}/) end end end diff --git a/qa/spec/page/element_spec.rb b/qa/spec/page/element_spec.rb index f746fe06e40..87c9fbf74a3 100644 --- a/qa/spec/page/element_spec.rb +++ b/qa/spec/page/element_spec.rb @@ -11,7 +11,7 @@ describe QA::Page::Element do describe '#selector_css' do it 'transforms element name into QA-specific clickable css selector' do expect(described_class.new(:sign_in_button).selector_css) - .to eq '.qa-sign-in-button' + .to include('.qa-sign-in-button') end end @@ -49,6 +49,10 @@ describe QA::Page::Element do it 'does not match if QA selector is not there' do expect(subject.matches?('some_name selector')).to be false end + + it 'matches when element name is specified' do + expect(subject.matches?('data:{qa:{selector:"some_name"}}')).to be true + end end describe 'attributes' do @@ -106,4 +110,11 @@ describe QA::Page::Element do end end end + + describe 'data-qa selectors' do + subject { described_class.new(:my_element) } + it 'properly translates to a data-qa-selector' do + expect(subject.selector_css).to include("[data-qa-selector='my_element']") + end + end end |