class Object

Constants

FeatureMemory

Public Instance Methods

camelize(string) click to toggle source
# File lib/helpers/sunomono_helpers.rb, line 72
def camelize(string)
  camelized = ''

  string.split('_').each do |s|
    camelized += s.capitalize
  end

  camelized
end
copy_all_project_files(dir) click to toggle source

Copies all folders and files from specs that are valid in AWS context

# File lib/helpers/sunomono_helpers.rb, line 122
def copy_all_project_files(dir)
  directory FileUtils.pwd, dir,
            exclude_pattern: /(.git|.DS_Store|.irb-history|.gitignore|.gitkeep|screenshot|.apk|.zip)/
  # Replacing launcher files to avoid problems with AWS Device Farm
  copy_file File.join(File.dirname(__FILE__), '..', 'aws',
                      'android', 'app_installation_hooks.rb'),
            File.join(dir, 'features', 'android',
                      'support', 'app_installation_hooks.rb'),
            force: true
  copy_file File.join(File.dirname(__FILE__), '..', 'aws',
                      'android', 'app_life_cycle_hooks.rb'),
            File.join(dir, 'features', 'android',
                      'support', 'app_life_cycle_hooks.rb'),
            force: true
  copy_file File.join(File.dirname(__FILE__), '..', 'aws',
                      'ios', '01_launch.rb'),
            File.join(dir, 'features', 'ios',
                      'support', '01_launch.rb'),
            force: true
end
create_appium_screen_file(name, platform) click to toggle source
# File lib/helpers/sunomono_helpers.rb, line 60
def create_appium_screen_file(name, platform)
  # options used to generate the file in the template function
  opts = { name: camelize(name), platform: platform }

  # Thor creates a file based on the templates/appium_screen.tt template
  template('appium_screen',
           File.join(
               FileUtils.pwd, 'features', platform.downcase, 'screens',
               "#{name.downcase}_screen.rb"
           ), opts)
end
create_feature_file(name, platform = nil) click to toggle source
# File lib/helpers/sunomono_helpers.rb, line 3
def create_feature_file(name, platform = nil)
  # options used to generate the file in the template function
  opts = { name: camelize(name) }

  # If platform is not nil than the feature is OS dependent
  file_path = ''
  if platform.nil?
    file_path = File.join(FileUtils.pwd, 'features', "#{name.downcase}.feature")
    opts[:platform] = ''
  else
    file_path = File.join(
      FileUtils.pwd, 'features', platform.downcase, 'features',
      "#{name.downcase}.feature"
    )
    opts[:platform] = platform
  end

  # Thor creates a file based on the templates/feature.tt template
  template('feature', file_path, opts)
end
create_screen_file(name, platform) click to toggle source
# File lib/helpers/sunomono_helpers.rb, line 48
def create_screen_file(name, platform)
  # options used to generate the file in the template function
  opts = { name: camelize(name), platform: platform }

  # Thor creates a file based on the templates/screen.tt template
  template('screen',
           File.join(
             FileUtils.pwd, 'features', platform.downcase, 'screens',
             "#{name.downcase}_screen.rb"
           ), opts)
end
create_screen_shot_dirs(dir) click to toggle source
# File lib/helpers/sunomono_helpers.rb, line 143
def create_screen_shot_dirs(dir)
  Dir.mkdir File.join(dir, 'screenshots')
  Dir.mkdir File.join(dir, 'screenshots', 'ios')
  Dir.mkdir File.join(dir, 'screenshots', 'android')
end
create_steps_file(name, platform = nil) click to toggle source
# File lib/helpers/sunomono_helpers.rb, line 24
def create_steps_file(name, platform = nil)
  # options used to generate the file in the template function
  opts = { name: camelize(name) }

  # If platform is not nil than the step is OS dependent
  file_path = nil
  if platform.nil?
    file_path = File.join(
      FileUtils.pwd, 'features', 'step_definitions',
      "#{name.downcase}_steps.rb"
    )
    opts[:platform] = ''
  else
    file_path = File.join(
      FileUtils.pwd, 'features', platform.downcase, 'step_definitions',
      "#{name.downcase}_steps.rb"
    )
    opts[:platform] = platform
  end

  # Thor creates a file based on the templates/steps.tt template
  template('steps', file_path, opts)
end
create_zip_folder(dir) click to toggle source
# File lib/helpers/sunomono_helpers.rb, line 93
def create_zip_folder(dir)
  file_name = "#{Time.now.strftime('%Y%m%d%H%M%S')}_specs.zip"
  zf = ZipFileGenerator.new(dir, file_name)
  zf.write
  say_status(:create, file_name)
end
device?() click to toggle source
# File lib/skeleton_calabash/features/ios/support/01_launch.rb, line 67
def device?
  # Check if UUID (ENV['DEVICE_TARGET']) is from a device or a simulator
  # Getting all the simulator's UUID
  uuids = `xcrun simctl list`
  return false if uuids.include? ENV['DEVICE_TARGET']
  return true
end
framework_avaliable?(framework) click to toggle source
# File lib/helpers/sunomono_helpers.rb, line 149
def framework_avaliable?(framework)
  if framework.downcase != 'calabash' && framework.downcase != 'appium'
    puts "#{framework} is a invalid framework choice calabash or appium"
    exit 1
  end
end
in_root_project_folder?() click to toggle source
# File lib/helpers/sunomono_helpers.rb, line 82
def in_root_project_folder?
  # Looks if the user is in the root folder of the project
  if !Dir.exist?(File.join(FileUtils.pwd, 'features', 'android', 'features')) ||
     !Dir.exist?(File.join(FileUtils.pwd, 'features', 'ios', 'features'))
    puts 'Please run this command on the root folder of the project'
    exit 1
  end

  true
end
puts_special_chars_error_message(entries) click to toggle source
# File lib/helpers/sunomono_helpers.rb, line 109
def puts_special_chars_error_message(entries)
  puts <<-EOF
There are special chars in your specs.
This can block AWS Device Farm execution.'
Entries found:
#{entries}

To skip this validation use: '--skip-char-validation'
Exiting..."
EOF
end
reinstall_app() click to toggle source
# File lib/skeleton_calabash/features/ios/support/01_launch.rb, line 75
def reinstall_app
  if device?
    system "echo 'Installing the app...'"
    # Trying to reinstall the app
    success = system "ios-deploy -r -b #{ENV['APP_BUNDLE_PATH']} -i #{ENV['DEVICE_TARGET']} -t 5 > /dev/null"

    # If the app is not installed the above command will throw an error
    # So we just install the app
    unless success
      success = system "ios-deploy -b #{ENV['APP_BUNDLE_PATH']} -i #{ENV['DEVICE_TARGET']} -t 5 > /dev/null"
      fail 'Error. Could not install the app.' unless
        success # If there is any error raises an exception
    end

    system "echo 'Installed.'"
    sleep(3) # Gives a time to finish the installation of the app in the device
  end
end
special_chars_in_exported_path?() click to toggle source

Looks for special chars in the specs folder

# File lib/helpers/sunomono_helpers.rb, line 101
def special_chars_in_exported_path?
  entries = `grep -inrE 'á|â|ã|é|ê|í|ó|õ|ô|ú|ç' . --exclude-dir={.git,screenshots,config,support,test_servers} --exclude='*.zip'`
  if entries.count("\n") > 0
    puts_special_chars_error_message(entries)
    exit 1
  end
end