robotframework-browser-tray 1.3.0__tar.gz → 1.4.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,7 +1,7 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: robotframework-browser-tray
3
- Version: 1.3.0
4
- Summary: Tray icon to start the Chromium installed by Browser Library
3
+ Version: 1.4.0
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
7
7
  Description-Content-Type: text/markdown
@@ -12,7 +12,8 @@ Project-URL: homepage, https://github.com/mardukbp/robotframework-browser-tray
12
12
 
13
13
  # robotframework-browser-tray
14
14
 
15
- A tray icon for starting the Chromium installed by [Browser Library](https://robotframework-browser.org/)
15
+ Tray icon and REPL for trying out [Browser Library](https://robotframework-browser.org/) keywords using Chromium or Edge
16
+
16
17
 
17
18
  **Requirements**
18
19
 
@@ -24,7 +25,7 @@ A tray icon for starting the Chromium installed by [Browser Library](https://rob
24
25
 
25
26
  - Execute tests incrementally using e.g. [RobotCode](https://github.com/d-biehl/robotcode)
26
27
 
27
- - Test selectors in an open web page interactively using [irobot](https://pypi.org/project/robotframework-debug/)
28
+ - Test selectors in an open web page interactively
28
29
 
29
30
 
30
31
  ## How to use it
@@ -50,13 +51,22 @@ python -m BrowserTray
50
51
  **Hint**: In case your environment does not allow executing ibrowser, call the Python module directly:
51
52
 
52
53
  ```bash
53
- python -m BrowserTray.BrowserRepl
54
+ python -m BrowserTray.Repl
54
55
  ```
55
56
 
56
57
  ### ibrowser
57
58
 
58
- ibrowser allows testing selectors in an open web page interactively. In addition to the selectors supported by Browser library,
59
- it adds the selector `role` for selecting elements using their ARIA role.
59
+ ibrowser allows testing selectors in an open web page interactively.
60
+
61
+ To start it execute:
62
+
63
+ ```bash
64
+ ibrowser
65
+ ```
66
+
67
+ On start up it checks whether the Chromium installed by `rfbrowser init chromium` is present. It can also be used with Microsoft Edge. See the section below for instructions.
68
+
69
+ In addition to the selectors supported by Browser Library, `ibrowser` adds the selector `role` for selecting elements using their ARIA role.
60
70
 
61
71
  The role of an element can be easily obtained from the Accessibility Tree. To open the tree follow these steps:
62
72
 
@@ -70,7 +80,7 @@ The role of an element can be easily obtained from the Accessibility Tree. To op
70
80
 
71
81
  ### Usage in a Robot Framework Test Suite
72
82
 
73
- Add these lines to the top of the .robot file:
83
+ Add these lines to the Settings section of the .robot file:
74
84
 
75
85
  ```robotframework
76
86
  Library Browser playwright_process_port=55555
@@ -88,26 +98,24 @@ browser-tray --pw-port=XXXX --cdp-port=XXXX
88
98
 
89
99
  If Microsoft Edge is installed on your machine:
90
100
 
91
- 1. Close all instances of Microsoft Edge
101
+ 1. Create a Shortcut to msedge.exe with the target:
92
102
 
93
103
  ```powershell
94
- taskkill /F /IM msedge.exe
104
+ "C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe" --remote-debugging-port=1234 --user-data-dir=C:\Users\YOUR_USER\RFEdgeProfile
95
105
  ```
96
106
 
97
- 2. Start Microsoft Edge with `Windows + R`
107
+ 2. Start Edge using this shortcut
98
108
 
99
- ```powershell
100
- msedge.exe --remote-debugging-port=1234
101
- ```
109
+ 3. Execute `ibrowser`
102
110
 
103
111
 
104
112
  ## How it works
105
113
 
106
- On start up it checks whether `rfbrowser init chromium` has been executed in the current environment.
114
+ On start up `browser-tray` checks whether `rfbrowser init` has been executed.
107
115
 
108
116
  If this requirement is met the Playwright wrapper is started with `node site-packages/Browser/wrapper/index.js 55555`.
109
117
 
110
118
  Selecting "Open Chromium" in the tray icon executes `site-packages/Browser/wrapper/node_modules/playwright-core/.local-browsers/chromium-XX/chrome-win/chrome.exe --remote-debugging-port=1234 --test-type`.
111
119
 
112
- `ibrowser` is a batteries-included irobot that imports Browser library, connects to Chromium (if it is running) and adds some convenient selectors.
120
+ `ibrowser` is a batteries-included [irobot](https://pypi.org/project/robotframework-debug/) that saves time by importing Browser Library and connecting to a running Chromium or Edge.
113
121
 
@@ -1,6 +1,7 @@
1
1
  # robotframework-browser-tray
2
2
 
3
- A tray icon for starting the Chromium installed by [Browser Library](https://robotframework-browser.org/)
3
+ Tray icon and REPL for trying out [Browser Library](https://robotframework-browser.org/) keywords using Chromium or Edge
4
+
4
5
 
5
6
  **Requirements**
6
7
 
@@ -12,7 +13,7 @@ A tray icon for starting the Chromium installed by [Browser Library](https://rob
12
13
 
13
14
  - Execute tests incrementally using e.g. [RobotCode](https://github.com/d-biehl/robotcode)
14
15
 
15
- - Test selectors in an open web page interactively using [irobot](https://pypi.org/project/robotframework-debug/)
16
+ - Test selectors in an open web page interactively
16
17
 
17
18
 
18
19
  ## How to use it
@@ -38,13 +39,22 @@ python -m BrowserTray
38
39
  **Hint**: In case your environment does not allow executing ibrowser, call the Python module directly:
39
40
 
40
41
  ```bash
41
- python -m BrowserTray.BrowserRepl
42
+ python -m BrowserTray.Repl
42
43
  ```
43
44
 
44
45
  ### ibrowser
45
46
 
46
- ibrowser allows testing selectors in an open web page interactively. In addition to the selectors supported by Browser library,
47
- it adds the selector `role` for selecting elements using their ARIA role.
47
+ ibrowser allows testing selectors in an open web page interactively.
48
+
49
+ To start it execute:
50
+
51
+ ```bash
52
+ ibrowser
53
+ ```
54
+
55
+ On start up it checks whether the Chromium installed by `rfbrowser init chromium` is present. It can also be used with Microsoft Edge. See the section below for instructions.
56
+
57
+ In addition to the selectors supported by Browser Library, `ibrowser` adds the selector `role` for selecting elements using their ARIA role.
48
58
 
49
59
  The role of an element can be easily obtained from the Accessibility Tree. To open the tree follow these steps:
50
60
 
@@ -58,7 +68,7 @@ The role of an element can be easily obtained from the Accessibility Tree. To op
58
68
 
59
69
  ### Usage in a Robot Framework Test Suite
60
70
 
61
- Add these lines to the top of the .robot file:
71
+ Add these lines to the Settings section of the .robot file:
62
72
 
63
73
  ```robotframework
64
74
  Library Browser playwright_process_port=55555
@@ -76,25 +86,23 @@ browser-tray --pw-port=XXXX --cdp-port=XXXX
76
86
 
77
87
  If Microsoft Edge is installed on your machine:
78
88
 
79
- 1. Close all instances of Microsoft Edge
89
+ 1. Create a Shortcut to msedge.exe with the target:
80
90
 
81
91
  ```powershell
82
- taskkill /F /IM msedge.exe
92
+ "C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe" --remote-debugging-port=1234 --user-data-dir=C:\Users\YOUR_USER\RFEdgeProfile
83
93
  ```
84
94
 
85
- 2. Start Microsoft Edge with `Windows + R`
95
+ 2. Start Edge using this shortcut
86
96
 
87
- ```powershell
88
- msedge.exe --remote-debugging-port=1234
89
- ```
97
+ 3. Execute `ibrowser`
90
98
 
91
99
 
92
100
  ## How it works
93
101
 
94
- On start up it checks whether `rfbrowser init chromium` has been executed in the current environment.
102
+ On start up `browser-tray` checks whether `rfbrowser init` has been executed.
95
103
 
96
104
  If this requirement is met the Playwright wrapper is started with `node site-packages/Browser/wrapper/index.js 55555`.
97
105
 
98
106
  Selecting "Open Chromium" in the tray icon executes `site-packages/Browser/wrapper/node_modules/playwright-core/.local-browsers/chromium-XX/chrome-win/chrome.exe --remote-debugging-port=1234 --test-type`.
99
107
 
100
- `ibrowser` is a batteries-included irobot that imports Browser library, connects to Chromium (if it is running) and adds some convenient selectors.
108
+ `ibrowser` is a batteries-included [irobot](https://pypi.org/project/robotframework-debug/) that saves time by importing Browser Library and connecting to a running Chromium or Edge.
@@ -1,7 +1,7 @@
1
1
  [project]
2
2
  name = "robotframework-browser-tray"
3
- version = "1.3.0"
4
- description = "Tray icon to start the Chromium installed by Browser Library"
3
+ version = "1.4.0"
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"},
7
7
  ]
@@ -21,7 +21,7 @@ name = "BrowserTray"
21
21
 
22
22
  [project.scripts]
23
23
  browser-tray = "BrowserTray.tray:run"
24
- ibrowser = "BrowserTray.BrowserRepl.repl:run"
24
+ ibrowser = "BrowserTray.Repl.repl:run"
25
25
 
26
26
  [build-system]
27
27
  requires = ["flit_core>=3.2,<4"]
@@ -1,12 +1,13 @@
1
+ import pathlib
2
+
1
3
  from RobotDebug.RobotDebug import RobotDebug
2
4
  from robot.libraries.BuiltIn import BuiltIn
3
- import pathlib
4
5
 
5
6
 
6
- class BrowserRepl(RobotDebug):
7
+ class Repl(RobotDebug):
7
8
  def __init__(self, jsextension=None, **kwargs):
8
9
  super().__init__(**kwargs)
9
10
 
10
11
  jsextension = str(pathlib.Path(__file__).parent.resolve() / jsextension).replace('\\', '\\\\')
11
- self.Library("Browser", "playwright_process_port=55555", f"jsextension={jsextension}") #
12
+ self.Library("Browser", "enable_presenter_mode=True", "playwright_process_port=55555", f"jsextension={jsextension}") #
12
13
  BuiltIn().run_keyword("Connect To Browser", "http://localhost:1234", "chromium", "use_cdp=True")
@@ -8,7 +8,7 @@ from robot import run_cli
8
8
 
9
9
  TEST_SUITE = b"""
10
10
  *** Settings ***
11
- Library BrowserTray.BrowserRepl jsextension=jsextension.js repl=${True}
11
+ Library BrowserTray.Repl jsextension=jsextension.js repl=${True}
12
12
 
13
13
  *** Test Cases ***
14
14
  Robot Framework Debug REPL
@@ -55,9 +55,13 @@ def shell():
55
55
  if file_path.exists():
56
56
  file_path.unlink()
57
57
 
58
+
58
59
  def run():
59
60
  try:
60
61
  http.client.HTTPConnection('127.0.0.1', 1234, timeout=1).connect()
61
62
  shell()
62
63
  except TimeoutError:
63
- print("ibrowser needs a running Chromium, started using the tray icon")
64
+ print("ibrowser needs either:\n" +
65
+ " - a running Chromium, started using the tray icon or\n" +
66
+ " - a running Microsoft Edge started as explained in the documentation: https://pypi.org/project/robotframework-browser-tray/"
67
+ )
@@ -6,6 +6,8 @@ import sys
6
6
  from os.path import realpath
7
7
  from pathlib import Path
8
8
  from subprocess import Popen
9
+ from tkinter import messagebox
10
+
9
11
  from PIL import Image
10
12
  from pystray import Icon, Menu, MenuItem
11
13
 
@@ -14,6 +16,7 @@ _, site_packages = site.getsitepackages()
14
16
  browser_wrapper = Path(site_packages) / "Browser" / "wrapper"
15
17
  index_js = browser_wrapper / "index.js"
16
18
  node_modules = browser_wrapper / "node_modules"
19
+ playwright_core = node_modules / "playwright-core"
17
20
 
18
21
 
19
22
  def find_chromium(path: Path) -> list[Path]:
@@ -24,8 +27,12 @@ def find_chromium(path: Path) -> list[Path]:
24
27
  ]
25
28
 
26
29
 
30
+ def playwright_is_initialized():
31
+ return node_modules.is_dir() and playwright_core.is_dir()
32
+
33
+
27
34
  def get_chromium_dir(node_modules: Path):
28
- local_browsers = node_modules / "playwright-core" / ".local-browsers"
35
+ local_browsers = playwright_core / ".local-browsers"
29
36
 
30
37
  if not (node_modules.is_dir() and local_browsers.is_dir() and find_chromium(local_browsers)):
31
38
  return None
@@ -37,16 +44,10 @@ def start_playwright(index_js: Path, playwright_process_port: int) -> Popen:
37
44
  return Popen(['node', index_js, str(playwright_process_port)])
38
45
 
39
46
 
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)
44
-
45
47
 
46
48
  class TrayIcon:
47
- def __init__(self, processes: list[Popen], chromium_dir: Path, remote_debugging_port: int):
49
+ def __init__(self, processes: list[Popen], remote_debugging_port: int):
48
50
  chromium_icon = Image.open(Path(realpath(__file__)).parent / "chromium.png")
49
- self.chromium_dir = chromium_dir
50
51
  self.processes = processes
51
52
  self.remote_debugging_port = remote_debugging_port
52
53
  self.icon = Icon(
@@ -76,16 +77,25 @@ class TrayIcon:
76
77
  self.icon.stop()
77
78
 
78
79
  def open_chromium(self):
79
- chromium = start_chromium(self.chromium_dir, self.remote_debugging_port, False)
80
- self.processes.append(chromium)
80
+ self.start_chromium(self.remote_debugging_port, False)
81
81
 
82
82
  def open_chromium_incognito(self):
83
- chromium = start_chromium(self.chromium_dir, self.remote_debugging_port, True)
84
- self.processes.append(chromium)
83
+ self.start_chromium(self.remote_debugging_port, True)
85
84
 
86
85
  def run(self):
87
86
  self.icon.run()
88
87
 
88
+ def start_chromium(self, remote_debugging_port: int, incognito: bool):
89
+ chromium_dir = get_chromium_dir(node_modules)
90
+
91
+ if not chromium_dir:
92
+ messagebox.showerror("Error", "Chromium is not installed. Execute 'rfbrowser init chromium'.")
93
+ else:
94
+ incognito_flag = ["-incognito"] if incognito else []
95
+ chrome_exe = chromium_dir / "chrome-win" / "chrome.exe"
96
+ chromium = Popen([chrome_exe, f"--remote-debugging-port={remote_debugging_port}", "--test-type"] + incognito_flag)
97
+ self.processes.append(chromium)
98
+
89
99
 
90
100
  def is_running(cmd: str) -> bool:
91
101
  process_list = subprocess.check_output(
@@ -125,12 +135,16 @@ def run():
125
135
  sys.exit(1)
126
136
 
127
137
  playwright_process_port, remote_debugging_port = get_ports()
128
- chromium_dir = get_chromium_dir(node_modules)
129
138
 
130
- if not chromium_dir:
131
- raise Exception("Playwright has not been initialized. Execute 'rfbrowser init chromium'.")
139
+ if not playwright_is_initialized():
140
+ print(
141
+ "Playwright has not been initialized.\n" +
142
+ "In order to use Chromium execute 'rfbrowser init chromium'.\n" +
143
+ "If you want to use the Microsoft Edge installed on your system execute 'rfbrowser init --skip-browsers'"
144
+ )
145
+ sys.exit(1)
132
146
 
133
147
  playwright_process = start_playwright(index_js, playwright_process_port)
134
148
  processes = [playwright_process]
135
- tray_icon = TrayIcon(processes, chromium_dir, remote_debugging_port)
149
+ tray_icon = TrayIcon(processes, remote_debugging_port)
136
150
  tray_icon.run()