-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathTestCafeBrowsers.py
86 lines (69 loc) · 3.4 KB
/
TestCafeBrowsers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import sublime_plugin
import os
import sys
import json
import copy
sys.path.append(os.path.abspath(os.path.dirname(__file__)))
import ProcessRunner as process_runner
PACKAGE_PATH = os.path.dirname(__file__)
CONTEXT_MENU_FILE_NAME = 'Context.sublime-menu'
SIDE_BAR_FILE_NAME = 'Side Bar.sublime-menu'
COMMANDS_FILE_NAME = 'TestCafe.sublime-commands'
KEYMAP_FILE_NAME = 'Default.sublime-keymap'
TEMPLATES = {
'context_menu': [{'caption': 'TestCafe', 'id': 'testcafe', 'children': [{
'args': {'cmd': 'previous'},
'caption': 'Rerun Previous Tests',
'command': 'test_cafe'
}, {'caption': '-'}]}],
'side_bar_menu': [{'caption': 'TestCafe', 'children': [{
'args': {'cmd': 'previous'},
'caption': 'Rerun Previous Tests',
'command': 'test_cafe',
'mnemonic': 'P'
}, {'caption': '-'}]}],
'keymap': [{'args': {'cmd': 'previous'}, 'command': 'test_cafe',
'keys': ['ctrl+alt+p']}, {'args': {'panel': 'output.testcafe'},
'command': 'show_panel', 'keys': ['ctrl+alt+l']}],
'commands': [{'args': {'panel': 'output.testcafe'}, 'caption': 'TestCafe: Show Output Panel',
'command': 'show_panel'}, {'args': {'cmd': 'previous'}, 'caption': 'TestCafe: Rerun Previous Tests',
'command': 'test_cafe'}]
}
def write_to_file(file_name, content):
f = open(os.path.join(PACKAGE_PATH, file_name), 'w')
f.write(json.dumps(content, sort_keys=True, indent=4, separators=(',', ': ')))
f.close()
def get_browser_list():
proc = process_runner.run('testcafe --list-browsers')
result = proc.communicate()[0]
process_runner.kill(proc)
return result.decode('utf-8').strip().split('\n')
def update_browsers():
browser_list = get_browser_list()
templates = copy.deepcopy(TEMPLATES)
for browser in browser_list:
browserIndex = browser_list.index(browser) + 1
command = {'command': 'test_cafe',
'caption': 'TestCafe: Run in {0}'.format(browser),
'args': {'browser': browser}}
templates['commands'].append(command)
comtext_menu_item = {'command': 'test_cafe',
'caption': 'Run in {0}'.format(browser, browserIndex),
'args': {'browser': browser}}
templates['context_menu'][0]['children'].append(comtext_menu_item)
side_bar_menu_item = {'command': 'test_cafe',
'caption': 'Run in {0}'.format(browser, browserIndex),
'args': {'browser': browser, 'cmd': 'all'}}
templates['side_bar_menu'][0]['children'].append(side_bar_menu_item)
keymap_item = {'command': 'test_cafe', 'keys': ["ctrl+alt+{0}".format(browserIndex)],
'args': {'browser': browser}}
templates['keymap'].append(keymap_item)
write_to_file(KEYMAP_FILE_NAME, templates['keymap'])
write_to_file(COMMANDS_FILE_NAME, templates['commands'])
write_to_file(CONTEXT_MENU_FILE_NAME, templates['context_menu'])
write_to_file(SIDE_BAR_FILE_NAME, templates['side_bar_menu'])
class TestCafeBrowsersCommand(sublime_plugin.WindowCommand):
def run(self):
update_browsers()
if not os.path.isfile(os.path.join(PACKAGE_PATH, COMMANDS_FILE_NAME)):
update_browsers()