Sha256: 2a7859b16a1c958fb1c55a2ee8a6e7c4614e4c847e1837c488c81cfe71b29734

Contents?: true

Size: 1.87 KB

Versions: 11

Compression:

Stored size: 1.87 KB

Contents

require "rest-client"

class Elem < Struct.new(:element_id, :element_name, :element_type); end
class Cello::PageObjects::Recorder
  class << self
    def record args
      page_url = args.shift
      page_source = RestClient.get page_url
      title = page_source.scan(/\<title\>(.*?)\<\/title\>/)[0].to_s.gsub!(/\W+/, ' ').strip!.split(" ").each { |w| w.capitalize! }.join("")
      page = "require 'cello'\n\n"
      page += "class #{title} < Cello::PageObjects::Page\n\n"
      raw_element = Array.new()
      page_source.scan(/\<input(.*?)\>/).each do |raw_element|
        element_object = Elem.new nil, nil, nil
        raw_element.to_s.split(" ").each do |element| 
          element_object.element_type = element.split("=")[1].gsub!(/\W+/, '') if !element.scan(/type/).empty?
          element_object.element_name = element.split("=")[1].gsub!(/\W+/, '') if !element.scan(/name/).empty?
          element_object.element_id = element.split("=")[1].gsub!(/\W+/, '') if !element.scan(/id/).empty?
        end
        raw_element.push element_object if (!element_object.element_type.nil? && (!element_object.element_id.nil? || !element_object.element_name.nil?))
      end

      raw_element.each do |complete_element|
        key = ":id"
        complete_element.element_name = complete_element.element_id if complete_element.element_name.nil? 
        key = ":name" if complete_element.element_id.nil? 
        complete_element.element_id = complete_element.element_name if complete_element.element_id.nil? 
        page += "  element :#{complete_element.element_name}, :#{complete_element.element_type}, #{key} => '#{complete_element.element_id }'\n" if !complete_element.element_type.empty? && !complete_element.element_type != "hidden"
      end
      page += "\n  url(\"#{page_url}\")\n\n"
      page += "end\n"
      File.open("./features/pages/#{title}.rb", 'w') {|f| f.write( page ) }
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
cello-0.0.35 lib/cello/pageobjects/recorder.rb
cello-0.0.34 lib/cello/pageobjects/recorder.rb
cello-0.0.33 lib/cello/pageobjects/recorder.rb
cello-0.0.32 lib/cello/pageobjects/recorder.rb
cello-0.0.31 lib/cello/pageobjects/recorder.rb
cello-0.0.30 lib/cello/pageobjects/recorder.rb
cello-0.0.29 lib/cello/pageobjects/recorder.rb
cello-0.0.28 lib/cello/pageobjects/recorder.rb
cello-0.0.27 lib/cello/pageobjects/recorder.rb
cello-0.0.26 lib/cello/pageobjects/recorder.rb
cello-0.0.25 lib/cello/pageobjects/recorder.rb