Checks and compares current URL of web page and the URL to be navigated and if it is different, it does navigate
(browser, link)
| 1289 | |
| 1290 | |
| 1291 | def web_address_navigator(browser, link): |
| 1292 | """Checks and compares current URL of web page and the URL to be |
| 1293 | navigated and if it is different, it does navigate""" |
| 1294 | current_url = get_current_url(browser) |
| 1295 | total_timeouts = 0 |
| 1296 | page_type = None # file or directory |
| 1297 | |
| 1298 | # remove slashes at the end to compare efficiently |
| 1299 | if current_url is not None and current_url.endswith("/"): |
| 1300 | current_url = current_url[:-1] |
| 1301 | |
| 1302 | if link.endswith("/"): |
| 1303 | link = link[:-1] |
| 1304 | page_type = "dir" # slash at the end is a directory |
| 1305 | |
| 1306 | new_navigation = current_url != link |
| 1307 | |
| 1308 | if current_url is None or new_navigation: |
| 1309 | link = link + "/" if page_type == "dir" else link # directory links |
| 1310 | # navigate faster |
| 1311 | |
| 1312 | while True: |
| 1313 | try: |
| 1314 | browser.get(link) |
| 1315 | # update server calls |
| 1316 | update_activity(browser, state=None) |
| 1317 | sleep(2) |
| 1318 | break |
| 1319 | |
| 1320 | except TimeoutException as exc: |
| 1321 | if total_timeouts >= 7: |
| 1322 | raise TimeoutException( |
| 1323 | "Retried {} times to GET '{}' webpage " |
| 1324 | "but failed out of a timeout!\n\t{}".format( |
| 1325 | total_timeouts, |
| 1326 | str(link).encode("utf-8"), |
| 1327 | str(exc).encode("utf-8"), |
| 1328 | ) |
| 1329 | ) |
| 1330 | total_timeouts += 1 |
| 1331 | sleep(2) |
| 1332 | |
| 1333 | |
| 1334 | @contextmanager |
no test coverage detected