Module: OnlyofficeWebdriverWrapper::WebdriverHelper

Included in:
WebDriver
Defined in:
lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_helper.rb

Overview

Some additional methods for webdriver

Instance Method Summary collapse

Instance Method Details

#cleanup_download_folderNothing

Perform safe cleanup of download folder

Returns:

  • (Nothing)


30
31
32
33
34
35
36
37
38
39
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_helper.rb', line 30

def cleanup_download_folder
  return unless Dir.exist?(@download_directory)

  if @download_directory.start_with?(Dir.tmpdir)
    FileUtils.remove_dir(@download_directory)
  else
    OnlyofficeLoggerHelper.log("Download directory #{@download_directory} is not at tmp dir. " \
                               'It will be not deleted')
  end
end

#download(file_url) ⇒ String

Download temp file and return it location

Parameters:

  • file_url (String)

    url

Returns:

  • (String)

    path to file



20
21
22
23
24
25
26
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_helper.rb', line 20

def download(file_url)
  data = URI.parse(file_url).open.read
  file = Tempfile.new('onlyoffice-downloaded-file')
  file.write(data.force_encoding('UTF-8'))
  file.close
  file.path
end

#system_screenshot(file_name) ⇒ String

Make screenshot by system methods Works only on Linux

Parameters:

  • file_name (String)

    to export screenshot

Returns:

  • (String)

    result of screenshot command execution



13
14
15
# File 'lib/onlyoffice_webdriver_wrapper/webdriver/webdriver_helper.rb', line 13

def system_screenshot(file_name)
  `import -window root #{file_name}`
end