Module: LeapSalesforce::FormFiller
- Included in:
- CreatePage, UpdatePage
- Defined in:
- lib/leap_salesforce_ui/form_filler.rb
Instance Method Summary collapse
-
#error_list ⇒ Watir::Elements::Ul
List of errors.
-
#field_for(desc) ⇒ Hash
Description of field.
-
#form ⇒ Watir::Elements::Div
Div where form entered to create/edit entity.
-
#get_label_for(field) ⇒ Object
Use metadata to get label for field.
-
#populate_with(data) ⇒ Object
Based on data type of field passed, fill in each field The type of field is attempted to be filled in based on the metadata.
-
#save ⇒ Object
Save the current form, creating the new object.
-
#set_picklist(label, value) ⇒ Object
Set value of picklist.
-
#set_reference_field(label, value) ⇒ Object
Set reference field where another entity is referred to by this entity.
-
#set_text_area(label, value) ⇒ Object
Set input text field.
-
#set_text_field(label, value) ⇒ Object
Set input text field.
- #submit_with(data) ⇒ Object
Instance Method Details
#error_list ⇒ Watir::Elements::Ul
Returns List of errors.
125 126 127 |
# File 'lib/leap_salesforce_ui/form_filler.rb', line 125 def error_list browser.ul(xpath: "//ul[contains(@class, 'errorsList') and not(normalize-space()='')]") end |
#field_for(desc) ⇒ Hash
Returns Description of field.
23 24 25 26 27 28 |
# File 'lib/leap_salesforce_ui/form_filler.rb', line 23 def field_for(desc) ruby_desc = @soql_object.accessors[desc.to_sym] return ruby_desc if ruby_desc @soql_object.properties_for(desc) end |
#form ⇒ Watir::Elements::Div
Returns Div where form entered to create/edit entity.
6 7 8 |
# File 'lib/leap_salesforce_ui/form_filler.rb', line 6 def form browser.div(class: "inlinePanel") end |
#get_label_for(field) ⇒ Object
Use metadata to get label for field
12 13 14 15 16 17 18 19 20 |
# File 'lib/leap_salesforce_ui/form_filler.rb', line 12 def get_label_for(field) raise "SoqlObject not defined" unless @soql_object return field if @soql_object.label_names.include? field raise "Cannot find field #{field} on #{@soql_object}" unless @soql_object.accessors[field.to_sym] @soql_object.accessors[field.to_sym][:label] end |
#populate_with(data) ⇒ Object
Based on data type of field passed, fill in each field The type of field is attempted to be filled in based on the metadata
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/leap_salesforce_ui/form_filler.rb', line 33 def populate_with(data) sleep 1 # Being too fast can cause issues with first value. TODO: Wait for a condition data.each do |desc, value| field = field_for(desc) label_name = field[:label] || field["label"] type = field[:type] || field["type"] case type when "string" then set_text_field(label_name, value) when "picklist" then set_picklist(label_name, value) when "textarea" then set_text_area(label_name, value) when "reference" then set_reference_field(label_name, value) else raise NotImplementedError, "#{type} not yet defined in #{self}" end end self end |
#save ⇒ Object
Save the current form, creating the new object
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/leap_salesforce_ui/form_filler.rb', line 130 def save LeapSalesforce.logger.info "Saving form for #{self}" form.(xpath: "//button[@title='Save']|//button[text()='Save']").click form.wait_until do |panel| sleep 1.5 if error_list.exists? errors = error_list.lis error_text = errors.collect(&:text) LeapSalesforce.logger.error "Error submitting #{self} #{error_list.text}" raise LeapSalesforce::SubmitError, "Errors creating on #{self}: #{error_text}" if errors.count.positive? end !panel.present? end end |
#set_picklist(label, value) ⇒ Object
Set value of picklist
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/leap_salesforce_ui/form_filler.rb', line 89 def set_picklist(label, value) LeapSalesforce.logger.info "Setting picklist, label '#{label}' with '#{value}'" field_transaction label, value do dropdown = form.(xpath: "//*[./*[text()='#{label}']]//following-sibling::div//button") dropdown_id = dropdown.attribute "id" LeapSalesforce.logger.debug "Using dropdown id: #{dropdown_id}" dropdown.focus sleep 0.5 dropdown.click has_value = "@data-value='#{value}'" in_dropdown = "starts-with(@data-item-id, '#{dropdown_id}')" browser.element(xpath: ".//lightning-base-combobox-item[#{has_value} and #{in_dropdown}]").click end self end |
#set_reference_field(label, value) ⇒ Object
Set reference field where another entity is referred to by this entity
106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/leap_salesforce_ui/form_filler.rb', line 106 def set_reference_field(label, value) ref_label = label.gsub("ID", "Name") search_val = value[0..12] LeapSalesforce.logger.info "Setting reference field, label '#{ref_label}', searching with '#{search_val}'" field_transaction label, value do search_field = browser.text_field(xpath: "//label[contains(.,'#{ref_label}')]//following-sibling::div[1]//input") search_field.set search_val browser.element(xpath: ".//lightning-base-combobox-item[starts-with(.,'SearchShow')]").click browser.link(xpath: "//div[contains(@class,'searchScroller')]//a[contains(.,'#{search_val}')]").click end self end |
#set_text_area(label, value) ⇒ Object
Set input text field
55 56 57 58 59 60 61 |
# File 'lib/leap_salesforce_ui/form_filler.rb', line 55 def set_text_area(label, value) LeapSalesforce.logger.info "Setting text area, label '#{label}' with '#{value}'" field_transaction label, value do text_area = form.textarea(xpath: "//lightning-textarea[./label[contains(.,'#{label}')]]//following-sibling::div/textarea") text_area.set value end end |
#set_text_field(label, value) ⇒ Object
Set input text field
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/leap_salesforce_ui/form_filler.rb', line 66 def set_text_field(label, value) value = value.to_s LeapSalesforce.logger.info "Setting text field, label '#{label}' with '#{value}'" field_transaction label, value do label_element = form.label(xpath: "//label[contains(.,'#{label}')]") text_field = label_element.text_field(xpath: ".//following-sibling::input|.//following-sibling::div/input") text_field.focus text_field.set! value return self if text_field.value == value sleep 2 # Wait a bit and then set field text_field.set! value unless text_field.value == value raise SetFieldError, "Unable to set text field '#{label}' with value " \ "'#{value}'. Value set is '#{text_field.value}'" end end self end |
#submit_with(data) ⇒ Object
119 120 121 122 |
# File 'lib/leap_salesforce_ui/form_filler.rb', line 119 def submit_with(data) populate_with data save end |