@@ -73,9 +73,7 @@ def fetch_element(
7373
7474 try :
7575 WebDriverWait (self .context .driver , element_timeout ).until (
76- ec .visibility_of_element_located (
77- (getattr (By , strategy ), actual_locator )
78- )
76+ ec .visibility_of_element_located ((getattr (By , strategy ), actual_locator ))
7977 )
8078 except (TimeoutException , StaleElementReferenceException ):
8179 logging .debug (
@@ -86,14 +84,10 @@ def fetch_element(
8684 )
8785
8886 if is_list_of_elements :
89- return self .context .driver .find_elements (
90- getattr (By , strategy ), actual_locator
91- )
87+ return self .context .driver .find_elements (getattr (By , strategy ), actual_locator )
9288
9389 try :
94- element = self .context .driver .find_element (
95- getattr (By , strategy ), actual_locator
96- )
90+ element = self .context .driver .find_element (getattr (By , strategy ), actual_locator )
9791 return element
9892 except TypeError :
9993 return False
@@ -119,9 +113,7 @@ def fetch_element(
119113 + "'}"
120114 ) from ex
121115
122- def is_element_present (
123- self , locator , replacement = None , timeout = None , retry_refresh_browser = False
124- ):
116+ def is_element_present (self , locator , replacement = None , timeout = None , retry_refresh_browser = False ):
125117 """Verify if element is present on page
126118 :param locator: element locator
127119 :param replacement: if locator contains dynamic part, i.e. '$value',
@@ -141,16 +133,12 @@ def is_element_present(
141133 def scroll_down_javascript (self , locator , pixel = 0 ):
142134 """Scrolls down javascript element"""
143135 try :
144- self .execute_java_script (
145- f"document.querySelector('{ locator } ').scrollTop={ pixel } "
146- )
136+ self .execute_java_script (f"document.querySelector('{ locator } ').scrollTop={ pixel } " )
147137 logging .info ("Scrolling on element '%s' using JavaScript" , locator )
148138 except Exception :
149139 Assert .assert_fail (f"Unable to scroll on element with locator { locator } " )
150140
151- def is_element_displayed (
152- self , locator , replacement = None , timeout = None , retry_refresh_browser = False
153- ):
141+ def is_element_displayed (self , locator , replacement = None , timeout = None , retry_refresh_browser = False ):
154142 """Verify if element is present on page
155143 :param locator: element locator
156144 :param replacement: if locator contains dynamic part, i.e. '$value',
@@ -165,9 +153,7 @@ def is_element_displayed(
165153 if not self .fetch_element (locator , False , timeout , retry_refresh_browser ):
166154 logging .info ("Unable to find element '%s'" , locator )
167155 return False
168- return self .fetch_element (
169- locator , False , timeout , retry_refresh_browser
170- ).is_displayed ()
156+ return self .fetch_element (locator , False , timeout , retry_refresh_browser ).is_displayed ()
171157 except Exception :
172158 return False
173159
@@ -191,13 +177,9 @@ def is_text_present(self, locator, text, timeout=None):
191177 strategy = locator .split ("," )[0 ].strip ()
192178 actual_locator = locator .replace (strategy + "," , "" )
193179
194- logging .info (
195- "Waiting for text '%s' to be present in '%s'" , text , locator
196- )
180+ logging .info ("Waiting for text '%s' to be present in '%s'" , text , locator )
197181 WebDriverWait (self .context .driver , timeout ).until (
198- ec .text_to_be_present_in_element (
199- (getattr (By , strategy ), actual_locator ), text
200- )
182+ ec .text_to_be_present_in_element ((getattr (By , strategy ), actual_locator ), text )
201183 )
202184 logging .info ("Found text '%s' present in '%s'" , text , locator )
203185 return True
@@ -218,9 +200,7 @@ def is_text_present(self, locator, text, timeout=None):
218200 logging .info ("Failed to find text '%s' present in '%s'" , text , locator )
219201 return False
220202
221- def is_element_checked (
222- self , locator , replacement = None , timeout = None , retry_refresh_browser = False
223- ):
203+ def is_element_checked (self , locator , replacement = None , timeout = None , retry_refresh_browser = False ):
224204 """Verify is element is checked
225205 :param locator: element locator
226206 :param replacement: if locator contains dynamic part, i.e. '$value',
@@ -233,9 +213,7 @@ def is_element_checked(
233213 locator = locator .replace ("$value" , replacement )
234214
235215 try :
236- is_element_checked = self .fetch_element (
237- locator , False , timeout , retry_refresh_browser
238- ).is_selected ()
216+ is_element_checked = self .fetch_element (locator , False , timeout , retry_refresh_browser ).is_selected ()
239217 logging .info (
240218 "Checked status for element '%s' is '%s'" ,
241219 locator ,
@@ -261,9 +239,7 @@ def is_element_clickable(self, locator):
261239 actual_locator = locator .replace (strategy + "," , "" ).strip ()
262240 timeout = int (settings .wait_time )
263241
264- logging .info (
265- "Checking element '%s' (%s) is clickable" , actual_locator , strategy
266- )
242+ logging .info ("Checking element '%s' (%s) is clickable" , actual_locator , strategy )
267243 WebDriverWait (self .context .driver , timeout ).until (
268244 ec .element_to_be_clickable ((getattr (By , strategy ), actual_locator ))
269245 )
@@ -314,9 +290,7 @@ def click(
314290 if timeout is None :
315291 timeout = int (settings .wait_time )
316292
317- logging .info (
318- "Checking element '%s' (%s) is clickable" , actual_locator , strategy
319- )
293+ logging .info ("Checking element '%s' (%s) is clickable" , actual_locator , strategy )
320294 WebDriverWait (self .context .driver , timeout ).until (
321295 ec .element_to_be_clickable ((getattr (By , strategy ), actual_locator ))
322296 )
@@ -345,32 +319,24 @@ def click(
345319 self .execute_java_script ("arguments[0].click();" , element )
346320 logging .info ("Clicked on element '%s' using JavaScript" , locator )
347321 except Exception as ex1 :
348- logging .warning (
349- "Unable to click on element '%s' using JavaScript" , locator
350- )
322+ logging .warning ("Unable to click on element '%s' using JavaScript" , locator )
351323 logging .debug (ex1 )
352324
353325 try :
354- logging .info (
355- "Clicking on element '%s' using ActionChains" , locator
356- )
326+ logging .info ("Clicking on element '%s' using ActionChains" , locator )
357327 element = self .fetch_element (locator )
358328 actions = ActionChains (self .context .driver )
359329 actions .move_to_element (element )
360330 actions .click (element )
361331 actions .perform ()
362- logging .info (
363- "Clicked on element '%s' using ActionChains" , locator
364- )
332+ logging .info ("Clicked on element '%s' using ActionChains" , locator )
365333 except Exception as ex2 :
366334 logging .warning (
367335 "Unable to click on element '%s' using ActionChains" ,
368336 locator ,
369337 )
370338 logging .debug (ex2 )
371- Assert .assert_fail (
372- "Unable to click on element '" + locator + "'"
373- )
339+ Assert .assert_fail ("Unable to click on element '" + locator + "'" )
374340 # Adding a small delay after a click increases test reliability
375341 sleep (delay )
376342
@@ -394,14 +360,10 @@ def type(self, locator, text, delay: float = 0.2, sensitive: boolean = False):
394360 if sensitive :
395361 logging .info ("Typed text ***** on element %s" , locator , exc_info = True )
396362 else :
397- logging .info (
398- "Typed text %s on element %s" , text , locator , exc_info = True
399- )
363+ logging .info ("Typed text %s on element %s" , text , locator , exc_info = True )
400364 except Exception :
401365 logging .error ("Unable to type text %s on element %s." , text , locator )
402- Assert .assert_fail (
403- "Unable to type text '" + text + "' on element '" + locator + "'"
404- )
366+ Assert .assert_fail ("Unable to type text '" + text + "' on element '" + locator + "'" )
405367
406368 def type_using_actionschains (self , locator , text , delay : float = 0.5 ):
407369 """Type text in locator
@@ -433,9 +395,7 @@ def type_using_actionschains(self, locator, text, delay: float = 0.5):
433395 locator ,
434396 exc_info = True ,
435397 )
436- Assert .assert_fail (
437- "Unable to type text '" + text + "' on element '" + locator + "'"
438- )
398+ Assert .assert_fail ("Unable to type text '" + text + "' on element '" + locator + "'" )
439399
440400 def user_tab_on_element (self , locator = None , delay = 0.5 , replacement = None ):
441401 """user performs tab keystroke
@@ -738,9 +698,7 @@ def select_by_visible_text(self, locator, option_text, replacement=None):
738698 select = Select (self .fetch_element (locator ))
739699 select .select_by_visible_text (option_text )
740700
741- logging .info (
742- "Selected element + %s+ by visible text + %s+ " , locator , option_text
743- )
701+ logging .info ("Selected element + %s+ by visible text + %s+ " , locator , option_text )
744702 except Exception :
745703 logging .error (
746704 "Unable to select option + %s +" ,
@@ -759,26 +717,20 @@ def switch_to_frame(self, frame_number, assert_it=True):
759717 self .context .driver .switch_to .frame (frame_number )
760718 logging .info ("Successfully switched frame" )
761719 except Exception :
762- logging .info (
763- "Frame not loaded yet! Waiting for another 10 seconds for frame to load..."
764- )
720+ logging .info ("Frame not loaded yet! Waiting for another 10 seconds for frame to load..." )
765721 sleep (int (settings .wait_time ))
766722
767723 try :
768724 self .context .driver .switch_to .frame (frame_number )
769- logging .info (
770- "Successfully switched to frame numbered + %s+ " , str (frame_number )
771- )
725+ logging .info ("Successfully switched to frame numbered + %s+ " , str (frame_number ))
772726 except Exception :
773727 logging .error (
774728 "Unable to locate frame numbered + %s+ " ,
775729 str (frame_number ),
776730 exc_info = True ,
777731 )
778732 if assert_it :
779- Assert .assert_fail (
780- "Unable to locate frame numbered '" + str (frame_number ) + "' "
781- )
733+ Assert .assert_fail ("Unable to locate frame numbered '" + str (frame_number ) + "' " )
782734
783735 def switch_to_default_content (self , assert_it = True , delay = 0.5 ):
784736 """Switch to parent window
@@ -789,15 +741,11 @@ def switch_to_default_content(self, assert_it=True, delay=0.5):
789741 self .context .driver .switch_to .default_content ()
790742 logging .info ("Successfully switched to default frame" )
791743 except Exception as ex :
792- logging .error (
793- "Unable to switch to default content! Error: %s" , ex , exc_info = True
794- )
744+ logging .error ("Unable to switch to default content! Error: %s" , ex , exc_info = True )
795745 if assert_it :
796746 Assert .assert_fail ("Unable to switch to default content!" )
797747
798- def switch_to_new_window (
799- self , count = 0 , expected_window_url = None , validate_url = False , delay = 0.5
800- ):
748+ def switch_to_new_window (self , count = 0 , expected_window_url = None , validate_url = False , delay = 0.5 ):
801749 """switch to the new window"""
802750 sleep (delay )
803751 tabs = self .context .driver .window_handles
@@ -809,9 +757,7 @@ def switch_to_new_window(
809757 else :
810758 for tab in tabs :
811759 self .context .driver .switch_to .window (tab )
812- logging .info (
813- "Switching to tab URL: %s" , self .context .driver .current_url
814- )
760+ logging .info ("Switching to tab URL: %s" , self .context .driver .current_url )
815761 opened_urls .append (self .context .driver .current_url )
816762 return opened_urls
817763
@@ -846,9 +792,7 @@ def close_other_tabs(self, delay=0.5):
846792 logging .info ("Length of Driver = %s " , driver_len )
847793 if driver_len > 1 :
848794 for i in range (driver_len - 1 , 0 , - 1 ):
849- self .context .driver .switch_to .window (
850- self .context .driver .window_handles [i ]
851- )
795+ self .context .driver .switch_to .window (self .context .driver .window_handles [i ])
852796 self .context .driver .close ()
853797 print ("Closed Tab No. " , i )
854798 self .context .driver .switch_to .window (self .context .driver .window_handles [0 ])
@@ -879,9 +823,7 @@ def press_key(self, locator, key, replacement=None):
879823 locator ,
880824 exc_info = True ,
881825 )
882- Assert .assert_fail (
883- "Unable to press key '" + key + "' on element '" + locator + "' "
884- )
826+ Assert .assert_fail ("Unable to press key '" + key + "' on element '" + locator + "' " )
885827
886828 def input_attachment_1 (self , locator , filename ):
887829 """Add attachment"""
@@ -977,9 +919,7 @@ def convert_pdf_to_txt(self, path):
977919 def extract_text_by_page (self , pdf_path ):
978920 """extract text by page"""
979921 with open (pdf_path , "rb" ) as file_handle :
980- for page in PDFPage .get_pages (
981- file_handle , caching = True , check_extractable = True
982- ):
922+ for page in PDFPage .get_pages (file_handle , caching = True , check_extractable = True ):
983923 resource_manager = PDFResourceManager ()
984924 fake_file_handle = io .StringIO ()
985925
0 commit comments