@@ -7642,6 +7642,57 @@ def __assert_shadow_element_visible(self, selector):
7642
7642
7643
7643
############
7644
7644
7645
+ # Console Log controls
7646
+
7647
+ def start_recording_console_logs(self):
7648
+ """
7649
+ Starts recording console logs. Logs are saved to: "console.logs".
7650
+ To get those logs later, call "self.get_recorded_console_logs()".
7651
+ If navigating to a new page, then the current recorded logs will be
7652
+ lost, and you'll have to call start_recording_console_logs() again.
7653
+ # Link1: https://stackoverflow.com/a/19846113/7058266
7654
+ # Link2: https://stackoverflow.com/a/74196986/7058266
7655
+ """
7656
+ self.driver.execute_script(
7657
+ """
7658
+ console.stdlog = console.log.bind(console);
7659
+ console.logs = [];
7660
+ console.log = function(){
7661
+ console.logs.push(Array.from(arguments));
7662
+ console.stdlog.apply(console, arguments);
7663
+ }
7664
+ """
7665
+ )
7666
+
7667
+ def console_log_string(self, string):
7668
+ """
7669
+ Log a string to the Web Browser's Console.
7670
+ Example:
7671
+ self.console_log_string("Hello World!")
7672
+ """
7673
+ self.driver.execute_script("""console.log(`%s`);""" % string)
7674
+
7675
+ def console_log_script(self, script):
7676
+ """
7677
+ Log output of JavaScript to the Web Browser's Console.
7678
+ Example:
7679
+ self.console_log_script('document.querySelector("h2").textContent')
7680
+ """
7681
+ self.driver.execute_script("""console.log(%s);""" % script)
7682
+
7683
+ def get_recorded_console_logs(self):
7684
+ """
7685
+ Returns console logs recorded after "start_recording_console_logs()".
7686
+ """
7687
+ logs = []
7688
+ try:
7689
+ logs = self.driver.execute_script("return console.logs;")
7690
+ except Exception:
7691
+ pass
7692
+ return logs
7693
+
7694
+ ############
7695
+
7645
7696
# Application "Local Storage" controls
7646
7697
7647
7698
def __is_valid_storage_url(self):
0 commit comments