class Skeleton::Skeleton

Attributes

browser[RW]
bundle_id[RW]
platform[RW]
udid[RW]

Public Class Methods

new(options) click to toggle source
# File lib/skeleton.rb, line 18
def initialize(options)
  self.platform = options.platform
  self.browser = options.browser
  @driver = ios? ? IOS.new(options) : Android.new(options)
end

Public Instance Methods

android?() click to toggle source
# File lib/skeleton.rb, line 86
def android?
  @platform == 'android'
end
attach_image() click to toggle source
# File lib/skeleton.rb, line 63
def attach_image
  screenshot = Dir["#{Base::ATTACHMENTS_FOLDER}/*.png"].first
  image = MiniMagick::Image.new(screenshot)
  image.rotate(90) if image.width > image.height
rescue MiniMagick::Error => err
  Log.warn(err)
ensure
  FileUtils.cp_r(screenshot, "#{Base::ROOT_DIR}/server/screenshot.png")
end
fill_html() click to toggle source
# File lib/skeleton.rb, line 39
def fill_html
                    languages = ios? ? Language.all : Language.all - ['swift']
                    languages.each_with_index do |lang, index|
    attach_image
                            type = Language.domain(lang)
    folder = Base::PAGE_OBJECTS_FOLDER
    begin
                              @screen_objects = File.read(Dir["#{folder}/*.#{type}"].first)
    rescue TypeError
      Log.warn('Failed to find any screen objects 💩') if index.zero?
    end
                            @elements_tree = File.read(Dir["#{folder}/*.xml"].first)
                            @build_version = "v#{VERSION}"
    if @driver.class == Android
      @elements_tree = Nokogiri::XML(@elements_tree).to_s
      @elements_tree.gsub!('<', '&lt;')
      @elements_tree.gsub!('>', '&gt;')
    end
                            template = File.read("#{Base::ROOT_DIR}/server/template.html.erb")
                            result = ERB.new(template).result(binding)
                            File.open("#{Base::ROOT_DIR}/server/#{lang}.html", 'w+') { |f| f.write(result) }
                    end
end
ios?() click to toggle source
# File lib/skeleton.rb, line 82
def ios?
  @platform == 'ios'
end
open_url() click to toggle source
# File lib/skeleton.rb, line 73
def open_url
  port = File.read("#{Base::ROOT_DIR}/server/port")
  url = "http://localhost:#{port}/skeleton"
  `open #{url}` if @browser
  Log.info("Take a peek on #{url} 😍")
rescue Errno::ENOENT
  Log.warn("Something went wrong with skeleton server 💩 \nTry to rerun it (:")
end
platform=(platform) click to toggle source
# File lib/skeleton.rb, line 24
def platform=(platform)
  platform.nil? || platform.downcase!
  if platform != 'ios' && platform != 'android'
    raise 'Set platform, ios or android [-p arg]'
  end
  @platform = platform
end
run() click to toggle source
# File lib/skeleton.rb, line 32
def run
                    @driver.precondition
                    @driver.skeletoner
                    fill_html
                    open_url
end