module Marta::PublicMethods
Methods that user can use out of the box in SmartPage
Public Class Methods
User can create pageobject class using SmartPage.new
SmartPage
can be created without all the data. But in that case it will be pretty useless until values are provided
The first argument is a class name. It is a constant-like string like “MyClass”. All data provided will be stored in MyClass.json Once it is created that way you can call it like MyClass.new. That argument is totally necessary one
The second argument is a marta's special data hash. By default = {“vars”=>{},“meths”=>{}}. You can take an existing json as well. Notice that rocket like syntax is a must here. It will be changed later
Third parameter is about to show or not default page creation dialog. So it can be true or false
# File lib/marta/public_methods.rb, line 26 def initialize(my_class_name, my_data = ({"vars" => {},"meths" => {}}), will_edit = true) @data ||= my_data @class_name ||= my_class_name @edit_mark ||= will_edit data_vars = Hash.new build_content my_data if will_edit data_vars = page_edit my_class_name, my_data my_data["vars"] = data_vars if data_vars != Hash.new end # We need optimization here very much! build_content my_data end
Public Instance Methods
User can get engine (normally browser instance or iframe element)
# File lib/marta/public_methods.rb, line 58 def engine SettingMaster.engine end
User can define a method for example in a middle of a debug session
# File lib/marta/public_methods.rb, line 42 def method_edit(name) method_name = correct_name(name) exact_name = method_name.to_s + "_exact" data = user_method_dialogs(method_name) define_singleton_method method_name. to_sym do |meth_content=@data['meths'][method_name]| marta_magic_finder(meth_content, method_name) end define_singleton_method exact_name. to_sym do |meth_content=@data['meths'][method_name]| marta_simple_finder(meth_content) end public_send name.to_sym end
method missing hijacking It should be used only for SmartPage
# File lib/marta/public_methods.rb, line 81 def method_missing(method_name, *args, &block) if learn_status method_edit(method_name)# , *args, &block) else default_method_missing(method_name, *args, &block) end end
If page has url variable it can be opened like Page.new.open_page
# File lib/marta/public_methods.rb, line 63 def open_page(url = nil) @path ||= "" if !url.nil? engine.goto url elsif !@url.nil? and @url != "" engine.goto @url elsif base_url != "" engine.goto base_url + ((@path == "") ? "" : "/#{@path}") else raise ArgumentError, "You should set url to use open_page. You may"\ " also use base_url option for dance_with and path for page object" end self end