Class: Maze::Api::Appium::FileManager

Inherits:
Object
  • Object
show all
Defined in:
lib/maze/api/appium/file_manager.rb

Overview

Provides operations for working with files during Appium runs.

Instance Method Summary collapse

Constructor Details

#initializeFileManager

param driver



7
8
9
# File 'lib/maze/api/appium/file_manager.rb', line 7

def initialize
  @driver = Maze.driver
end

Instance Method Details

#read_app_file(filename, directory = nil) ⇒ Object

Attempts to retrieve a given file from the device (using Appium). The default location for the file will be the app’s documents directory for iOS. On Android, it will be /sdcard/Android/data/<app-id>/files unless Maze.config.android_app_files_directory has been set.

Parameters:

  • filename (String)

    Name (with no path) of the file to be retrieved from the device

  • directory (String) (defaults to: nil)

    Directory on the device where the file is located (optional)



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/maze/api/appium/file_manager.rb', line 34

def read_app_file(filename, directory = nil)
  if directory
    path = directory
  else
    path = case Maze::Helper.get_current_platform
          when 'ios'
            "@#{@driver.app_id}/Documents/#{filename}"
          when 'android'
            dir = Maze.config.android_app_files_directory || "/sdcard/Android/data/#{@driver.app_id}/files"
            "#{dir}/#{filename}"
          end
  end

  $logger.trace "Attempting to read file from '#{path}'"
  file = @driver.pull_file(path)
end

#write_app_file(contents, filename) ⇒ Object

Creates a file with the given contents on the device (using Appium). The file will be located in the app’s documents directory for iOS. On Android, it will be /sdcard/Android/data/<app-id>/files unless Maze.config.android_app_files_directory has been set.

Parameters:

  • contents (String)

    Content of the file to be written

  • filename (String)

    Name (with no path) of the file to be written on the device



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/maze/api/appium/file_manager.rb', line 16

def write_app_file(contents, filename)
  path = case Maze::Helper.get_current_platform
         when 'ios'
           "@#{@driver.app_id}/Documents/#{filename}"
         when 'android'
           directory = Maze.config.android_app_files_directory || "/sdcard/Android/data/#{@driver.app_id}/files"
           "#{directory}/#{filename}"
         end

  $logger.trace "Pushing file to '#{path}' with contents: #{contents}"
  @driver.push_file(path, contents)
end