|
5 | 5 | import pytest |
6 | 6 | from django.forms import ClearableFileInput |
7 | 7 | from selenium.common.exceptions import NoSuchElementException |
| 8 | +from selenium.webdriver.common.by import By |
8 | 9 | from selenium.webdriver.support.expected_conditions import staleness_of |
9 | 10 | from selenium.webdriver.support.wait import WebDriverWait |
10 | 11 |
|
|
20 | 21 |
|
21 | 22 | @contextmanager |
22 | 23 | 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') |
24 | 25 | yield |
25 | 26 | WebDriverWait(driver, timeout).until( |
26 | 27 | staleness_of(old_page) |
@@ -132,73 +133,73 @@ def test_no_js_error(self, driver, live_server): |
132 | 133 | driver.get(live_server + self.url) |
133 | 134 |
|
134 | 135 | with pytest.raises(NoSuchElementException): |
135 | | - error = driver.find_element_by_xpath('//body[@JSError]') |
| 136 | + error = driver.find_element(By.XPATH, '//body[@JSError]') |
136 | 137 | pytest.fail(error.get_attribute('JSError')) |
137 | 138 |
|
138 | 139 | def test_file_insert(self, request, driver, live_server, upload_file, freeze): |
139 | 140 | 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\']') |
141 | 142 | file_input.send_keys(upload_file) |
142 | 143 | assert file_input.get_attribute('name') == 'file' |
143 | 144 | with wait_for_page_load(driver, timeout=10): |
144 | 145 | file_input.submit() |
145 | 146 | assert storage.exists('tmp/%s.txt' % request.node.name) |
146 | 147 |
|
147 | 148 | with pytest.raises(NoSuchElementException): |
148 | | - error = driver.find_element_by_xpath('//body[@JSError]') |
| 149 | + error = driver.find_element(By.XPATH, '//body[@JSError]') |
149 | 150 | pytest.fail(error.get_attribute('JSError')) |
150 | 151 |
|
151 | 152 | def test_file_insert_submit_value(self, driver, live_server, upload_file, freeze): |
152 | 153 | 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\']') |
154 | 155 | file_input.send_keys(upload_file) |
155 | 156 | 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\']') |
157 | 158 | with wait_for_page_load(driver, timeout=10): |
158 | 159 | save_button.click() |
159 | 160 | assert 'save' in driver.page_source |
160 | 161 |
|
161 | 162 | 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\']') |
163 | 164 | file_input.send_keys(upload_file) |
164 | 165 | 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\']') |
166 | 167 | with wait_for_page_load(driver, timeout=10): |
167 | 168 | save_button.click() |
168 | 169 | assert 'save_continue' in driver.page_source |
169 | 170 | assert 'continue_value' in driver.page_source |
170 | 171 |
|
171 | 172 | def test_progress(self, driver, live_server, upload_file, freeze): |
172 | 173 | 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\']') |
174 | 175 | file_input.send_keys(upload_file) |
175 | 176 | 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\']') |
177 | 178 | with wait_for_page_load(driver, timeout=10): |
178 | 179 | save_button.click() |
179 | 180 | assert 'save' in driver.page_source |
180 | 181 |
|
181 | 182 | 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\']') |
183 | 184 | file_input.send_keys(upload_file) |
184 | 185 | 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\']') |
186 | 187 | with wait_for_page_load(driver, timeout=10): |
187 | 188 | 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) |
189 | 190 | assert response['POST']['progress'] == '1' |
190 | 191 |
|
191 | 192 | def test_multi_file(self, driver, live_server, freeze, |
192 | 193 | upload_file, another_upload_file, yet_another_upload_file): |
193 | 194 | 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\']') |
195 | 196 | 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\']') |
197 | 198 | 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\']') |
199 | 200 | with wait_for_page_load(driver, timeout=10): |
200 | 201 | 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) |
202 | 203 | assert response['FILES'] == { |
203 | 204 | 'file': [ |
204 | 205 | os.path.basename(upload_file), |
|
0 commit comments