How to use __get_link_if_404_error method in SeleniumBase

Best Python code snippet using SeleniumBase

base_case.py

Source:base_case.py Github

copy

Full Screen

...1212 """1213 status_code = str(self.get_link_status_code(link))1214 bad_link_str = 'Error: "%s" returned a 404!' % link1215 self.unittest.assertNotEqual(status_code, "404", bad_link_str)1216 def __get_link_if_404_error(self, link):1217 status_code = str(self.get_link_status_code(link))1218 if status_code == "404":1219 # Verify again to be sure. (In case of multi-threading overload.)1220 status_code = str(self.get_link_status_code(link))1221 if status_code == "404":1222 return link1223 else:1224 return None1225 else:1226 return None1227 def assert_no_404_errors(self, multithreaded=True):1228 """Assert no 404 errors from page links obtained from:1229 "a"->"href", "img"->"src", "link"->"href", and "script"->"src".1230 (A 404 error represents a broken link on a web page.)1231 """1232 all_links = self.get_unique_links()1233 links = []1234 for link in all_links:1235 if (1236 "javascript:" not in link1237 and "mailto:" not in link1238 and "data:" not in link1239 ):1240 links.append(link)1241 broken_links = []1242 if multithreaded:1243 from multiprocessing.dummy import Pool as ThreadPool1244 pool = ThreadPool(10)1245 results = pool.map(self.__get_link_if_404_error, links)1246 pool.close()1247 pool.join()1248 for result in results:1249 if result:1250 broken_links.append(result)1251 else:1252 broken_links = []1253 for link in links:1254 if self.__get_link_if_404_error(link):1255 broken_links.append(link)1256 if len(broken_links) > 0:1257 bad_links_str = "\n".join(broken_links)1258 if len(broken_links) == 1:1259 # self.fail("Broken link detected:\n%s" % bad_links_str)1260 raise ("Broken link detected:\n%s" % bad_links_str)1261 elif len(broken_links) > 1:1262 # self.fail("Broken links detected:\n%s" % bad_links_str)1263 raise ("Broken links detected:\n%s" % bad_links_str)1264 def print_unique_links_with_status_codes(self):1265 """Finds all unique links in the html of the page source1266 and then prints out those links with their status codes.1267 Format: ["link" -> "status_code"] (per line)1268 Page links include those obtained from:...

Full Screen

Full Screen

asserts.py

Source:asserts.py Github

copy

Full Screen

...603 broken_links.append(result)604 else:605 broken_links = []606 for link in links:607 if self.__get_link_if_404_error(link):608 broken_links.append(link)609 self.__requests_timeout = None # Reset the requests.get() timeout610 if len(broken_links) > 0:611 broken_links = sorted(broken_links)612 bad_links_str = "\n".join(broken_links)613 if len(broken_links) == 1:614 self.fail("Broken link detected:\n%s" % bad_links_str)615 elif len(broken_links) > 1:616 self.fail("Broken links detected:\n%s" % bad_links_str)617 if self.demo_mode:618 a_t = "ASSERT NO 404 ERRORS"619 if self._language != "English":620 from seleniumbase.fixtures.words import SD621 a_t = SD.translate_assert_no_404_errors(self._language)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run SeleniumBase automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful