module KendoPageObjectWidgets module Widgets class KendoMultiSelectComboBox < PageObject::Elements::TextField def clear_all self.parent.click KendoMultiSelectComboBox.clear_values(self) end def set(values) values.each do |value| unless value.empty? self.parent.click self.append(value.strip) sleep 0.5 self.send_keys :enter end end end def self.clear_values(base) list_elements = base.parent.span_elements(:class => 'k-i-close') list_elements.map { |item| item }.each { |li| li.click } end def self.accessor_methods(accessor, name) accessor.send :define_method, "#{name}_option_text" do self.send("open_#{name}") self.send("#{name}_listbox").when_visible(10) self.send("#{name}_listbox").text end accessor.send :define_method, "clear_#{name}" do self.send("open_#{name}") KendoMultiSelectComboBox.clear_values(self.send("#{name}_element")) end accessor.send :define_method, "#{name}=" do |values| values.each do |new_value| unless new_value.empty? send("open_#{name}") list_item = send("#{name}_listbox").list_item_element(text: new_value.strip) list_item.click if list_item.when_present 10 end end end #private accessor.send :define_method, "open_#{name}" do self.send("#{name}_element").parent.click end accessor.send :define_method, "#{name}_listbox" do self.platform.unordered_list_for(:id => "#{self.send("#{name}_id")}_listbox") end accessor.send :define_method, "#{name}_id" do self.send("#{name}_element").attribute('id') end accessor.send :private, "open_#{name}", "#{name}_listbox", "#{name}_id" end end end end