Skip to content

Commit 78e50f8

Browse files
committed
Fix selenium deprecation warnings
1 parent 123f47b commit 78e50f8

File tree

2 files changed

+19
-18
lines changed

2 files changed

+19
-18
lines changed

tests/test_forms.py

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import pytest
66
from django.forms import ClearableFileInput
77
from selenium.common.exceptions import NoSuchElementException
8+
from selenium.webdriver.common.by import By
89
from selenium.webdriver.support.expected_conditions import staleness_of
910
from selenium.webdriver.support.wait import WebDriverWait
1011

@@ -20,7 +21,7 @@
2021

2122
@contextmanager
2223
def wait_for_page_load(driver, timeout=30):
23-
old_page = driver.find_element_by_tag_name('html')
24+
old_page = driver.find_element(By.TAG_NAME, 'html')
2425
yield
2526
WebDriverWait(driver, timeout).until(
2627
staleness_of(old_page)
@@ -132,73 +133,73 @@ def test_no_js_error(self, driver, live_server):
132133
driver.get(live_server + self.url)
133134

134135
with pytest.raises(NoSuchElementException):
135-
error = driver.find_element_by_xpath('//body[@JSError]')
136+
error = driver.find_element(By.XPATH, '//body[@JSError]')
136137
pytest.fail(error.get_attribute('JSError'))
137138

138139
def test_file_insert(self, request, driver, live_server, upload_file, freeze):
139140
driver.get(live_server + self.url)
140-
file_input = driver.find_element_by_xpath('//input[@name=\'file\']')
141+
file_input = driver.find_element(By.XPATH, '//input[@name=\'file\']')
141142
file_input.send_keys(upload_file)
142143
assert file_input.get_attribute('name') == 'file'
143144
with wait_for_page_load(driver, timeout=10):
144145
file_input.submit()
145146
assert storage.exists('tmp/%s.txt' % request.node.name)
146147

147148
with pytest.raises(NoSuchElementException):
148-
error = driver.find_element_by_xpath('//body[@JSError]')
149+
error = driver.find_element(By.XPATH, '//body[@JSError]')
149150
pytest.fail(error.get_attribute('JSError'))
150151

151152
def test_file_insert_submit_value(self, driver, live_server, upload_file, freeze):
152153
driver.get(live_server + self.url)
153-
file_input = driver.find_element_by_xpath('//input[@name=\'file\']')
154+
file_input = driver.find_element(By.XPATH, '//input[@name=\'file\']')
154155
file_input.send_keys(upload_file)
155156
assert file_input.get_attribute('name') == 'file'
156-
save_button = driver.find_element_by_xpath('//input[@name=\'save\']')
157+
save_button = driver.find_element(By.XPATH, '//input[@name=\'save\']')
157158
with wait_for_page_load(driver, timeout=10):
158159
save_button.click()
159160
assert 'save' in driver.page_source
160161

161162
driver.get(live_server + self.url)
162-
file_input = driver.find_element_by_xpath('//input[@name=\'file\']')
163+
file_input = driver.find_element(By.XPATH, '//input[@name=\'file\']')
163164
file_input.send_keys(upload_file)
164165
assert file_input.get_attribute('name') == 'file'
165-
save_button = driver.find_element_by_xpath('//button[@name=\'save_continue\']')
166+
save_button = driver.find_element(By.XPATH, '//button[@name=\'save_continue\']')
166167
with wait_for_page_load(driver, timeout=10):
167168
save_button.click()
168169
assert 'save_continue' in driver.page_source
169170
assert 'continue_value' in driver.page_source
170171

171172
def test_progress(self, driver, live_server, upload_file, freeze):
172173
driver.get(live_server + self.url)
173-
file_input = driver.find_element_by_xpath('//input[@name=\'file\']')
174+
file_input = driver.find_element(By.XPATH, '//input[@name=\'file\']')
174175
file_input.send_keys(upload_file)
175176
assert file_input.get_attribute('name') == 'file'
176-
save_button = driver.find_element_by_xpath('//input[@name=\'save\']')
177+
save_button = driver.find_element(By.XPATH, '//input[@name=\'save\']')
177178
with wait_for_page_load(driver, timeout=10):
178179
save_button.click()
179180
assert 'save' in driver.page_source
180181

181182
driver.get(live_server + self.url)
182-
file_input = driver.find_element_by_xpath('//input[@name=\'file\']')
183+
file_input = driver.find_element(By.XPATH, '//input[@name=\'file\']')
183184
file_input.send_keys(upload_file)
184185
assert file_input.get_attribute('name') == 'file'
185-
save_button = driver.find_element_by_xpath('//button[@name=\'save_continue\']')
186+
save_button = driver.find_element(By.XPATH, '//button[@name=\'save_continue\']')
186187
with wait_for_page_load(driver, timeout=10):
187188
save_button.click()
188-
response = json.loads(driver.find_elements_by_css_selector('pre')[0].text)
189+
response = json.loads(driver.find_elements(By.CSS_SELECTOR, 'pre')[0].text)
189190
assert response['POST']['progress'] == '1'
190191

191192
def test_multi_file(self, driver, live_server, freeze,
192193
upload_file, another_upload_file, yet_another_upload_file):
193194
driver.get(live_server + self.url)
194-
file_input = driver.find_element_by_xpath('//input[@name=\'file\']')
195+
file_input = driver.find_element(By.XPATH, '//input[@name=\'file\']')
195196
file_input.send_keys(' \n '.join([upload_file, another_upload_file]))
196-
file_input = driver.find_element_by_xpath('//input[@name=\'other_file\']')
197+
file_input = driver.find_element(By.XPATH, '//input[@name=\'other_file\']')
197198
file_input.send_keys(yet_another_upload_file)
198-
save_button = driver.find_element_by_xpath('//input[@name=\'save\']')
199+
save_button = driver.find_element(By.XPATH, '//input[@name=\'save\']')
199200
with wait_for_page_load(driver, timeout=10):
200201
save_button.click()
201-
response = json.loads(driver.find_elements_by_css_selector('pre')[0].text)
202+
response = json.loads(driver.find_elements(By.CSS_SELECTOR, 'pre')[0].text)
202203
assert response['FILES'] == {
203204
'file': [
204205
os.path.basename(upload_file),

tests/testapp/templates/form.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!DOCTYPE html>
2-
{% load staticfiles %}
2+
{% load static %}
33
<html>
44
<head>
55
{#<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">#}

0 commit comments

Comments
 (0)