class Fastlane::Actions::UploadToBrowserstackAppLiveAction

Constants

SUPPORTED_FILE_EXTENSIONS
UPLOAD_API_ENDPOINT

Public Class Methods

authors() click to toggle source
# File lib/fastlane/plugin/browserstack/actions/upload_to_browserstack_app_live_action.rb, line 51
def self.authors
  ["Hitesh Raghuvanshi"]
end
available_options() click to toggle source
# File lib/fastlane/plugin/browserstack/actions/upload_to_browserstack_app_live_action.rb, line 76
def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :browserstack_username,
                                 description: "BrowserStack's username",
                                 optional: false,
                                 is_string: true,
                                 verify_block: proc do |value|
                                   UI.user_error!("No browserstack_username given.") if value.to_s.empty?
                                 end),
    FastlaneCore::ConfigItem.new(key: :browserstack_access_key,
                                 description: "BrowserStack's access key",
                                 optional: false,
                                 is_string: true,
                                 verify_block: proc do |value|
                                   UI.user_error!("No browserstack_access_key given.") if value.to_s.empty?
                                 end),
    FastlaneCore::ConfigItem.new(key: :file_path,
                                 description: "Path to the app file",
                                 optional: true,
                                 is_string: true,
                                 default_value: default_file_path)
  ]
end
default_file_path() click to toggle source
# File lib/fastlane/plugin/browserstack/actions/upload_to_browserstack_app_live_action.rb, line 65
def self.default_file_path
  platform = Actions.lane_context[Actions::SharedValues::PLATFORM_NAME]
  if platform == :ios
    # Shared value for ipa path if it was generated by gym https://docs.fastlane.tools/actions/gym/.
    return Actions.lane_context[Actions::SharedValues::IPA_OUTPUT_PATH]
  else
    # Shared value for apk if it was generated by gradle.
    return Actions.lane_context[Actions::SharedValues::GRADLE_APK_OUTPUT_PATH]
  end
end
description() click to toggle source
# File lib/fastlane/plugin/browserstack/actions/upload_to_browserstack_app_live_action.rb, line 47
def self.description
  "Uploads IPA and APK files to BrowserStack AppLive for running manual tests."
end
details() click to toggle source
# File lib/fastlane/plugin/browserstack/actions/upload_to_browserstack_app_live_action.rb, line 55
def self.details
  "Uploads IPA and APK files to BrowserStack AppLive for running manual tests."
end
example_code() click to toggle source
# File lib/fastlane/plugin/browserstack/actions/upload_to_browserstack_app_live_action.rb, line 104
def self.example_code
  [
    'upload_to_browserstack_app_live',
    'upload_to_browserstack_app_live(
      browserstack_username: ENV["BROWSERSTACK_USERNAME"],
      browserstack_access_key: ENV["BROWSERSTACK_ACCESS_KEY"],
      file_path: "path_to_apk_or_ipa_file"
     )'
  ]
end
is_supported?(platform) click to toggle source
# File lib/fastlane/plugin/browserstack/actions/upload_to_browserstack_app_live_action.rb, line 100
def self.is_supported?(platform)
  [:ios, :android].include?(platform)
end
output() click to toggle source
# File lib/fastlane/plugin/browserstack/actions/upload_to_browserstack_app_live_action.rb, line 59
def self.output
  [
    ['BROWSERSTACK_LIVE_APP_ID', 'App id of uploaded app.']
  ]
end
run(params) click to toggle source
# File lib/fastlane/plugin/browserstack/actions/upload_to_browserstack_app_live_action.rb, line 14
def self.run(params)
  browserstack_username = params[:browserstack_username] # Required
  browserstack_access_key = params[:browserstack_access_key] # Required
  file_path = params[:file_path].to_s # Required

  validate_file_path(file_path)

  UI.message("Uploading app to BrowserStack AppLive...")

  browserstack_app_id = Helper::BrowserstackHelper.upload_file(browserstack_username, browserstack_access_key, file_path, UPLOAD_API_ENDPOINT)

  # Set 'BROWSERSTACK_APP_ID' environment variable, if app upload was successful.
  ENV['BROWSERSTACK_LIVE_APP_ID'] = browserstack_app_id

  UI.success("Successfully uploaded app " + file_path + " to BrowserStack AppLive with app_url : " + browserstack_app_id)

  UI.success("Setting Environment variable BROWSERSTACK_LIVE_APP_ID = " + browserstack_app_id)

  # Setting app id in SharedValues, which can be used by other fastlane actions.
  Actions.lane_context[SharedValues::BROWSERSTACK_LIVE_APP_ID] = browserstack_app_id
end
validate_file_path(file_path) click to toggle source

Validate file_path.

# File lib/fastlane/plugin/browserstack/actions/upload_to_browserstack_app_live_action.rb, line 37
def self.validate_file_path(file_path)
  UI.user_error!("No file found at '#{file_path}'.") unless File.exist?(file_path)

  # Validate file extension.
  file_path_parts = file_path.split(".")
  unless file_path_parts.length > 1 && SUPPORTED_FILE_EXTENSIONS.include?(file_path_parts.last)
    UI.user_error!("file_path is invalid, only files with extensions " + SUPPORTED_FILE_EXTENSIONS.to_s + " are allowed to be uploaded.")
  end
end