Best Python code snippet using SeleniumBase
base_case.py
Source:base_case.py
...699 if not timeout:700 timeout = settings.LARGE_TIMEOUT701 selector, by = self.__recalculate_selector(selector, by)702 if self.__is_shadow_selector(selector):703 self.__shadow_type(selector, text)704 return705 element = self.wait_for_element_visible(706 selector, by=by, timeout=timeout707 )708 self.__scroll_to_element(element, selector, by)709 try:710 element.clear() # May need https://stackoverflow.com/a/50691625711 backspaces = Keys.BACK_SPACE * 42 # Is the answer to everything712 element.send_keys(backspaces) # In case autocomplete keeps text713 except (StaleElementReferenceException, ENI_Exception):714 time.sleep(0.16)715 element = self.wait_for_element_visible(716 selector, by=by, timeout=timeout717 )...
blavideo.py
Source:blavideo.py
1# blaplay, Copyright (C) 2013 Niklas Koep2# This program is free software; you can redistribute it and/or3# modify it under the terms of the GNU General Public License4# as published by the Free Software Foundation; either version 25# of the License, or (at your option) any later version.6# This program is distributed in the hope that it will be useful,7# but WITHOUT ANY WARRANTY; without even the implied warranty of8# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the9# GNU General Public License for more details.10# You should have received a copy of the GNU General Public License11# along with this program; if not, write to the Free Software12# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.13import gobject14import gtk15import blaplay16player = blaplay.bla.player17from blaplay.blacore import blaconst, blacfg18from blaplay import blautil, blagui19from blaview import BlaViewMeta20class BlaVideoCanvas(gtk.DrawingArea):21 __gsignals__ = {22 "toggle_fullscreen": blautil.signal(0)23 }24 def __init__(self):25 super(BlaVideoCanvas, self).__init__()26 self.set_app_paintable(True)27 self.add_events(gtk.gdk.BUTTON_PRESS_MASK | gtk.gdk.SCROLL_MASK |28 gtk.gdk.KEY_PRESS_MASK | gtk.gdk.POINTER_MOTION_MASK)29 self.connect_object_after("expose_event",30 BlaVideoCanvas.__expose_event, self)31 # The cover art display uses this class as well but must be able to32 # override the the default button_press event handler. Thus we need to33 # register the default handler via connect_*_after().34 self.connect_object_after("button_press_event",35 BlaVideoCanvas.__button_press_event, self)36 self.connect_object("scroll_event",37 BlaVideoCanvas.__scroll_event, self)38 self.connect_object("motion_notify_event",39 BlaVideoCanvas.__motion_notify_event, self)40 self.connect_object("toggle_fullscreen",41 BlaVideoCanvas.__toggle_fullscreen, self)42 # The video view always gets realized/unrealized when the view changes.43 # We can't update the xid right after changing the view because44 # realizing the drawingarea is done asynchronously in the X server so45 # the xid might not be valid yet. Note that the signal is not emitted46 # when the side pane gets unhidden because the video canvas element47 # never gets unrealized in the first place.48 def realize(da):49 self.__parent = self.get_parent()50 # If the xid is updated even though no video is playing we get51 # killed off by the X server due to a BadWindow error.52 if player.video:53 player.set_xwindow_id(self.window.xid)54 self.modify_bg(gtk.STATE_NORMAL, gtk.gdk.Color(0, 0, 0))55 self.connect("realize", realize)56 # Request a redraw on track_changed and track_stopped events to reset57 # the drawing area.58 for signal in ["track_changed", "track_stopped"]:59 player.connect(signal, lambda *x: self.queue_draw())60 self.__parent = None61 def __toggle_fullscreen(self):62 blaplay.bla.window.set_fullscreen(63 self, self.__parent if self.__parent.child is None else None)64 def __expose_event(self, event):65 # TODO: - if not player.video: display title + anim66 pass67 def __button_press_event(self, event):68 if event.button == 1 and event.type == gtk.gdk._2BUTTON_PRESS:69 self.emit("toggle_fullscreen")70 elif event.button == 3 and event.type not in (gtk.gdk._2BUTTON_PRESS,71 gtk.gdk._3BUTTON_PRESS):72 if not player.video:73 return False74 menu = blaguiutils.create_control_popup_menu()75 menu.append(gtk.SeparatorMenuItem())76 # Add fullscreen entry.77 action = ("Enter" if not blaplay.bla.window.is_fullscreen else78 "Leave")79 m = gtk.ImageMenuItem(gtk.STOCK_FULLSCREEN)80 m.set_label("%s fullscreen" % action)81 m.connect("activate",82 lambda *x: self.emit("toggle_fullscreen"))83 menu.append(m)84 menu.show_all()85 menu.popup(None, None, None, event.button, event.time)86 return True87 else:88 return False89 self.__schedule_hide_cursor()90 def __scroll_event(self, event):91 # TODO: add either volume up/down or seek-on-scroll behaviour92 print_d("TODO: scroll event")93 def __motion_notify_event(self, event):94 # TODO: toggle cursor and controls overlay visibility95 self.__schedule_hide_cursor()96 def __schedule_hide_cursor(self):97 try:98 gobject.source_remove(self.__tid)99 except AttributeError:100 pass101 self.window.set_cursor(None)102 def hide_cursor():103 if blaplay.bla.window.is_fullscreen:104 self.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.BLANK_CURSOR))105 self.__tid = gobject.timeout_add(1500, hide_cursor)106class BlaVideo(gtk.Viewport):107 __metaclass__ = BlaViewMeta("Video")108 def __init__(self):109 super(BlaVideo, self).__init__()110 self.__drawing_area = BlaVideoCanvas()111 viewport = gtk.Viewport()112 viewport.set_shadow_type(gtk.SHADOW_NONE)113 vbox = gtk.VBox(spacing=10)114 viewport.add(self.__drawing_area)115 vbox.pack_start(viewport, expand=True, fill=True)116 self.__hbox = gtk.HBox(spacing=3)117 categories = [118 ("General", ["Title", "Artist", "Duration", "Filesize"]),119 ("Video", ["Codec", "Resolution", "Frame rate", "Bitrate"]),120 ("Audio", ["Stream", "Codec", "Channels", "Sampling rate",121 "Bitrate"])122 ]123 for title, fields in categories:124 table = gtk.Table(rows=len(fields)+1, columns=2, homogeneous=False)125 # Add the heading.126 label = gtk.Label()127 label.set_markup("<b>%s</b>" % title)128 alignment = gtk.Alignment(xalign=0.05)129 alignment.add(label)130 table.attach(alignment, 0, 2, 0, 1)131 for idx, field in enumerate(fields):132 label = gtk.Label()133 label.set_markup("<i>%s:</i>" % field)134 alignment = gtk.Alignment(xalign=0.1)135 alignment.add(label)136 table.attach(alignment, 0, 1, 2 * idx + 1, 2 * idx + 2)137 self.__hbox.pack_start(table)138 # TODO: fix the height to the same height as cover display139 self.__hbox.set_size_request(-1, 150)140 vbox.pack_start(self.__hbox, expand=False, fill=False)141 self.__shadow_type = self.get_shadow_type()142 self.add(vbox)143 self.show_all()144 def get_video_canvas(self):...
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!!