Best Python code snippet using SeleniumBase
browser.py
Source:browser.py
...73 except selenium.common.exceptions.WebDriverException as e:74 if 'modal dialog' in e.msg:75 require_webdriver().switch_to.alert().accept()76 else:77 assert_no_js_errors()78 raise79 except Exception:80 assert_no_js_errors()81 raise82 def assert_current_page(page_name):83 current_page_name = require_webdriver().execute_script('''84 if (window.veil && veil.doc && veil.doc.currentPage) {85 return veil.doc.currentPage.pageName;86 } else {87 return null;88 }89 ''')90 if page_name != current_page_name:91 assert_no_js_errors()92 message = 'we are on the wrong page, expected: {}, actual: {}, url: {}'.format(93 page_name, current_page_name, webdriver.current_url)94 report_error(message)95 def assert_no_js_errors():96 js_errors = require_webdriver().execute_script('''97 if (window.veil && veil.doc) {98 return veil.doc.jsErrors99 } else {100 return null;101 }102 ''')103 if js_errors:104 report_error('java script errors: {}'.format(js_errors))105 def report_error(message):106 LOGGER.error(message)107 import time108 time.sleep(60)109 raise Exception(message)...
jbrowse_selenium.py
Source:jbrowse_selenium.py
...45 el = self.browser.find_elements_by_xpath( xpathExpression )46 except NoSuchElementException:47 assert 0, ( "can't find %s" % xpathExpression )48 return el49 def assert_no_js_errors( self ):50 assert self.browser.find_element_by_xpath('/html/body') \51 .get_attribute('JSError') == None52 def do_typed_query( self, text ):53 # Find the query box and put f15 into it and hit enter54 qbox = self.browser.find_element_by_id("location")55 qbox.clear()56 qbox.send_keys( text + Keys.RETURN )57 time.sleep( 0.2 )58 def _rubberband( self, el_xpath, start_pct, end_pct, modkey = None ):59 el = self.assert_element( el_xpath )60 start_offset = el.size['width'] * start_pct - el.size['width']/2;61 c = self.actionchains() \62 .move_to_element( el ) \63 .move_by_offset( start_offset, 0 )64 if( modkey ):65 c = c.key_down( modkey )66 c = c \67 .click_and_hold( None ) \68 .move_by_offset( el.size['width']*(end_pct-start_pct), 0 ) \69 .release( None )70 if( modkey ):71 c = c.key_up( modkey )72 c \73 .release( None ) \74 .perform()75 self.assert_no_js_errors()76 def overview_rubberband( self, start_pct, end_pct ):77 """Executes a rubberband gesture from start_pct to end_pct on the overview bar"""78 self._rubberband( "//div[@id='overview']", start_pct, end_pct )79 # I can't get a mainscale_rubberband() working, can't find an80 # element to tell selenium to move to that will hit it. can't81 # move to the scale itself because it's so wide.82 def trackpane_rubberband( self, start_pct, end_pct ):83 """Executes a rubberband gesture from start_pct to end_pct in the main track pane"""84 self._rubberband( "//div[contains(@class,'dragWindow')]", start_pct, end_pct, Keys.SHIFT )85 def is_track_on( self, tracktext ):86 # find the track label87 return not self.maybe_find_element_by_xpath( "//div[@class='tracklist-label'][contains(.,'%s')]" % tracktext )88 def turn_on_track( self, tracktext ):89 # find the track label90 tracklabel = self.assert_element( "//div[@class='tracklist-label'][contains(.,'%s')]" % tracktext )91 dragpane = self.assert_element( "//div[contains(@class, 'trackContainer')]" )92 # drag the track label over93 self.actionchains() \94 .drag_and_drop( tracklabel, dragpane ) \95 .perform()96 self.assert_no_js_errors()97 def turn_off_track( self, tracktext ):98 # drag the track back into the track list99 track_handle = self.assert_element( "/html//div[contains(@class,'track')]//div[contains(@class,'track-label')][contains(.,'%s')]" % tracktext )100 track_list = self.assert_element( "/html//div[@id='tracksAvail']" )101 self.actionchains() \102 .drag_and_drop( track_handle, track_list ) \103 .perform()104 self.assert_no_js_errors()105 def actionchains( self ):106 return ActionChains( self.browser )107 def get_track_labels_containing( self, string ):108 return self.assert_elements( "//div[contains(@class,'track-label')][contains(.,'%s')]" % string )109 def select_refseq( self, name ):110 refseq_selector = Select( self.browser.find_element_by_id('chrom') )111 refseq_selector.select_by_value( name )112 def scroll( self ):113 move_right_button = self.browser.find_element_by_id('moveRight')114 move_right_button.click()115 time.sleep(0.5)116 move_left_button = self.browser.find_element_by_id('moveLeft')117 move_left_button.click()118 # TODO: check the outcome of this119 time.sleep(0.5)120 self.assert_no_js_errors()121 # scroll back and forth with the mouse122 self.actionchains() \123 .move_to_element( move_right_button ) \124 .move_by_offset( 0, 300 ) \125 .click_and_hold( None ) \126 .move_by_offset( 300, 0 ) \127 .release( None ) \128 .move_by_offset( -100,100 ) \129 .click_and_hold( None ) \130 .move_by_offset( -300, 0 ) \131 .release( None ) \132 .perform()...
test_base.py
Source:test_base.py
...92 self.assertEqual(status_code, 200)93 @layer94 def test_layer_no_errors(self):95 self.assert_no_404_errors()96 self.assert_no_js_errors()97 @layer98 def test_layers_no_errors(self):99 self.open(BASE+'/layers/')100 self.assert_no_404_errors()101 self.assert_no_js_errors()102 def test_home_no_errors(self):103 self.assert_no_404_errors()104 self.assert_no_js_errors()105 @superuser106 def test_home_no_404_admin(self):107 self.assert_no_404_errors()...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!