robotframework-browser-tray 1.1.0__tar.gz → 1.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: robotframework-browser-tray
3
- Version: 1.1.0
3
+ Version: 1.2.0
4
4
  Summary: Tray icon to start the Chromium installed by Browser Library
5
5
  Author-email: Marduk Bolaños <marduk.bolanos@imbus.de>
6
6
  Requires-Python: >=3.8.2
@@ -35,7 +35,9 @@ pip install robotframework-browser-tray
35
35
 
36
36
  2. Execute `browser-tray`
37
37
 
38
- 3. Add these lines to the top of the .robot file with your tests:
38
+ 3. Click on the tray icon with the Chromium logo and select `Open Chromium`
39
+
40
+ 4. Add these lines to the top of the .robot file with your tests:
39
41
 
40
42
  ```robotframework
41
43
  Library Browser playwright_process_port=55555
@@ -25,7 +25,9 @@ pip install robotframework-browser-tray
25
25
 
26
26
  2. Execute `browser-tray`
27
27
 
28
- 3. Add these lines to the top of the .robot file with your tests:
28
+ 3. Click on the tray icon with the Chromium logo and select `Open Chromium`
29
+
30
+ 4. Add these lines to the top of the .robot file with your tests:
29
31
 
30
32
  ```robotframework
31
33
  Library Browser playwright_process_port=55555
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "robotframework-browser-tray"
3
- version = "1.1.0"
3
+ version = "1.2.0"
4
4
  description = "Tray icon to start the Chromium installed by Browser Library"
5
5
  authors = [
6
6
  {name = "Marduk Bolaños", email = "marduk.bolanos@imbus.de"},
@@ -22,4 +22,4 @@ build-backend = "flit_core.buildapi"
22
22
 
23
23
 
24
24
  [tool.pdm]
25
- package-type = "library"
25
+ distribution = true
@@ -14,7 +14,6 @@ _, site_packages = site.getsitepackages()
14
14
  browser_wrapper = Path(site_packages) / "Browser" / "wrapper"
15
15
  index_js = browser_wrapper / "index.js"
16
16
  node_modules = browser_wrapper / "node_modules"
17
- local_browsers = node_modules / "playwright-core" / ".local-browsers"
18
17
 
19
18
 
20
19
  def find_chromium(path: Path) -> list[Path]:
@@ -25,71 +24,78 @@ def find_chromium(path: Path) -> list[Path]:
25
24
  ]
26
25
 
27
26
 
28
- def assert_playwright_initialized():
29
- if not (node_modules.is_dir() and local_browsers.is_dir() and find_chromium(local_browsers)):
30
- raise FileNotFoundError("Playwright has not been initialized. Execute 'rfbrowser init chromium'.")
31
-
32
-
33
- def start_playwright(playwright_process_port: int) -> Popen:
34
- return Popen(f"node {index_js} {playwright_process_port}")
35
-
27
+ def get_chromium_dir(node_modules: Path):
28
+ local_browsers = node_modules / "playwright-core" / ".local-browsers"
36
29
 
37
- def start_chromium(remote_debugging_port: int, incognito=False) -> Popen:
38
- incognito_flag = "-incognito" if incognito else ""
39
- chromium_dir = find_chromium(local_browsers)[0]
40
- chrome_exe = chromium_dir / "chrome-win" / "chrome.exe"
41
- return Popen(f"{chrome_exe} --remote-debugging-port={remote_debugging_port} --test-type {incognito_flag}")
30
+ if not (node_modules.is_dir() and local_browsers.is_dir() and find_chromium(local_browsers)):
31
+ return None
42
32
 
33
+ return find_chromium(local_browsers)[0]
43
34
 
44
- def new_tray_icon(processes: list[Popen], remote_debugging_port: int) -> Icon:
45
- def exit():
46
- for proc in processes:
47
- proc.terminate()
48
35
 
49
- icon.stop()
36
+ def start_playwright(index_js: Path, playwright_process_port: int) -> Popen:
37
+ return Popen(['node', index_js, str(playwright_process_port)])
50
38
 
51
- def open_chromium():
52
- chromium = start_chromium(remote_debugging_port)
53
- processes.append(chromium)
54
39
 
55
- def open_chromium_incognito():
56
- chromium = start_chromium(remote_debugging_port, True)
57
- processes.append(chromium)
40
+ def start_chromium(chromium_dir: Path, remote_debugging_port: int, incognito: bool) -> Popen:
41
+ incognito_flag = ["-incognito"] if incognito else []
42
+ chrome_exe = chromium_dir / "chrome-win" / "chrome.exe"
43
+ return Popen([chrome_exe, f"--remote-debugging-port={remote_debugging_port}", "--test-type"] + incognito_flag)
58
44
 
59
- chromium_icon = Image.open(Path(realpath(__file__)).parent / "chromium.png")
60
45
 
61
- icon = Icon(
46
+ class TrayIcon:
47
+ def __init__(self, processes: list[Popen], chromium_dir: Path, remote_debugging_port: int):
48
+ chromium_icon = Image.open(Path(realpath(__file__)).parent / "chromium.png")
49
+ self.chromium_dir = chromium_dir
50
+ self.processes = processes
51
+ self.remote_debugging_port = remote_debugging_port
52
+ self.icon = Icon(
62
53
  name='Browser Tray',
63
54
  icon=chromium_icon,
64
55
  menu=Menu(
65
56
  MenuItem(
66
57
  'Open Chromium',
67
- open_chromium,
58
+ self.open_chromium,
68
59
  default=True
69
60
  ),
70
61
  MenuItem(
71
62
  'Open Chromium Incognito',
72
- open_chromium_incognito,
63
+ self.open_chromium_incognito,
73
64
  ),
74
65
  MenuItem(
75
66
  'Exit',
76
- exit
67
+ self.exit
77
68
  )
78
69
  )
79
70
  )
80
71
 
81
- return icon
72
+ def exit(self):
73
+ for proc in self.processes:
74
+ proc.terminate()
75
+
76
+ self.icon.stop()
77
+
78
+ def open_chromium(self):
79
+ chromium = start_chromium(self.chromium_dir, self.remote_debugging_port, False)
80
+ self.processes.append(chromium)
81
+
82
+ def open_chromium_incognito(self):
83
+ chromium = start_chromium(self.chromium_dir, self.remote_debugging_port, True)
84
+ self.processes.append(chromium)
85
+
86
+ def run(self):
87
+ self.icon.run()
82
88
 
83
89
 
84
90
  def is_running(cmd: str) -> bool:
85
91
  process_list = subprocess.check_output(
86
- ["TASKLIST", "/FI", f'imagename eq {cmd}'],
92
+ ["TASKLIST", "/V", "/FI", f'imagename eq {cmd}'],
87
93
  encoding="utf-8"
88
94
  ).splitlines()
89
95
  instances = [
90
96
  process
91
97
  for process in process_list
92
- if process.startswith(cmd)
98
+ if process.startswith(cmd) and os.getlogin().lower() in process.lower()
93
99
  ]
94
100
  return len(instances) > 1
95
101
 
@@ -119,8 +125,12 @@ def run():
119
125
  sys.exit(1)
120
126
 
121
127
  playwright_process_port, remote_debugging_port = get_ports()
128
+ chromium_dir = get_chromium_dir(node_modules)
129
+
130
+ if not chromium_dir:
131
+ raise Exception("Playwright has not been initialized. Execute 'rfbrowser init chromium'.")
122
132
 
123
- assert_playwright_initialized()
124
- playwright_process = start_playwright(playwright_process_port)
125
- tray_icon = new_tray_icon([playwright_process], remote_debugging_port)
133
+ playwright_process = start_playwright(index_js, playwright_process_port)
134
+ processes = [playwright_process]
135
+ tray_icon = TrayIcon(processes, chromium_dir, remote_debugging_port)
126
136
  tray_icon.run()