Skip to content

Commit 58c628f

Browse files
authored
Merge pull request #1133 from seleniumbase/recorder-desktop-and-more
The Recorder Mode Desktop App: Deluxe Edition (and more)
2 parents 906b538 + a70c353 commit 58c628f

File tree

16 files changed

+311
-106
lines changed

16 files changed

+311
-106
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ COMMANDS:
108108
mkdir [DIRECTORY] [OPTIONS]
109109
mkfile [FILE.py] [OPTIONS]
110110
mkrec / codegen [FILE.py] [OPTIONS]
111+
recorder (Open Recorder Desktop App)
111112
mkpres [FILE.py] [LANG]
112113
mkchart [FILE.py] [LANG]
113114
print [FILE] [OPTIONS]

examples/desktop_apps/ReadMe.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
<h2><img src="https://seleniumbase.io/img/logo6.png" title="SeleniumBase" width="32" /> Desktop Apps</h2>
44

5-
* **Recorder** (Run using ``python recorder.py``)
5+
* **Recorder** (Run using ``python recorder.py`` or ``sbase recorder``)

examples/desktop_apps/recorder.py

Lines changed: 5 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,12 @@
1-
""" Run this file using `python recorder.py` """
1+
""" Run this file using ``python recorder.py`` """
22

33
import os
4-
import sys
5-
from seleniumbase.fixtures import page_utils
64

7-
if sys.version_info[0] < 3:
8-
raise Exception("This script is for Python 3 only!")
9-
import tkinter as tk # noqa: E402
10-
from tkinter import messagebox # noqa: E402
115

12-
13-
def do_recording(file_name, url):
14-
url = url.strip()
15-
if not page_utils.is_valid_url(url):
16-
if page_utils.is_valid_url("https://" + url):
17-
url = "https://" + url
18-
if not page_utils.is_valid_url(url):
19-
messagebox.showwarning(
20-
"Invalid URL", "Enter a valid URL. (Eg. https://google.com)")
21-
else:
22-
if os.path.exists(file_name):
23-
os.remove(file_name)
24-
os.system("python -m sbase mkrec %s --url=%s" % (file_name, url))
25-
26-
27-
def do_playback(file_name):
28-
os.system("pytest %s --verbose --capture=no" % file_name)
29-
30-
31-
def create_tkinter_gui(file_name):
32-
window = tk.Tk()
33-
window.title("Recorder App")
34-
window.geometry("360x175")
35-
frame = tk.Frame(window)
36-
frame.pack()
37-
38-
a = tk.StringVar()
39-
tk.Label(window, text="Enter URL to start recording on:").pack()
40-
entry = tk.Entry(window, textvariable=a)
41-
entry.pack()
42-
entry.focus()
43-
entry.bind("<Return>", (lambda _: do_recording(file_name, a.get())))
44-
tk.Button(
45-
window, text="Record", command=lambda: do_recording(file_name, a.get())
46-
).pack()
47-
tk.Label(window, text="").pack()
48-
tk.Label(
49-
window, text="Playback the latest recording:").pack()
50-
tk.Button(
51-
window, text="Playback", command=lambda: do_playback(file_name)
52-
).pack()
53-
54-
# Bring form to front
55-
window.lift()
56-
window.attributes("-topmost", True)
57-
window.after_idle(window.attributes, "-topmost", False)
58-
window.mainloop()
6+
def open_recorder_desktop_app():
7+
command = "sbase recorder"
8+
os.system(command)
599

6010

6111
if __name__ == "__main__":
62-
file_name = "new_recording.py"
63-
create_tkinter_gui(file_name)
12+
open_recorder_desktop_app()

examples/hack_the_planet.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ def test_all_your_base_are_belong_to_us(self):
2121
wiki = "https://en.wikipedia.org/wiki/All_your_base_are_belong_to_us"
2222

2323
self.open(wiki)
24+
self.click_if_visible('button[aria-label="Close"]')
2425
self.set_text_content("h1#firstHeading", aybabtu)
2526
self.set_text_content("#ca-history a", aybabtu)
2627
self.set_text_content('#n-mainpage-description a', "ALL")

help_docs/recorder_mode.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<img src="https://seleniumbase.io/cdn/img/sb_recorder_notification.png" title="SeleniumBase" width="380">
88

9-
(This tutorial assumes that you are using SeleniumBase version ``2.1.6`` or newer.)
9+
(For the latest Recorder improvements, use SeleniumBase version ``2.3.0`` or newer.)
1010

1111
🔴 To make a new recording with Recorder Mode, you can use ``sbase mkrec`` or ``sbase codegen``):
1212

@@ -38,7 +38,16 @@ ipdb> c
3838
*** RECORDING COPIED to: new_test.py
3939
```
4040
41-
🔴 While a recording is in progress, you can press the ``[ESC]`` key to pause the recording. To resume the recording, you can hit the ``[~`]`` key, which is located directly below the ``[ESC]`` key on most keyboards.
41+
🔴 You can also activate Recorder Mode from the Recorder Desktop App:
42+
43+
```bash
44+
sbase recorder
45+
* Starting the SeleniumBase Recorder Desktop App...
46+
```
47+
48+
<img src="https://seleniumbase.io/cdn/img/recorder_desktop.png" title="SeleniumBase" width="340">
49+
50+
🔴 While a recording is in progress, you can press the ``[ESC]`` key to pause the Recorder. To resume the recording, you can hit the ``[~`]`` key, which is located directly below the ``[ESC]`` key on most keyboards.
4251
4352
🔴 From within Recorder Mode there are two additional modes: "Assert Element Mode" and "Assert Text Mode". To switch into "Assert Element Mode", press the <code>{^}-key (SHIFT+6)</code>: The border will become purple, and you'll be able to click on elements to assert from your test. To switch into "Assert Text Mode", press the <code>{&}-key (SHIFT+7)</code>: The border will become teal, and you'll be able to click on elements for asserting text from your test. While using either of the two special Assertion Modes, certain actions such as clicking on links won't have any effect. This lets you make assertions on elements without navigating away from the page, etc. To add an assertion for a button without triggering its default behavior via a "click" action, mouse-down on the button and then mouse-up somewhere else, which prevents a detected click while still recording the assert. To return back to the original Recorder Mode, press any key other than SHIFT or BACKSPACE (Eg: Press ``CONTROL``, etc.). You can also press ESC once to leave the Assertion Modes, but if you press it again, it'll stop the Recorder.
4453

mkdocs_build/requirements.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ click==8.0.3;python_version>="3.6"
1414
zipp==3.6.0;python_version>="3.6"
1515
readme-renderer==32.0
1616
pymdown-extensions==9.1;python_version>="3.6"
17-
importlib-metadata==4.8.2;python_version>="3.6"
17+
importlib-metadata==4.9.0;python_version>="3.6"
1818
bleach==4.1.0
1919
jsmin==3.0.0;python_version>="3.6"
2020
lunr==0.6.1;python_version>="3.6"
2121
nltk==3.6.5;python_version>="3.6"
2222
watchdog==2.1.6;python_version>="3.6"
2323
mkdocs==1.2.3;python_version>="3.6"
24-
mkdocs-material==8.1.1;python_version>="3.6"
24+
mkdocs-material==8.1.2;python_version>="3.6"
2525
mkdocs-exclude-search==0.5.4;python_version>="3.6"
26-
mkdocs-simple-hooks==0.1.3
26+
mkdocs-simple-hooks==0.1.4
2727
mkdocs-material-extensions==1.0.3;python_version>="3.6"
2828
mkdocs-minify-plugin==0.5.0

requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ beautifulsoup4==4.10.0;python_version>="3.5"
7979
cryptography==2.9.2;python_version<"3.5"
8080
cryptography==3.2.1;python_version>="3.5" and python_version<"3.6"
8181
cryptography==3.4.8;python_version>="3.6" and python_version<"3.7"
82-
cryptography==36.0.0;python_version>="3.7"
82+
cryptography==36.0.1;python_version>="3.7"
8383
pygments==2.5.2;python_version<"3.5"
8484
pygments==2.10.0;python_version>="3.5"
8585
prompt-toolkit==1.0.18;python_version<"3.5"
@@ -111,7 +111,7 @@ Pillow==7.2.0;python_version>="3.5" and python_version<"3.6"
111111
Pillow==8.4.0;python_version>="3.6"
112112
typing-extensions==3.10.0.2;python_version<"3.6"
113113
typing-extensions==4.0.0;python_version>="3.6" and python_version<"3.8"
114-
rich==10.16.0;python_version>="3.6" and python_version<"4.0"
114+
rich==10.16.1;python_version>="3.6" and python_version<"4.0"
115115
tornado==5.1.1;python_version<"3.5"
116116
tornado==6.1;python_version>="3.5"
117117
pdfminer.six==20191110;python_version<"3.5"

seleniumbase/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# seleniumbase package
2-
__version__ = "2.2.10"
2+
__version__ = "2.3.0"

seleniumbase/console_scripts/ReadMe.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ COMMANDS:
2020
mkdir [DIRECTORY] [OPTIONS]
2121
mkfile [FILE.py] [OPTIONS]
2222
mkrec / codegen [FILE.py] [OPTIONS]
23+
recorder (Open Recorder Desktop App)
2324
mkpres [FILE.py] [LANG]
2425
mkchart [FILE.py] [LANG]
2526
print [FILE] [OPTIONS]
@@ -243,6 +244,14 @@ is included.
243244
Creates a new SeleniumBase test using the Recorder.
244245
If the filename already exists, an error is raised.
245246

247+
<h3>recorder</h3>
248+
249+
* Usage:
250+
``sbase recorder``
251+
252+
* Output:
253+
Launches the SeleniumBase Recorder Desktop App.
254+
246255
<h3>mkpres</h3>
247256

248257
* Usage:

seleniumbase/console_scripts/run.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
sbase mkrec new_test.py
1515
sbase mkrec new_test.py --url=wikipedia.org
1616
sbase codegen new_test.py --url=wikipedia.org
17+
sbase recorder
1718
sbase mkpres new_presentation.py
1819
sbase mkchart new_chart.py
1920
sbase convert webdriver_unittest_file.py
@@ -78,6 +79,7 @@ def show_basic_usage():
7879
sc += " mkdir [DIRECTORY] [OPTIONS]\n"
7980
sc += " mkfile [FILE.py] [OPTIONS]\n"
8081
sc += " mkrec / codegen [FILE.py] [OPTIONS]\n"
82+
sc += " recorder (Open Recorder Desktop App)\n"
8183
sc += " mkpres [FILE.py] [LANG]\n"
8284
sc += " mkchart [FILE.py] [LANG]\n"
8385
sc += " print [FILE] [OPTIONS]\n"
@@ -772,6 +774,10 @@ def main():
772774
else:
773775
show_basic_usage()
774776
show_install_usage()
777+
elif command == "recorder":
778+
from seleniumbase.console_scripts import sb_recorder
779+
780+
sb_recorder.main()
775781
elif command == "mkdir":
776782
if len(command_args) >= 1:
777783
from seleniumbase.console_scripts import sb_mkdir

0 commit comments

Comments
 (0)