Skip to content

Commit b443eb2

Browse files
Merge pull request bepasty#338 from ThomasWaldmann/selenium430-compat-fixes
fix compatibility with selenium >=4.3.0
2 parents cc57020 + a4454df commit b443eb2

File tree

2 files changed

+32
-31
lines changed

2 files changed

+32
-31
lines changed

src/bepasty/tests/screenshots.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def toggle_hamburger(self):
7171

7272
# Toggle the hamburger menu
7373
try:
74-
self.browser.find_element_by_xpath('//button[@class="navbar-toggler"]').click()
74+
self.browser.find_element(By.XPATH, '//button[@class="navbar-toggler"]').click()
7575
except ElementNotInteractableException:
7676
pass
7777
time.sleep(.5)
@@ -101,7 +101,7 @@ def login(self):
101101
self.top_screen_shots("top")
102102
self.screenshot_seq += 1
103103

104-
token = self.browser.find_element_by_name("token")
104+
token = self.browser.find_element(By.NAME, "token")
105105
password = "foo"
106106
# Log in
107107
token.send_keys(password)
@@ -113,17 +113,17 @@ def login(self):
113113
self.screenshot_seq += 1
114114

115115
try:
116-
self.browser.find_element_by_xpath("//input[@value='Logout']")
116+
self.browser.find_element(By.XPATH, "//input[@value='Logout']")
117117
except NoSuchElementException:
118118
raise ValueError("Can't log in! Please edit your config, go to the PERMISSIONS setting, "
119119
"and add a new secret 'foo' with all permissions.")
120120

121121
def upload_file(self, path):
122122
# Set the file path
123-
fileupload = self.browser.find_element_by_id('fileupload')
123+
fileupload = self.browser.find_element(By.ID, 'fileupload')
124124
fileupload.send_keys(path)
125125

126-
form = self.browser.find_element_by_xpath('//form[@action="/+upload"]')
126+
form = self.browser.find_element(By.XPATH, '//form[@action="/+upload"]')
127127
form.click()
128128

129129
def upload_view(self):
@@ -160,15 +160,15 @@ def upload_view(self):
160160
self.screenshot_seq += 1
161161

162162
# Click Abort
163-
abort = self.browser.find_element_by_id('fileupload-abort')
163+
abort = self.browser.find_element(By.ID, 'fileupload-abort')
164164
abort.click()
165165
time.sleep(.5)
166166

167167
# NOTE: Abort Bootbox dialog
168168
self.screen_shots("abort")
169169
self.screenshot_seq += 1
170170

171-
ok = self.browser.find_element_by_class_name('bootbox-accept')
171+
ok = self.browser.find_element(By.CLASS_NAME, 'bootbox-accept')
172172
ok.click()
173173

174174
self.scroll_to_bottom()
@@ -185,7 +185,7 @@ def list_view(self):
185185

186186
def display_view(self):
187187
self.browser.get(self.url_base + '/+list')
188-
list_link = self.browser.find_elements_by_xpath('//tr/td/a')
188+
list_link = self.browser.find_elements(By.XPATH, '//tr/td/a')
189189
list_link[0].click()
190190

191191
# Highlight a line
@@ -195,25 +195,25 @@ def display_view(self):
195195
self.screen_shots("display")
196196
self.screenshot_seq += 1
197197

198-
modify = self.browser.find_element_by_id('modify-btn')
198+
modify = self.browser.find_element(By.ID, 'modify-btn')
199199
modify.click()
200200
time.sleep(.5)
201201

202202
# NOTE: Modify Bootbox dialog
203203
self.screen_shots("modify")
204204
self.screenshot_seq += 1
205205

206-
modify_cancel = self.browser.find_element_by_class_name('bootbox-cancel')
206+
modify_cancel = self.browser.find_element(By.CLASS_NAME, 'bootbox-cancel')
207207
modify_cancel.click()
208208
time.sleep(.5)
209209

210-
lock = self.browser.find_element_by_id('lock-btn')
210+
lock = self.browser.find_element(By.ID, 'lock-btn')
211211
lock.click()
212212
# NOTE: Display with lock screen
213213
self.screen_shots("lock")
214214
self.screenshot_seq += 1
215215

216-
qr = self.browser.find_element_by_id('qr-btn')
216+
qr = self.browser.find_element(By.ID, 'qr-btn')
217217
qr.click()
218218
# NOTE: QR code screen
219219
self.screen_shots("qr")

src/bepasty/tests/test_website.py

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from selenium.webdriver.chrome.service import Service as ChromeService
33
from selenium.webdriver import Chrome
44
from selenium.webdriver.common.keys import Keys
5+
from selenium.webdriver.common.by import By
56
from selenium.common.exceptions import (
67
NoSuchDriverException, NoSuchElementException
78
)
@@ -27,17 +28,17 @@ def setup_class(self):
2728
service = ChromeService(executable_path="/usr/bin/chromedriver")
2829
self.browser = Chrome(service=service)
2930
self.browser.get('http://localhost:5000/')
30-
token = self.browser.find_element_by_name("token")
31+
token = self.browser.find_element(By.NAME, "token")
3132
password = "foo"
3233
# Log in
3334
token.send_keys(password)
3435
token.send_keys(Keys.ENTER)
3536
time.sleep(.1)
3637
try:
37-
self.browser.find_element_by_xpath("//input[@value='Logout']")
38+
self.browser.find_element(By.XPATH, "//input[@value='Logout']")
3839
except NoSuchElementException:
3940
raise ValueError("Can't log in! Create a user 'foo' with the permissions "
40-
"'read' and 'create' in your PERMISSIONS in the config")
41+
"'read,create,delete' in your PERMISSIONS in the config.")
4142

4243
def teardown_class(self):
4344
"""
@@ -47,12 +48,12 @@ def teardown_class(self):
4748

4849
@property
4950
def page_body_lowercase(self):
50-
return self.browser.find_element_by_tag_name("body").text.lower()
51+
return self.browser.find_element(By.TAG_NAME, "body").text.lower()
5152

5253
def test_unit_input_exists(self):
53-
unit_input = self.browser.find_element_by_name("maxlife-unit")
54+
unit_input = self.browser.find_element(By.NAME, "maxlife-unit")
5455
assert unit_input is not None
55-
value_input = self.browser.find_element_by_name("maxlife-value")
56+
value_input = self.browser.find_element(By.NAME, "maxlife-value")
5657
assert value_input is not None
5758

5859
def fill_form(self):
@@ -62,33 +63,33 @@ def fill_form(self):
6263
"""
6364
filename = "test.txt"
6465
text_to_paste = "This is a test"
65-
paste_input = self.browser.find_element_by_id("formupload")
66+
paste_input = self.browser.find_element(By.ID, "formupload")
6667
paste_input.send_keys(text_to_paste)
67-
filename_input = self.browser.find_element_by_id("filename")
68+
filename_input = self.browser.find_element(By.ID, "filename")
6869
filename_input.send_keys(filename)
69-
contenttype_input = self.browser.find_element_by_id("contenttype")
70+
contenttype_input = self.browser.find_element(By.ID, "contenttype")
7071
contenttype_input.send_keys("text/plain")
7172
contenttype_input.send_keys(Keys.ENTER)
7273
time.sleep(.2) # give some time to render the next view
7374
return filename, text_to_paste
7475

7576
def delete_current_file(self):
76-
self.browser.find_element_by_id("del-btn").click()
77+
self.browser.find_element(By.ID, "del-btn").click()
7778
time.sleep(.2)
78-
self.browser.find_element_by_class_name("bootbox-accept").click()
79+
self.browser.find_element(By.CLASS_NAME, "bootbox-accept").click()
7980

8081
def test_paste_keep_forever(self):
81-
self.browser.find_element_by_xpath("//select[@name='maxlife-unit']/option[@value='forever']").click()
82-
value_input = self.browser.find_element_by_name("maxlife-value")
82+
self.browser.find_element(By.XPATH, "//select[@name='maxlife-unit']/option[@value='forever']").click()
83+
value_input = self.browser.find_element(By.NAME, "maxlife-value")
8384
value_input.clear()
8485
value_input.send_keys(1)
8586
self.fill_form()
8687
assert "max lifetime: forever" in self.page_body_lowercase
8788
self.delete_current_file()
8889

8990
def test_paste_keep_minutes(self):
90-
self.browser.find_element_by_xpath("//select[@name='maxlife-unit']/option[@value='minutes']").click()
91-
value_input = self.browser.find_element_by_name("maxlife-value")
91+
self.browser.find_element(By.XPATH, "//select[@name='maxlife-unit']/option[@value='minutes']").click()
92+
value_input = self.browser.find_element(By.NAME, "maxlife-value")
9293
value_input.clear()
9394
value_input.send_keys(1)
9495
self.fill_form()
@@ -102,18 +103,18 @@ def test_filename_gets_displayed(self):
102103

103104
def test_pasted_text_gets_displayed(self):
104105
_, pasted_text = self.fill_form()
105-
self.browser.find_element_by_id("inline-btn").click()
106+
self.browser.find_element(By.ID, "inline-btn").click()
106107
assert pasted_text.lower() in self.page_body_lowercase
107108
self.browser.back()
108109
self.delete_current_file()
109110

110111
@pytest.mark.slow
111112
def test_file_gets_deleted_after_expiry_time(self):
112-
self.browser.find_element_by_xpath("//select[@name='maxlife-unit']/option[@value='minutes']").click()
113-
value_input = self.browser.find_element_by_name("maxlife-value")
113+
self.browser.find_element(By.XPATH, "//select[@name='maxlife-unit']/option[@value='minutes']").click()
114+
value_input = self.browser.find_element(By.NAME, "maxlife-value")
114115
value_input.clear()
115116
value_input.send_keys(1)
116117
self.fill_form()
117118
time.sleep(61)
118-
self.browser.find_element_by_id("inline-btn").click()
119+
self.browser.find_element(By.ID, "inline-btn").click()
119120
assert "not found" in self.page_body_lowercase

0 commit comments

Comments
 (0)