Skip to content

Commit 05416e0

Browse files
committed
Refactoring
1 parent 881c7bb commit 05416e0

File tree

8 files changed

+34
-81
lines changed

8 files changed

+34
-81
lines changed

seleniumbase/behave/behave_helper.py

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ def generate_gherkin(srt_actions):
2222
elif "'" not in action[2]:
2323
sb_actions.append("Open '%s'" % action[2])
2424
else:
25-
sb_actions.append(
26-
'Open "%s"' % action[2].replace('"', '\\"')
27-
)
25+
sb_actions.append('Open "%s"' % action[2].replace('"', '\\"'))
2826
elif action[0] == "f_url":
2927
if "%" in action[2] and python3:
3028
try:
@@ -73,27 +71,17 @@ def generate_gherkin(srt_actions):
7371
method = "js_type"
7472
text = action[2].replace("\n", "\\n")
7573
if '"' not in action[1] and '"' not in text:
76-
sb_actions.append(
77-
'Into "%s" type "%s"' % (action[1], text)
78-
)
74+
sb_actions.append('Into "%s" type "%s"' % (action[1], text))
7975
elif '"' not in action[1] and '"' in text:
80-
sb_actions.append(
81-
'Into "%s" type \'%s\'' % (action[1], text)
82-
)
76+
sb_actions.append('Into "%s" type \'%s\'' % (action[1], text))
8377
elif '"' in action[1] and '"' not in text:
84-
sb_actions.append(
85-
'Into \'%s\' type "%s"' % (action[1], text)
86-
)
78+
sb_actions.append('Into \'%s\' type "%s"' % (action[1], text))
8779
elif '"' in action[1] and '"' in text:
88-
sb_actions.append(
89-
"Into '%s' type '%s'" % (action[1], text)
90-
)
80+
sb_actions.append("Into '%s' type '%s'" % (action[1], text))
9181
elif action[0] == "e_mfa":
9282
text = action[2].replace("\n", "\\n")
9383
if '"' not in action[1] and '"' not in text:
94-
sb_actions.append(
95-
'Into "%s" do MFA "%s"' % (action[1], text)
96-
)
84+
sb_actions.append('Into "%s" do MFA "%s"' % (action[1], text))
9785
elif '"' not in action[1] and '"' in text:
9886
sb_actions.append(
9987
'Into "%s" do MFA \'%s\'' % (action[1], text)
@@ -103,9 +91,7 @@ def generate_gherkin(srt_actions):
10391
'Into \'%s\' do MFA "%s"' % (action[1], text)
10492
)
10593
elif '"' in action[1] and '"' in text:
106-
sb_actions.append(
107-
"Into '%s' do MFA '%s'" % (action[1], text)
108-
)
94+
sb_actions.append("Into '%s' do MFA '%s'" % (action[1], text))
10995
elif action[0] == "h_clk":
11096
if '"' not in action[1] and '"' not in action[2]:
11197
sb_actions.append(
@@ -271,9 +257,7 @@ def generate_gherkin(srt_actions):
271257
if not dest:
272258
sb_actions.append('%s "%s" to downloads' % (method, file_url))
273259
else:
274-
sb_actions.append(
275-
'%s "%s" to "%s"' % (method, file_url, dest)
276-
)
260+
sb_actions.append('%s "%s" to "%s"' % (method, file_url, dest))
277261
elif action[0] == "as_at":
278262
if ('"' not in action[1][0]) and action[1][2]:
279263
sb_actions.append(
@@ -337,13 +321,9 @@ def generate_gherkin(srt_actions):
337321
)
338322
else:
339323
if '"' not in action[1][0]:
340-
sb_actions.append(
341-
'%s "%s"' % (method, action[1][0])
342-
)
324+
sb_actions.append('%s "%s"' % (method, action[1][0]))
343325
else:
344-
sb_actions.append(
345-
"%s '%s'" % (method, action[1][0])
346-
)
326+
sb_actions.append("%s '%s'" % (method, action[1][0]))
347327
elif action[0] == "da_el":
348328
method = "Deferred assert element"
349329
if '"' not in action[1]:

seleniumbase/behave/behave_sb.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ def get_configured_sb(context):
636636
sb.proxy_bypass_list = proxy_bypass_list
637637
continue
638638
# Handle: -D proxy-pac-url=URL / proxy-pac-url=USERNAME:PASSWORD@URL
639-
if low_key in ["proxy-pac-url", "proxy_pac_url", "pac-url", "pac_url"]:
639+
if low_key in ["proxy-pac-url", "pac-url"]:
640640
proxy_pac_url = userdata[key]
641641
if proxy_pac_url == "true":
642642
proxy_pac_url = sb.proxy_pac_url # revert to default

seleniumbase/console_scripts/sb_behave_gui.py

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,7 @@ def do_behave_run(
8484
total_selected_tests += 1
8585

8686
full_run_command = "behave"
87-
if (
88-
total_selected_tests == 0
89-
or total_tests == total_selected_tests
90-
):
87+
if total_selected_tests == 0 or total_tests == total_selected_tests:
9188
if command_string:
9289
full_run_command += " "
9390
full_run_command += command_string
@@ -192,27 +189,19 @@ def create_tkinter_gui(tests, command_string):
192189
question_menu.pack()
193190

194191
qmx = tk.IntVar()
195-
chk = tk.Checkbutton(
196-
root, text="Quiet Mode (--quiet)", variable=qmx
197-
)
192+
chk = tk.Checkbutton(root, text="Quiet Mode (--quiet)", variable=qmx)
198193
chk.pack()
199194

200195
dmx = tk.IntVar()
201-
chk = tk.Checkbutton(
202-
root, text="Demo Mode (-D demo)", variable=dmx
203-
)
196+
chk = tk.Checkbutton(root, text="Demo Mode (-D demo)", variable=dmx)
204197
chk.pack()
205198

206199
mmx = tk.IntVar()
207-
chk = tk.Checkbutton(
208-
root, text="Mobile Mode (-D mobile)", variable=mmx
209-
)
200+
chk = tk.Checkbutton(root, text="Mobile Mode (-D mobile)", variable=mmx)
210201
chk.pack()
211202

212203
dbx = tk.IntVar()
213-
chk = tk.Checkbutton(
214-
root, text="Dashboard (-D dashboard)", variable=dbx
215-
)
204+
chk = tk.Checkbutton(root, text="Dashboard (-D dashboard)", variable=dbx)
216205
chk.pack()
217206
chk.select()
218207

seleniumbase/console_scripts/sb_commander.py

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,7 @@ def do_pytest_run(
8383
total_selected_tests += 1
8484

8585
full_run_command = "pytest"
86-
if (
87-
total_selected_tests == 0
88-
or total_tests == total_selected_tests
89-
):
86+
if total_selected_tests == 0 or total_tests == total_selected_tests:
9087
if command_string:
9188
full_run_command += " "
9289
full_run_command += command_string
@@ -195,28 +192,20 @@ def create_tkinter_gui(tests, command_string):
195192
question_menu.pack()
196193

197194
vox = tk.IntVar()
198-
chk = tk.Checkbutton(
199-
root, text="Verbose Output (-v)", variable=vox
200-
)
195+
chk = tk.Checkbutton(root, text="Verbose Output (-v)", variable=vox)
201196
chk.pack()
202197
chk.select()
203198

204199
dmx = tk.IntVar()
205-
chk = tk.Checkbutton(
206-
root, text="Demo Mode (--demo)", variable=dmx
207-
)
200+
chk = tk.Checkbutton(root, text="Demo Mode (--demo)", variable=dmx)
208201
chk.pack()
209202

210203
mmx = tk.IntVar()
211-
chk = tk.Checkbutton(
212-
root, text="Mobile Mode (--mobile)", variable=mmx
213-
)
204+
chk = tk.Checkbutton(root, text="Mobile Mode (--mobile)", variable=mmx)
214205
chk.pack()
215206

216207
dbx = tk.IntVar()
217-
chk = tk.Checkbutton(
218-
root, text="Dashboard (--dashboard)", variable=dbx
219-
)
208+
chk = tk.Checkbutton(root, text="Dashboard (--dashboard)", variable=dbx)
220209
chk.pack()
221210
chk.select()
222211

seleniumbase/console_scripts/sb_recorder.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def show_already_recording_warning():
6060
messagebox.showwarning(
6161
"SeleniumBase Recorder: Already Running!",
6262
"Please finalize the active recording from the terminal\n"
63-
'where you opened the Recorder: Type "c" and hit Enter.'
63+
'where you opened the Recorder: Type "c" and hit Enter.',
6464
)
6565

6666

@@ -175,7 +175,7 @@ def do_playback(file_name, use_chrome, window, demo_mode=False):
175175
messagebox.showwarning(
176176
"SeleniumBase Recorder: Already Running!",
177177
"Please finalize the active recording from the terminal\n"
178-
'where you opened the Recorder: Type "c" and hit Enter.'
178+
'where you opened the Recorder: Type "c" and hit Enter.',
179179
)
180180
send_window_to_front(window)
181181

@@ -278,7 +278,7 @@ def show_still_running_warning():
278278
"SeleniumBase Recorder: Still Running!",
279279
"Please finalize the active recording from the terminal\n"
280280
'where you opened the Recorder: Type "c" and hit Enter.\n'
281-
"(Then you can safely close this alert.)"
281+
"(Then you can safely close this alert.)",
282282
)
283283

284284

seleniumbase/fixtures/base_case.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1449,9 +1449,7 @@ def set_attributes(self, selector, attribute, value, by="css selector"):
14491449
except Exception:
14501450
pass
14511451

1452-
def set_attribute_all(
1453-
self, selector, attribute, value, by="css selector"
1454-
):
1452+
def set_attribute_all(self, selector, attribute, value, by="css selector"):
14551453
"""Same as set_attributes(), but using querySelectorAll naming scheme.
14561454
This method uses JavaScript to set/update a common attribute.
14571455
All matching selectors from querySelectorAll() are used.
@@ -3528,7 +3526,8 @@ def activate_recorder(self):
35283526

35293527
if not self.is_chromium():
35303528
raise Exception(
3531-
"The Recorder is only for Chromium browsers: (Chrome or Edge)")
3529+
"The Recorder is only for Chromium browsers: (Chrome or Edge)"
3530+
)
35323531
url = self.driver.current_url
35333532
if (
35343533
url.startswith("data:") or url.startswith("about:")
@@ -11488,8 +11487,8 @@ def __click_with_offset(
1148811487
m_y = y
1148911488
if center:
1149011489
element_rect = element.rect
11491-
left_offset = element_rect['width'] / 2
11492-
top_offset = element_rect['height'] / 2
11490+
left_offset = element_rect["width"] / 2
11491+
top_offset = element_rect["height"] / 2
1149311492
m_x = left_offset + (m_x or 0)
1149411493
m_y = top_offset + (m_y or 0)
1149511494
px = m_x - 3
@@ -11516,8 +11515,8 @@ def __click_with_offset(
1151611515
try:
1151711516
if selenium4_or_newer and not center:
1151811517
element_rect = element.rect
11519-
left_offset = element_rect['width'] / 2
11520-
top_offset = element_rect['height'] / 2
11518+
left_offset = element_rect["width"] / 2
11519+
top_offset = element_rect["height"] / 2
1152111520
x = -left_offset + (x or 0)
1152211521
y = -top_offset + (y or 0)
1152311522
elif selenium4_or_newer and center:
@@ -11527,8 +11526,8 @@ def __click_with_offset(
1152711526
else:
1152811527
# not selenium4_or_newer and center:
1152911528
element_rect = element.rect
11530-
left_offset = element_rect['width'] / 2
11531-
top_offset = element_rect['height'] / 2
11529+
left_offset = element_rect["width"] / 2
11530+
top_offset = element_rect["height"] / 2
1153211531
x = left_offset + x
1153311532
y = top_offset + y
1153411533
action_chains = ActionChains(self.driver)

seleniumbase/plugins/pytest_plugin.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -443,9 +443,7 @@ def pytest_addoption(parser):
443443
)
444444
parser.addoption(
445445
"--proxy-pac-url",
446-
"--proxy_pac_url",
447446
"--pac-url",
448-
"--pac_url",
449447
action="store",
450448
dest="proxy_pac_url",
451449
default=None,
@@ -1321,7 +1319,7 @@ def pytest_configure(config):
13211319
print(
13221320
"\n Recorder Mode does NOT support multi-process mode (-n)!"
13231321
'\n (DO NOT combine "--recorder" with "-n NUM_PROCESSES"!)'
1324-
'\n (The Recorder WILL BE DISABLED during this run!)\n'
1322+
"\n (The Recorder WILL BE DISABLED during this run!)\n"
13251323
)
13261324
sb_config.recorder_mode = False
13271325
sb_config.recorder_ext = False

seleniumbase/plugins/selenium_plugin.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,7 @@ def options(self, parser, env):
193193
)
194194
parser.add_option(
195195
"--proxy-pac-url",
196-
"--proxy_pac_url",
197196
"--pac-url",
198-
"--pac_url",
199197
action="store",
200198
dest="proxy_pac_url",
201199
default=None,

0 commit comments

Comments
 (0)