Class: TestCentricity::Elements::FileField
- Defined in:
- lib/testcentricity_web/web_elements/file_field.rb
Constant Summary
Constants inherited from UIElement
UIElement::CSS_SELECTORS, UIElement::XPATH_SELECTORS
Instance Attribute Summary
Attributes inherited from UIElement
#alt_locator, #base_object, #context, #locator, #locator_type, #mru_driver, #mru_locator, #mru_object, #mru_parent, #name, #original_style, #parent, #type
Instance Method Summary collapse
- #drop_files(files) ⇒ Object
-
#file_attach(file_path) ⇒ Object
:nocov:.
- #file_upload(file_path) ⇒ Object
-
#initialize(name, parent, locator, context) ⇒ FileField
constructor
A new instance of FileField.
- #ng_drop_file(file_path) ⇒ Object
Methods inherited from UIElement
#aria_autocomplete, #aria_busy?, #aria_checked?, #aria_colcount, #aria_controls, #aria_describedby, #aria_disabled?, #aria_expanded?, #aria_haspopup?, #aria_hidden?, #aria_invalid?, #aria_keyshortcuts, #aria_label, #aria_labelledby, #aria_live, #aria_modal?, #aria_multiline?, #aria_multiselectable?, #aria_orientation, #aria_pressed?, #aria_readonly?, #aria_required?, #aria_roledescription, #aria_rowcount, #aria_selected?, #aria_sort, #aria_valuemax, #aria_valuemin, #aria_valuenow, #aria_valuetext, #clear_alt_locator, #click, #click_at, #content_editable?, #count, #crossorigin, #disabled?, #displayed?, #double_click, #drag_and_drop, #drag_by, #enabled?, #exists?, #find_element, #focused?, #get_attribute, #get_locator, #get_locator_type, #get_name, #get_native_attribute, #get_object_type, #get_value, #height, #hidden?, #highlight, #hover, #hover_at, #obscured?, #required?, #reset_mru_cache, #right_click, #role, #scroll_to, #send_keys, #set, #set_alt_locator, #set_locator_type, #style, #tabindex, #title, #unhighlight, #verify_value, #visible?, #wait_until_enabled, #wait_until_exists, #wait_until_gone, #wait_until_hidden, #wait_until_value_changes, #wait_until_value_is, #wait_until_visible, #wait_while_busy, #width, #x, #y
Constructor Details
#initialize(name, parent, locator, context) ⇒ FileField
Returns a new instance of FileField.
4 5 6 7 |
# File 'lib/testcentricity_web/web_elements/file_field.rb', line 4 def initialize(name, parent, locator, context) super @type = :filefield end |
Instance Method Details
#drop_files(files) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/testcentricity_web/web_elements/file_field.rb', line 22 def drop_files(files) js_script = 'fileList = Array();' files.count.times do |i| # generate a fake input selector page.execute_script("if ($('#seleniumUpload#{i}').length == 0) { seleniumUpload#{i} = window.$('<input/>').attr({id: 'seleniumUpload#{i}', type:'file'}).appendTo('body'); }") # attach file to the fake input selector through Capybara attach_file("seleniumUpload#{i}", files[i]) # create the fake js event js_script = "#{js_script} fileList.push(seleniumUpload#{i}.get(0).files[0]);" end # trigger the fake drop event page.execute_script("#{js_script} e = $.Event('drop'); e.originalEvent = {dataTransfer : { files : fileList } }; $('#{@locator}').trigger(e);") end |
#file_attach(file_path) ⇒ Object
:nocov:
16 17 18 19 20 |
# File 'lib/testcentricity_web/web_elements/file_field.rb', line 16 def file_attach(file_path) Capybara.ignore_hidden_elements = false page.attach_file(@locator, file_path) Capybara.ignore_hidden_elements = true end |
#file_upload(file_path) ⇒ Object
9 10 11 12 |
# File 'lib/testcentricity_web/web_elements/file_field.rb', line 9 def file_upload(file_path) obj, = find_element(visible = false) obj.send_keys(file_path) end |
#ng_drop_file(file_path) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/testcentricity_web/web_elements/file_field.rb', line 36 def ng_drop_file(file_path) # generate a fake input selector page.execute_script("fakeFileInput = window.$('<input/>').attr({ id: 'fileFileInput', type: 'file' }).appendTo('body');") # attach file to the fake input selector through Capybara page.attach_file('fakeFileInput', file_path) # create the fake js event js_script = "var scope = angular.element('#{@locator}').scope();" js_script = "#{js_script} scope.files = [fakeFileInput.get(0).files[0]];" # trigger the fake drop event page.execute_script(js_script) end |