robotframework-browser-tray 1.3.0__tar.gz → 1.5.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.5.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,30 +51,29 @@ 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:
60
62
 
61
- The role of an element can be easily obtained from the Accessibility Tree. To open the tree follow these steps:
63
+ ```bash
64
+ ibrowser
65
+ ```
62
66
 
63
- 1. Press F12 to open the DevTools
64
- 2. Select the Elements tab
65
- 3. In the right panel click on the Accessibility tab
66
- 4. In the section "Accessibility Tree" check "Enable full-page accessibility tree"
67
- 5. Click the button "Reload DevTools"
68
- 6. In the left panel click on the person icon to toggle the Accessibility Tree view
67
+ On start up it connects to a running Chromium (started using the tray icon) or Microsoft Edge (see below for instructions).
69
68
 
69
+ If you start a new browser while ibrowser is running, call the keyword "Connect" to connect ibrowser to it.
70
70
 
71
71
  ### Usage in a Robot Framework Test Suite
72
72
 
73
- Add these lines to the top of the .robot file:
73
+ Add these lines to the Settings section of the .robot file:
74
74
 
75
75
  ```robotframework
76
- Library Browser playwright_process_port=55555
76
+ Library Browser playwright_process_port=4711
77
77
  Test Setup Connect To Browser http://localhost:1234 chromium use_cdp=True
78
78
  ```
79
79
 
@@ -88,26 +88,24 @@ browser-tray --pw-port=XXXX --cdp-port=XXXX
88
88
 
89
89
  If Microsoft Edge is installed on your machine:
90
90
 
91
- 1. Close all instances of Microsoft Edge
91
+ 1. Create a Shortcut to msedge.exe with the target:
92
92
 
93
93
  ```powershell
94
- taskkill /F /IM msedge.exe
94
+ "C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe" --remote-debugging-port=1234 --user-data-dir=C:\Users\YOUR_USER\RFEdgeProfile
95
95
  ```
96
96
 
97
- 2. Start Microsoft Edge with `Windows + R`
97
+ 2. Start Edge using this shortcut
98
98
 
99
- ```powershell
100
- msedge.exe --remote-debugging-port=1234
101
- ```
99
+ 3. Execute `ibrowser`
102
100
 
103
101
 
104
102
  ## How it works
105
103
 
106
- On start up it checks whether `rfbrowser init chromium` has been executed in the current environment.
104
+ On start up `browser-tray` checks whether `rfbrowser init` has been executed.
107
105
 
108
- If this requirement is met the Playwright wrapper is started with `node site-packages/Browser/wrapper/index.js 55555`.
106
+ If this requirement is met the Playwright wrapper is started with `node site-packages/Browser/wrapper/index.js 4711`.
109
107
 
110
108
  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
109
 
112
- `ibrowser` is a batteries-included irobot that imports Browser library, connects to Chromium (if it is running) and adds some convenient selectors.
110
+ `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
111
 
@@ -0,0 +1,98 @@
1
+ # robotframework-browser-tray
2
+
3
+ Tray icon and REPL for trying out [Browser Library](https://robotframework-browser.org/) keywords using Chromium or Edge
4
+
5
+
6
+ **Requirements**
7
+
8
+ - NodeJS >= 18
9
+ - Windows
10
+
11
+
12
+ ## Use Cases
13
+
14
+ - Execute tests incrementally using e.g. [RobotCode](https://github.com/d-biehl/robotcode)
15
+
16
+ - Test selectors in an open web page interactively
17
+
18
+
19
+ ## How to use it
20
+
21
+ 1. Install the package
22
+
23
+ ```bash
24
+ pip install robotframework-browser-tray
25
+ ```
26
+
27
+ 2. Execute `browser-tray`
28
+
29
+ **Hint**: In case your environment does not allow executing browser-tray, call the Python module directly:
30
+
31
+ ```bash
32
+ python -m BrowserTray
33
+ ```
34
+
35
+ 3. Click on the tray icon with the Chromium logo
36
+
37
+ 4. Open a Terminal and execute `ibrowser`
38
+
39
+ **Hint**: In case your environment does not allow executing ibrowser, call the Python module directly:
40
+
41
+ ```bash
42
+ python -m BrowserTray.Repl
43
+ ```
44
+
45
+ ### ibrowser
46
+
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 connects to a running Chromium (started using the tray icon) or Microsoft Edge (see below for instructions).
56
+
57
+ If you start a new browser while ibrowser is running, call the keyword "Connect" to connect ibrowser to it.
58
+
59
+ ### Usage in a Robot Framework Test Suite
60
+
61
+ Add these lines to the Settings section of the .robot file:
62
+
63
+ ```robotframework
64
+ Library Browser playwright_process_port=4711
65
+ Test Setup Connect To Browser http://localhost:1234 chromium use_cdp=True
66
+ ```
67
+
68
+ In order to use other ports execute:
69
+
70
+ ```bash
71
+ browser-tray --pw-port=XXXX --cdp-port=XXXX
72
+ ```
73
+
74
+
75
+ ### Using Microsoft Edge
76
+
77
+ If Microsoft Edge is installed on your machine:
78
+
79
+ 1. Create a Shortcut to msedge.exe with the target:
80
+
81
+ ```powershell
82
+ "C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe" --remote-debugging-port=1234 --user-data-dir=C:\Users\YOUR_USER\RFEdgeProfile
83
+ ```
84
+
85
+ 2. Start Edge using this shortcut
86
+
87
+ 3. Execute `ibrowser`
88
+
89
+
90
+ ## How it works
91
+
92
+ On start up `browser-tray` checks whether `rfbrowser init` has been executed.
93
+
94
+ If this requirement is met the Playwright wrapper is started with `node site-packages/Browser/wrapper/index.js 4711`.
95
+
96
+ 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`.
97
+
98
+ `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.5.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"]
@@ -0,0 +1,13 @@
1
+ from RobotDebug.RobotDebug import RobotDebug
2
+ from robot.libraries.BuiltIn import BuiltIn
3
+
4
+
5
+ class Repl(RobotDebug):
6
+ def __init__(self, **kwargs):
7
+ super().__init__(**kwargs)
8
+
9
+ self.Library("Browser", "enable_presenter_mode=True", "playwright_process_port=4711")
10
+ self.connect()
11
+
12
+ def connect(self):
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 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(
@@ -103,7 +113,7 @@ def is_running(cmd: str) -> bool:
103
113
  def get_ports() -> tuple[int, int]:
104
114
  MAX_PORT = 2**16
105
115
  REMOTE_DEBUGGING_PORT = 1234
106
- PLAYWRIGHT_PROCESS_PORT= 55555
116
+ PLAYWRIGHT_PROCESS_PORT= 4711
107
117
 
108
118
  arg_parser = argparse.ArgumentParser(add_help=True)
109
119
  arg_parser.add_argument("--pw-port", default=PLAYWRIGHT_PROCESS_PORT, type=int, help=f"Playwright process port (default: {PLAYWRIGHT_PROCESS_PORT})")
@@ -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()
@@ -1,100 +0,0 @@
1
- # robotframework-browser-tray
2
-
3
- A tray icon for starting the Chromium installed by [Browser Library](https://robotframework-browser.org/)
4
-
5
- **Requirements**
6
-
7
- - NodeJS >= 18
8
- - Windows
9
-
10
-
11
- ## Use Cases
12
-
13
- - Execute tests incrementally using e.g. [RobotCode](https://github.com/d-biehl/robotcode)
14
-
15
- - Test selectors in an open web page interactively using [irobot](https://pypi.org/project/robotframework-debug/)
16
-
17
-
18
- ## How to use it
19
-
20
- 1. Install the package
21
-
22
- ```bash
23
- pip install robotframework-browser-tray
24
- ```
25
-
26
- 2. Execute `browser-tray`
27
-
28
- **Hint**: In case your environment does not allow executing browser-tray, call the Python module directly:
29
-
30
- ```bash
31
- python -m BrowserTray
32
- ```
33
-
34
- 3. Click on the tray icon with the Chromium logo
35
-
36
- 4. Open a Terminal and execute `ibrowser`
37
-
38
- **Hint**: In case your environment does not allow executing ibrowser, call the Python module directly:
39
-
40
- ```bash
41
- python -m BrowserTray.BrowserRepl
42
- ```
43
-
44
- ### ibrowser
45
-
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.
48
-
49
- The role of an element can be easily obtained from the Accessibility Tree. To open the tree follow these steps:
50
-
51
- 1. Press F12 to open the DevTools
52
- 2. Select the Elements tab
53
- 3. In the right panel click on the Accessibility tab
54
- 4. In the section "Accessibility Tree" check "Enable full-page accessibility tree"
55
- 5. Click the button "Reload DevTools"
56
- 6. In the left panel click on the person icon to toggle the Accessibility Tree view
57
-
58
-
59
- ### Usage in a Robot Framework Test Suite
60
-
61
- Add these lines to the top of the .robot file:
62
-
63
- ```robotframework
64
- Library Browser playwright_process_port=55555
65
- Test Setup Connect To Browser http://localhost:1234 chromium use_cdp=True
66
- ```
67
-
68
- In order to use other ports execute:
69
-
70
- ```bash
71
- browser-tray --pw-port=XXXX --cdp-port=XXXX
72
- ```
73
-
74
-
75
- ### Using Microsoft Edge
76
-
77
- If Microsoft Edge is installed on your machine:
78
-
79
- 1. Close all instances of Microsoft Edge
80
-
81
- ```powershell
82
- taskkill /F /IM msedge.exe
83
- ```
84
-
85
- 2. Start Microsoft Edge with `Windows + R`
86
-
87
- ```powershell
88
- msedge.exe --remote-debugging-port=1234
89
- ```
90
-
91
-
92
- ## How it works
93
-
94
- On start up it checks whether `rfbrowser init chromium` has been executed in the current environment.
95
-
96
- If this requirement is met the Playwright wrapper is started with `node site-packages/Browser/wrapper/index.js 55555`.
97
-
98
- 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
-
100
- `ibrowser` is a batteries-included irobot that imports Browser library, connects to Chromium (if it is running) and adds some convenient selectors.
@@ -1,12 +0,0 @@
1
- from RobotDebug.RobotDebug import RobotDebug
2
- from robot.libraries.BuiltIn import BuiltIn
3
- import pathlib
4
-
5
-
6
- class BrowserRepl(RobotDebug):
7
- def __init__(self, jsextension=None, **kwargs):
8
- super().__init__(**kwargs)
9
-
10
- jsextension = str(pathlib.Path(__file__).parent.resolve() / jsextension).replace('\\', '\\\\')
11
- self.Library("Browser", "playwright_process_port=55555", f"jsextension={jsextension}") #
12
- BuiltIn().run_keyword("Connect To Browser", "http://localhost:1234", "chromium", "use_cdp=True")
@@ -1,18 +0,0 @@
1
- async function registerMySelector(playwright) {
2
- playwright.selectors.register("role", () => ({
3
- // Returns the first element matching given selector in the root's subtree.
4
- query(root, selector) {
5
- return root.querySelector([role="${selector}"]);
6
- },
7
-
8
- // Returns all elements matching given selector in the root's subtree.
9
- queryAll(root, selector) {
10
- return Array.from(root.querySelectorAll([role="${selector}"]));
11
- }
12
- }));
13
-
14
- return 1;
15
- }
16
-
17
- exports.__esModule = true;
18
- exports.registerMySelector = registerMySelector;