robotframework-browser-tray 1.5.0__tar.gz → 1.5.2__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.5.0
3
+ Version: 1.5.2
4
4
  Summary: Tray icon and REPL for trying out Browser Library keywords using Chromium or Edge
5
5
  Author-email: Marduk Bolaños <marduk.bolanos@imbus.de>
6
6
  Requires-Python: >=3.8.2
@@ -68,6 +68,8 @@ On start up it connects to a running Chromium (started using the tray icon) or M
68
68
 
69
69
  If you start a new browser while ibrowser is running, call the keyword "Connect" to connect ibrowser to it.
70
70
 
71
+ To exit ibrowser press `Ctrl-D`.
72
+
71
73
  ### Usage in a Robot Framework Test Suite
72
74
 
73
75
  Add these lines to the Settings section of the .robot file:
@@ -56,6 +56,8 @@ On start up it connects to a running Chromium (started using the tray icon) or M
56
56
 
57
57
  If you start a new browser while ibrowser is running, call the keyword "Connect" to connect ibrowser to it.
58
58
 
59
+ To exit ibrowser press `Ctrl-D`.
60
+
59
61
  ### Usage in a Robot Framework Test Suite
60
62
 
61
63
  Add these lines to the Settings section of the .robot file:
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "robotframework-browser-tray"
3
- version = "1.5.0"
3
+ version = "1.5.2"
4
4
  description = "Tray icon and REPL for trying out Browser Library keywords using Chromium or Edge"
5
5
  authors = [
6
6
  {name = "Marduk Bolaños", email = "marduk.bolanos@imbus.de"},
@@ -19,6 +19,21 @@ license = {text = "Apache 2.0"}
19
19
  [tool.flit.module]
20
20
  name = "BrowserTray"
21
21
 
22
+
23
+ [tool.pdm]
24
+ distribution = true
25
+
26
+ [tool.pdm.dev-dependencies]
27
+ dev = [
28
+ "tox>=4.15.1",
29
+ "pytest>=8.2.2",
30
+ "mypy>=1.10.0",
31
+ ]
32
+
33
+ [tool.pdm.scripts]
34
+ test = "tox -p all"
35
+
36
+
22
37
  [project.scripts]
23
38
  browser-tray = "BrowserTray.tray:run"
24
39
  ibrowser = "BrowserTray.Repl.repl:run"
@@ -26,7 +41,3 @@ ibrowser = "BrowserTray.Repl.repl:run"
26
41
  [build-system]
27
42
  requires = ["flit_core>=3.2,<4"]
28
43
  build-backend = "flit_core.buildapi"
29
-
30
-
31
- [tool.pdm]
32
- distribution = true
@@ -1,7 +1,9 @@
1
- import http
1
+ import http.client
2
+ import socket
2
3
  import sys
3
4
  import tempfile
4
5
  from pathlib import Path
6
+ import time
5
7
 
6
8
  from robot import run_cli
7
9
 
@@ -56,12 +58,16 @@ def shell():
56
58
  file_path.unlink()
57
59
 
58
60
 
59
- def run():
61
+ def run(timeout=0):
60
62
  try:
61
63
  http.client.HTTPConnection('127.0.0.1', 1234, timeout=1).connect()
64
+ if timeout:
65
+ time.sleep(timeout)
66
+ sys.exit(0)
62
67
  shell()
63
- except TimeoutError:
68
+ except socket.timeout:
64
69
  print("ibrowser needs either:\n" +
65
70
  " - a running Chromium, started using the tray icon or\n" +
66
71
  " - a running Microsoft Edge started as explained in the documentation: https://pypi.org/project/robotframework-browser-tray/"
67
72
  )
73
+ sys.exit(1)
@@ -1,17 +1,25 @@
1
1
  import argparse
2
+ import http.client
2
3
  import os
3
4
  import site
5
+ import socket
4
6
  import subprocess
5
7
  import sys
8
+ import time
6
9
  from os.path import realpath
7
10
  from pathlib import Path
8
11
  from subprocess import Popen
9
12
  from tkinter import messagebox
13
+ from typing import List, Tuple
10
14
 
11
15
  from PIL import Image
12
16
  from pystray import Icon, Menu, MenuItem
13
17
 
14
18
 
19
+ REMOTE_DEBUGGING_PORT = 1234
20
+ PLAYWRIGHT_PROCESS_PORT= 4711
21
+
22
+
15
23
  _, site_packages = site.getsitepackages()
16
24
  browser_wrapper = Path(site_packages) / "Browser" / "wrapper"
17
25
  index_js = browser_wrapper / "index.js"
@@ -19,7 +27,7 @@ node_modules = browser_wrapper / "node_modules"
19
27
  playwright_core = node_modules / "playwright-core"
20
28
 
21
29
 
22
- def find_chromium(path: Path) -> list[Path]:
30
+ def find_chromium(path: Path) -> List[Path]:
23
31
  return [
24
32
  Path(file.path)
25
33
  for file in os.scandir(path)
@@ -40,15 +48,27 @@ def get_chromium_dir(node_modules: Path):
40
48
  return find_chromium(local_browsers)[0]
41
49
 
42
50
 
43
- def start_playwright(index_js: Path, playwright_process_port: int) -> Popen:
51
+ def start_playwright(playwright_process_port: int) -> Popen:
44
52
  return Popen(['node', index_js, str(playwright_process_port)])
45
53
 
46
54
 
47
-
48
55
  class TrayIcon:
49
- def __init__(self, processes: list[Popen], remote_debugging_port: int):
56
+ def __init__(self, playwright_process_port: int, remote_debugging_port: int, timeout=0):
50
57
  chromium_icon = Image.open(Path(realpath(__file__)).parent / "chromium.png")
51
- self.processes = processes
58
+
59
+ playwright_process = start_playwright(playwright_process_port)
60
+ time.sleep(2)
61
+ return_code = playwright_process.poll()
62
+
63
+ if return_code:
64
+ sys.exit(return_code)
65
+
66
+ if timeout:
67
+ time.sleep(timeout)
68
+ playwright_process.kill()
69
+ sys.exit(0)
70
+
71
+ self.processes = [playwright_process]
52
72
  self.remote_debugging_port = remote_debugging_port
53
73
  self.icon = Icon(
54
74
  name='Browser Tray',
@@ -58,7 +78,7 @@ class TrayIcon:
58
78
  'Open Chromium',
59
79
  self.open_chromium,
60
80
  default=True
61
- ),
81
+ ),
62
82
  MenuItem(
63
83
  'Open Chromium Incognito',
64
84
  self.open_chromium_incognito,
@@ -94,6 +114,7 @@ class TrayIcon:
94
114
  incognito_flag = ["-incognito"] if incognito else []
95
115
  chrome_exe = chromium_dir / "chrome-win" / "chrome.exe"
96
116
  chromium = Popen([chrome_exe, f"--remote-debugging-port={remote_debugging_port}", "--test-type"] + incognito_flag)
117
+ time.sleep(2)
97
118
  self.processes.append(chromium)
98
119
 
99
120
 
@@ -110,10 +131,8 @@ def is_running(cmd: str) -> bool:
110
131
  return len(instances) > 1
111
132
 
112
133
 
113
- def get_ports() -> tuple[int, int]:
134
+ def get_ports() -> Tuple[int, int]:
114
135
  MAX_PORT = 2**16
115
- REMOTE_DEBUGGING_PORT = 1234
116
- PLAYWRIGHT_PROCESS_PORT= 4711
117
136
 
118
137
  arg_parser = argparse.ArgumentParser(add_help=True)
119
138
  arg_parser.add_argument("--pw-port", default=PLAYWRIGHT_PROCESS_PORT, type=int, help=f"Playwright process port (default: {PLAYWRIGHT_PROCESS_PORT})")
@@ -144,7 +163,11 @@ def run():
144
163
  )
145
164
  sys.exit(1)
146
165
 
147
- playwright_process = start_playwright(index_js, playwright_process_port)
148
- processes = [playwright_process]
149
- tray_icon = TrayIcon(processes, remote_debugging_port)
150
- tray_icon.run()
166
+ try:
167
+ http.client.HTTPConnection('127.0.0.1', playwright_process_port, timeout=1).connect()
168
+ print("The port 4711 is already in use. Either browser-tray is already running or another process is using the port.\n" +
169
+ "To start the Playwright wrapper on another port execute `browser-tray --pw-port PORT`")
170
+ sys.exit(1)
171
+ except socket.timeout:
172
+ tray_icon = TrayIcon(playwright_process_port, remote_debugging_port)
173
+ tray_icon.run()