You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

module_copy_firefox.py 2.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. """
  2. mbed SDK
  3. Copyright (c) 2011-2013 ARM Limited
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.apache.org/licenses/LICENSE-2.0
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. """
  14. from os.path import join, basename
  15. from host_test_plugins import HostTestPluginBase
  16. class HostTestPluginCopyMethod_Firefox(HostTestPluginBase):
  17. def file_store_firefox(self, file_path, dest_disk):
  18. try:
  19. from selenium import webdriver
  20. profile = webdriver.FirefoxProfile()
  21. profile.set_preference('browser.download.folderList', 2) # custom location
  22. profile.set_preference('browser.download.manager.showWhenStarting', False)
  23. profile.set_preference('browser.download.dir', dest_disk)
  24. profile.set_preference('browser.helperApps.neverAsk.saveToDisk', 'application/octet-stream')
  25. # Launch browser with profile and get file
  26. browser = webdriver.Firefox(profile)
  27. browser.get(file_path)
  28. browser.close()
  29. except:
  30. return False
  31. return True
  32. # Plugin interface
  33. name = 'HostTestPluginCopyMethod_Firefox'
  34. type = 'CopyMethod'
  35. capabilities = ['firefox']
  36. required_parameters = ['image_path', 'destination_disk']
  37. def setup(self, *args, **kwargs):
  38. """ Configure plugin, this function should be called before plugin execute() method is used.
  39. """
  40. try:
  41. from selenium import webdriver
  42. except ImportError, e:
  43. self.print_plugin_error("Error: firefox copy method requires selenium library. %s"% e)
  44. return False
  45. return True
  46. def execute(self, capabilitity, *args, **kwargs):
  47. """ Executes capability by name.
  48. Each capability may directly just call some command line
  49. program or execute building pythonic function
  50. """
  51. result = False
  52. if self.check_parameters(capabilitity, *args, **kwargs) is True:
  53. image_path = kwargs['image_path']
  54. destination_disk = kwargs['destination_disk']
  55. # Prepare correct command line parameter values
  56. image_base_name = basename(image_path)
  57. destination_path = join(destination_disk, image_base_name)
  58. if capabilitity == 'firefox':
  59. self.file_store_firefox(image_path, destination_path)
  60. return result
  61. def load_plugin():
  62. """ Returns plugin available in this module
  63. """
  64. return HostTestPluginCopyMethod_Firefox()