diff options
author | Lin Jen-Shin <godfat@godfat.org> | 2018-01-30 14:50:17 +0000 |
---|---|---|
committer | Lin Jen-Shin <godfat@godfat.org> | 2018-01-30 14:50:17 +0000 |
commit | 07557a946bac1b596a28293d39e7bd2581ff828b (patch) | |
tree | f725f935880b122862880f9f18d18fb74a7f758b /qa/qa/page/base.rb | |
parent | bf01452cc361842dab7442a9ad868213d53bd212 (diff) | |
parent | 03f386c2b20f95272e4846f5ecab54fd8b2566e0 (diff) | |
download | gitlab-ce-qa-define-selectors.tar.gz |
Merge branch 'master' into 'qa-define-selectors'qa-define-selectors
# Conflicts:
# qa/qa/page/group/show.rb
Diffstat (limited to 'qa/qa/page/base.rb')
-rw-r--r-- | qa/qa/page/base.rb | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/qa/qa/page/base.rb b/qa/qa/page/base.rb index f472e8ccc7e..7a2d9731205 100644 --- a/qa/qa/page/base.rb +++ b/qa/qa/page/base.rb @@ -42,6 +42,23 @@ module QA page.within(selector) { yield } if block_given? end + # Returns true if successfully GETs the given URL + # Useful because `page.status_code` is unsupported by our driver, and + # we don't have access to the `response` to use `have_http_status`. + def asset_exists?(url) + page.execute_script <<~JS + xhr = new XMLHttpRequest(); + xhr.open('GET', '#{url}', true); + xhr.send(); + JS + + return false unless wait(time: 0.5, max: 60, reload: false) do + page.evaluate_script('xhr.readyState == XMLHttpRequest.DONE') + end + + page.evaluate_script('xhr.status') == 200 + end + def find_element(name) find(element_selector_css(name)) end @@ -80,6 +97,21 @@ module QA views.map(&:errors).flatten end + # Not tested and not expected to work with multiple dropzones + # instantiated on one page because there is no distinguishing + # attribute per dropzone file field. + def attach_file_to_dropzone(attachment, dropzone_form_container) + filename = File.basename(attachment) + + field_style = { visibility: 'visible', height: '', width: '' } + attach_file(attachment, class: 'dz-hidden-input', make_visible: field_style) + + # Wait for link to be appended to dropzone text + wait(reload: false) do + find("#{dropzone_form_container} textarea").value.match(filename) + end + end + class DSL attr_reader :views |