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