From 10763a9d8845e6fb685418efa8c11bbf7964a87b Mon Sep 17 00:00:00 2001 From: Sanad Liaquat Date: Fri, 18 Jan 2019 18:10:49 +0500 Subject: [PATCH 1/3] Wait for label svg to load --- app/views/shared/empty_states/_labels.html.haml | 2 +- qa/qa/page/label/index.rb | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/views/shared/empty_states/_labels.html.haml b/app/views/shared/empty_states/_labels.html.haml index bee26cd8312..a739103641e 100644 --- a/app/views/shared/empty_states/_labels.html.haml +++ b/app/views/shared/empty_states/_labels.html.haml @@ -1,6 +1,6 @@ .row.empty-state.labels .col-12 - .svg-content + .svg-content.qa-label-svg = image_tag 'illustrations/labels.svg' .col-12 .text-content diff --git a/qa/qa/page/label/index.rb b/qa/qa/page/label/index.rb index 323acd57743..effe8ca0372 100644 --- a/qa/qa/page/label/index.rb +++ b/qa/qa/page/label/index.rb @@ -6,7 +6,17 @@ module QA element :label_create_new end + view 'app/views/shared/empty_states/_labels.html.haml' do + element :label_svg + end + def go_to_new_label + wait(reload: false) do + within_element(:label_svg) do + has_css?('.js-lazy-loaded') + end + end + click_element :label_create_new end end From d74b3cc1867c92a84515397d08c70a2632417636 Mon Sep 17 00:00:00 2001 From: Sanad Liaquat Date: Fri, 18 Jan 2019 18:37:30 +0500 Subject: [PATCH 2/3] Add comments explaining the wait --- qa/qa/page/label/index.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/qa/qa/page/label/index.rb b/qa/qa/page/label/index.rb index effe8ca0372..4eb07a51a81 100644 --- a/qa/qa/page/label/index.rb +++ b/qa/qa/page/label/index.rb @@ -11,10 +11,11 @@ module QA end def go_to_new_label - wait(reload: false) do - within_element(:label_svg) do - has_css?('.js-lazy-loaded') - end + # The 'labels.svg' takes a fraction of a second to load after which the "New label" button shifts up a bit + # This can cause webdriver to miss the hit so we wait for the svg to load (implicitly with has_css?) + # before clicking the button. + within_element(:label_svg) do + has_css?('.js-lazy-loaded') end click_element :label_create_new From 099613f41248f5c6d7ae5f6dfdb7a753e64c30cd Mon Sep 17 00:00:00 2001 From: Sanad Liaquat Date: Fri, 18 Jan 2019 19:12:00 +0500 Subject: [PATCH 3/3] Add qa element --- app/assets/javascripts/lazy_loader.js | 1 + qa/qa/page/label/index.rb | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/lazy_loader.js b/app/assets/javascripts/lazy_loader.js index ee01a73a6e8..66f25b622e0 100644 --- a/app/assets/javascripts/lazy_loader.js +++ b/app/assets/javascripts/lazy_loader.js @@ -163,6 +163,7 @@ export default class LazyLoader { img.removeAttribute('data-src'); img.classList.remove('lazy'); img.classList.add('js-lazy-loaded'); + img.classList.add('qa-js-lazy-loaded'); } } } diff --git a/qa/qa/page/label/index.rb b/qa/qa/page/label/index.rb index 4eb07a51a81..9344371a0b6 100644 --- a/qa/qa/page/label/index.rb +++ b/qa/qa/page/label/index.rb @@ -10,12 +10,16 @@ module QA element :label_svg end + view 'app/assets/javascripts/lazy_loader.js' do + element :js_lazy_loaded + end + def go_to_new_label # The 'labels.svg' takes a fraction of a second to load after which the "New label" button shifts up a bit - # This can cause webdriver to miss the hit so we wait for the svg to load (implicitly with has_css?) + # This can cause webdriver to miss the hit so we wait for the svg to load (implicitly with has_element?) # before clicking the button. within_element(:label_svg) do - has_css?('.js-lazy-loaded') + has_element?(:js_lazy_loaded) end click_element :label_create_new