How to use get_handle method in autotest

Best Python code snippet using autotest_python

window.py

Source:window.py Github

copy

Full Screen

...113 """114 Compatibility with ctypes.115 Allows passing transparently a Window object to an API call.116 """117 return self.get_handle()118 def get_handle(self):119 """120 @rtype: int121 @return: Window handle.122 @raise ValueError: No window handle set.123 """124 if self.hWnd is None:125 raise ValueError("No window handle set!")126 return self.hWnd127 def get_pid(self):128 """129 @rtype: int130 @return: Global ID of the process that owns this window.131 """132 if self.dwProcessId is not None:133 return self.dwProcessId134 self.__get_pid_and_tid()135 return self.dwProcessId136 def get_tid(self):137 """138 @rtype: int139 @return: Global ID of the thread that owns this window.140 """141 if self.dwThreadId is not None:142 return self.dwThreadId143 self.__get_pid_and_tid()144 return self.dwThreadId145 def __get_pid_and_tid(self):146 "Internally used by get_pid() and get_tid()."147 self.dwThreadId, self.dwProcessId = \148 win32.GetWindowThreadProcessId(self.get_handle())149 def __load_Process_class(self):150 global Process # delayed import151 if Process is None:152 from winappdbg.process import Process153 def __load_Thread_class(self):154 global Thread # delayed import155 if Thread is None:156 from winappdbg.thread import Thread157 def get_process(self):158 """159 @rtype: L{Process}160 @return: Parent Process object.161 """162 if self.__process is not None:163 return self.__process164 self.__load_Process_class()165 self.__process = Process(self.get_pid())166 return self.__process167 def set_process(self, process = None):168 """169 Manually set the parent process. Use with care!170 @type process: L{Process}171 @param process: (Optional) Process object. Use C{None} to autodetect.172 """173 if process is None:174 self.__process = None175 else:176 self.__load_Process_class()177 if not isinstance(process, Process):178 msg = "Parent process must be a Process instance, "179 msg += "got %s instead" % type(process)180 raise TypeError(msg)181 self.dwProcessId = process.get_pid()182 self.__process = process183 def get_thread(self):184 """185 @rtype: L{Thread}186 @return: Parent Thread object.187 """188 if self.__thread is not None:189 return self.__thread190 self.__load_Thread_class()191 self.__thread = Thread(self.get_tid())192 return self.__thread193 def set_thread(self, thread = None):194 """195 Manually set the thread process. Use with care!196 @type thread: L{Thread}197 @param thread: (Optional) Thread object. Use C{None} to autodetect.198 """199 if thread is None:200 self.__thread = None201 else:202 self.__load_Thread_class()203 if not isinstance(thread, Thread):204 msg = "Parent thread must be a Thread instance, "205 msg += "got %s instead" % type(thread)206 raise TypeError(msg)207 self.dwThreadId = thread.get_tid()208 self.__thread = thread209 def __get_window(self, hWnd):210 """211 User internally to get another Window from this one.212 It'll try to copy the parent Process and Thread references if possible.213 """214 window = Window(hWnd)215 if window.get_pid() == self.get_pid():216 window.set_process( self.get_process() )217 if window.get_tid() == self.get_tid():218 window.set_thread( self.get_thread() )219 return window220#------------------------------------------------------------------------------221 def get_classname(self):222 """223 @rtype: str224 @return: Window class name.225 @raise WindowsError: An error occured while processing this request.226 """227 return win32.GetClassName( self.get_handle() )228 def get_style(self):229 """230 @rtype: int231 @return: Window style mask.232 @raise WindowsError: An error occured while processing this request.233 """234 return win32.GetWindowLongPtr( self.get_handle(), win32.GWL_STYLE )235 def get_extended_style(self):236 """237 @rtype: int238 @return: Window extended style mask.239 @raise WindowsError: An error occured while processing this request.240 """241 return win32.GetWindowLongPtr( self.get_handle(), win32.GWL_EXSTYLE )242 def get_text(self):243 """244 @see: L{set_text}245 @rtype: str246 @return: Window text (caption) on success, C{None} on error.247 """248 try:249 return win32.GetWindowText( self.get_handle() )250 except WindowsError:251 return None252 def set_text(self, text):253 """254 Set the window text (caption).255 @see: L{get_text}256 @type text: str257 @param text: New window text.258 @raise WindowsError: An error occured while processing this request.259 """260 win32.SetWindowText( self.get_handle(), text )261 def get_placement(self):262 """263 Retrieve the window placement in the desktop.264 @see: L{set_placement}265 @rtype: L{win32.WindowPlacement}266 @return: Window placement in the desktop.267 @raise WindowsError: An error occured while processing this request.268 """269 return win32.GetWindowPlacement( self.get_handle() )270 def set_placement(self, placement):271 """272 Set the window placement in the desktop.273 @see: L{get_placement}274 @type placement: L{win32.WindowPlacement}275 @param placement: Window placement in the desktop.276 @raise WindowsError: An error occured while processing this request.277 """278 win32.SetWindowPlacement( self.get_handle(), placement )279 def get_screen_rect(self):280 """281 Get the window coordinates in the desktop.282 @rtype: L{win32.Rect}283 @return: Rectangle occupied by the window in the desktop.284 @raise WindowsError: An error occured while processing this request.285 """286 return win32.GetWindowRect( self.get_handle() )287 def get_client_rect(self):288 """289 Get the window's client area coordinates in the desktop.290 @rtype: L{win32.Rect}291 @return: Rectangle occupied by the window's client area in the desktop.292 @raise WindowsError: An error occured while processing this request.293 """294 cr = win32.GetClientRect( self.get_handle() )295 cr.left, cr.top = self.client_to_screen(cr.left, cr.top)296 cr.right, cr.bottom = self.client_to_screen(cr.right, cr.bottom)297 return cr298 # XXX TODO299 # * properties x, y, width, height300 # * properties left, top, right, bottom301 process = property(get_process, set_process, doc="")302 thread = property(get_thread, set_thread, doc="")303 classname = property(get_classname, doc="")304 style = property(get_style, doc="")305 exstyle = property(get_extended_style, doc="")306 text = property(get_text, set_text, doc="")307 placement = property(get_placement, set_placement, doc="")308#------------------------------------------------------------------------------309 def client_to_screen(self, x, y):310 """311 Translates window client coordinates to screen coordinates.312 @note: This is a simplified interface to some of the functionality of313 the L{win32.Point} class.314 @see: {win32.Point.client_to_screen}315 @type x: int316 @param x: Horizontal coordinate.317 @type y: int318 @param y: Vertical coordinate.319 @rtype: tuple( int, int )320 @return: Translated coordinates in a tuple (x, y).321 @raise WindowsError: An error occured while processing this request.322 """323 return tuple( win32.ClientToScreen( self.get_handle(), (x, y) ) )324 def screen_to_client(self, x, y):325 """326 Translates window screen coordinates to client coordinates.327 @note: This is a simplified interface to some of the functionality of328 the L{win32.Point} class.329 @see: {win32.Point.screen_to_client}330 @type x: int331 @param x: Horizontal coordinate.332 @type y: int333 @param y: Vertical coordinate.334 @rtype: tuple( int, int )335 @return: Translated coordinates in a tuple (x, y).336 @raise WindowsError: An error occured while processing this request.337 """338 return tuple( win32.ScreenToClient( self.get_handle(), (x, y) ) )339#------------------------------------------------------------------------------340 def get_parent(self):341 """342 @see: L{get_children}343 @rtype: L{Window} or None344 @return: Parent window. Returns C{None} if the window has no parent.345 @raise WindowsError: An error occured while processing this request.346 """347 hWnd = win32.GetParent( self.get_handle() )348 if hWnd:349 return self.__get_window(hWnd)350 def get_children(self):351 """352 @see: L{get_parent}353 @rtype: list( L{Window} )354 @return: List of child windows.355 @raise WindowsError: An error occured while processing this request.356 """357 return [358 self.__get_window(hWnd) \359 for hWnd in win32.EnumChildWindows( self.get_handle() )360 ]361 def get_tree(self):362 """363 @see: L{get_root}364 @rtype: dict( L{Window} S{->} dict( ... ) )365 @return: Dictionary of dictionaries forming a tree of child windows.366 @raise WindowsError: An error occured while processing this request.367 """368 subtree = dict()369 for aWindow in self.get_children():370 subtree[ aWindow ] = aWindow.get_tree()371 return subtree372 def get_root(self):373 """374 @see: L{get_tree}375 @rtype: L{Window}376 @return: If this is a child window, return the top-level window it377 belongs to.378 If this window is already a top-level window, returns itself.379 @raise WindowsError: An error occured while processing this request.380 """381 hWnd = self.get_handle()382 history = set()383 hPrevWnd = hWnd384 while hWnd and hWnd not in history:385 history.add(hWnd)386 hPrevWnd = hWnd387 hWnd = win32.GetParent(hWnd)388 if hWnd in history:389 # See: https://docs.google.com/View?id=dfqd62nk_228h28szgz390 return self391 if hPrevWnd != self.get_handle():392 return self.__get_window(hPrevWnd)393 return self394 def get_child_at(self, x, y, bAllowTransparency = True):395 """396 Get the child window located at the given coordinates. If no such397 window exists an exception is raised.398 @see: L{get_children}399 @type x: int400 @param x: Horizontal coordinate.401 @type y: int402 @param y: Vertical coordinate.403 @type bAllowTransparency: bool404 @param bAllowTransparency: If C{True} transparent areas in windows are405 ignored, returning the window behind them. If C{False} transparent406 areas are treated just like any other area.407 @rtype: L{Window}408 @return: Child window at the requested position, or C{None} if there409 is no window at those coordinates.410 """411 try:412 if bAllowTransparency:413 hWnd = win32.RealChildWindowFromPoint( self.get_handle(), (x, y) )414 else:415 hWnd = win32.ChildWindowFromPoint( self.get_handle(), (x, y) )416 if hWnd:417 return self.__get_window(hWnd)418 except WindowsError:419 pass420 return None421#------------------------------------------------------------------------------422 def is_valid(self):423 """424 @rtype: bool425 @return: C{True} if the window handle is still valid.426 """427 return win32.IsWindow( self.get_handle() )428 def is_visible(self):429 """430 @see: {show}, {hide}431 @rtype: bool432 @return: C{True} if the window is in a visible state.433 """434 return win32.IsWindowVisible( self.get_handle() )435 def is_enabled(self):436 """437 @see: {enable}, {disable}438 @rtype: bool439 @return: C{True} if the window is in an enabled state.440 """441 return win32.IsWindowEnabled( self.get_handle() )442 def is_maximized(self):443 """444 @see: L{maximize}445 @rtype: bool446 @return: C{True} if the window is maximized.447 """448 return win32.IsZoomed( self.get_handle() )449 def is_minimized(self):450 """451 @see: L{minimize}452 @rtype: bool453 @return: C{True} if the window is minimized.454 """455 return win32.IsIconic( self.get_handle() )456 def is_child(self):457 """458 @see: L{get_parent}459 @rtype: bool460 @return: C{True} if the window is a child window.461 """462 return win32.IsChild( self.get_handle() )463 is_zoomed = is_maximized464 is_iconic = is_minimized465#------------------------------------------------------------------------------466 def enable(self):467 """468 Enable the user input for the window.469 @see: L{disable}470 @raise WindowsError: An error occured while processing this request.471 """472 win32.EnableWindow( self.get_handle(), True )473 def disable(self):474 """475 Disable the user input for the window.476 @see: L{enable}477 @raise WindowsError: An error occured while processing this request.478 """479 win32.EnableWindow( self.get_handle(), False )480 def show(self, bAsync = True):481 """482 Make the window visible.483 @see: L{hide}484 @type bAsync: bool485 @param bAsync: Perform the request asynchronously.486 @raise WindowsError: An error occured while processing this request.487 """488 if bAsync:489 win32.ShowWindowAsync( self.get_handle(), win32.SW_SHOW )490 else:491 win32.ShowWindow( self.get_handle(), win32.SW_SHOW )492 def hide(self, bAsync = True):493 """494 Make the window invisible.495 @see: L{show}496 @type bAsync: bool497 @param bAsync: Perform the request asynchronously.498 @raise WindowsError: An error occured while processing this request.499 """500 if bAsync:501 win32.ShowWindowAsync( self.get_handle(), win32.SW_HIDE )502 else:503 win32.ShowWindow( self.get_handle(), win32.SW_HIDE )504 def maximize(self, bAsync = True):505 """506 Maximize the window.507 @see: L{minimize}, L{restore}508 @type bAsync: bool509 @param bAsync: Perform the request asynchronously.510 @raise WindowsError: An error occured while processing this request.511 """512 if bAsync:513 win32.ShowWindowAsync( self.get_handle(), win32.SW_MAXIMIZE )514 else:515 win32.ShowWindow( self.get_handle(), win32.SW_MAXIMIZE )516 def minimize(self, bAsync = True):517 """518 Minimize the window.519 @see: L{maximize}, L{restore}520 @type bAsync: bool521 @param bAsync: Perform the request asynchronously.522 @raise WindowsError: An error occured while processing this request.523 """524 if bAsync:525 win32.ShowWindowAsync( self.get_handle(), win32.SW_MINIMIZE )526 else:527 win32.ShowWindow( self.get_handle(), win32.SW_MINIMIZE )528 def restore(self, bAsync = True):529 """530 Unmaximize and unminimize the window.531 @see: L{maximize}, L{minimize}532 @type bAsync: bool533 @param bAsync: Perform the request asynchronously.534 @raise WindowsError: An error occured while processing this request.535 """536 if bAsync:537 win32.ShowWindowAsync( self.get_handle(), win32.SW_RESTORE )538 else:539 win32.ShowWindow( self.get_handle(), win32.SW_RESTORE )540 def move(self, x = None, y = None, width = None, height = None,541 bRepaint = True):542 """543 Moves and/or resizes the window.544 @note: This is request is performed syncronously.545 @type x: int546 @param x: (Optional) New horizontal coordinate.547 @type y: int548 @param y: (Optional) New vertical coordinate.549 @type width: int550 @param width: (Optional) Desired window width.551 @type height: int552 @param height: (Optional) Desired window height.553 @type bRepaint: bool554 @param bRepaint:555 (Optional) C{True} if the window should be redrawn afterwards.556 @raise WindowsError: An error occured while processing this request.557 """558 if None in (x, y, width, height):559 rect = self.get_screen_rect()560 if x is None:561 x = rect.left562 if y is None:563 y = rect.top564 if width is None:565 width = rect.right - rect.left566 if height is None:567 height = rect.bottom - rect.top568 win32.MoveWindow(self.get_handle(), x, y, width, height, bRepaint)569 def kill(self):570 """571 Signals the program to quit.572 @note: This is an asyncronous request.573 @raise WindowsError: An error occured while processing this request.574 """575 self.post(win32.WM_QUIT)576 def send(self, uMsg, wParam = None, lParam = None, dwTimeout = None):577 """578 Send a low-level window message syncronically.579 @type uMsg: int580 @param uMsg: Message code.581 @param wParam:582 The type and meaning of this parameter depends on the message.583 @param lParam:584 The type and meaning of this parameter depends on the message.585 @param dwTimeout: Optional timeout for the operation.586 Use C{None} to wait indefinitely.587 @rtype: int588 @return: The meaning of the return value depends on the window message.589 Typically a value of C{0} means an error occured. You can get the590 error code by calling L{win32.GetLastError}.591 """592 if dwTimeout is None:593 return win32.SendMessage(self.get_handle(), uMsg, wParam, lParam)594 return win32.SendMessageTimeout(595 self.get_handle(), uMsg, wParam, lParam,596 win32.SMTO_ABORTIFHUNG | win32.SMTO_ERRORONEXIT, dwTimeout)597 def post(self, uMsg, wParam = None, lParam = None):598 """599 Post a low-level window message asyncronically.600 @type uMsg: int601 @param uMsg: Message code.602 @param wParam:603 The type and meaning of this parameter depends on the message.604 @param lParam:605 The type and meaning of this parameter depends on the message.606 @raise WindowsError: An error occured while sending the message.607 """...

Full Screen

Full Screen

run-test.py

Source:run-test.py Github

copy

Full Screen

...99 nftables.set_echo_output(False)100 out = do_command(list_ruleset)101 nftables.set_echo_output(echo)102 return out103def get_handle(output, search):104 try:105 for item in output["nftables"]:106 if "add" in item:107 data = item["add"]108 elif "insert" in item:109 data = item["insert"]110 else:111 data = item112 k = list(search.keys())[0]113 if not k in data:114 continue115 found = True116 for key in list(search[k].keys()):117 if key == "handle":118 continue119 if not key in data[k] or search[k][key] != data[k][key]:120 found = False121 break122 if not found:123 continue124 return data[k]["handle"]125 except Exception as e:126 exit_dump(e, output)127# single commands first128do_flush()129print("Adding table t")130out = do_command(add_table)131handle = get_handle(out, add_table["add"])132out = do_list_ruleset()133handle_cmp = get_handle(out, add_table["add"])134if handle != handle_cmp:135 exit_err("handle mismatch!")136add_table["add"]["table"]["handle"] = handle137print("Adding chain c")138out = do_command(add_chain)139handle = get_handle(out, add_chain["add"])140out = do_list_ruleset()141handle_cmp = get_handle(out, add_chain["add"])142if handle != handle_cmp:143 exit_err("handle mismatch!")144add_chain["add"]["chain"]["handle"] = handle145print("Adding set s")146out = do_command(add_set)147handle = get_handle(out, add_set["add"])148out = do_list_ruleset()149handle_cmp = get_handle(out, add_set["add"])150if handle != handle_cmp:151 exit_err("handle mismatch!")152add_set["add"]["set"]["handle"] = handle153print("Adding rule")154out = do_command(add_rule)155handle = get_handle(out, add_rule["add"])156out = do_list_ruleset()157handle_cmp = get_handle(out, add_rule["add"])158if handle != handle_cmp:159 exit_err("handle mismatch!")160add_rule["add"]["rule"]["handle"] = handle161print("Adding counter")162out = do_command(add_counter)163handle = get_handle(out, add_counter["add"])164out = do_list_ruleset()165handle_cmp = get_handle(out, add_counter["add"])166if handle != handle_cmp:167 exit_err("handle mismatch!")168add_counter["add"]["counter"]["handle"] = handle169print("Adding quota")170out = do_command(add_quota)171handle = get_handle(out, add_quota["add"])172out = do_list_ruleset()173handle_cmp = get_handle(out, add_quota["add"])174if handle != handle_cmp:175 exit_err("handle mismatch!")176add_quota["add"]["quota"]["handle"] = handle177# adjust names and add items again178# Note: Handles are per-table, hence add renamed objects to first table179# to make sure assigned handle differs from first run.180add_table["add"]["table"]["name"] = "t2"181add_chain["add"]["chain"]["name"] = "c2"182add_set["add"]["set"]["name"] = "s2"183add_counter["add"]["counter"]["name"] = "c2"184add_quota["add"]["quota"]["name"] = "q2"185print("Adding table t2")186out = do_command(add_table)187handle = get_handle(out, add_table["add"])188if handle == add_table["add"]["table"]["handle"]:189 exit_err("handle not changed in re-added table!")190print("Adding chain c2")191out = do_command(add_chain)192handle = get_handle(out, add_chain["add"])193if handle == add_chain["add"]["chain"]["handle"]:194 exit_err("handle not changed in re-added chain!")195print("Adding set s2")196out = do_command(add_set)197handle = get_handle(out, add_set["add"])198if handle == add_set["add"]["set"]["handle"]:199 exit_err("handle not changed in re-added set!")200print("Adding rule again")201out = do_command(add_rule)202handle = get_handle(out, add_rule["add"])203if handle == add_rule["add"]["rule"]["handle"]:204 exit_err("handle not changed in re-added rule!")205print("Adding counter c2")206out = do_command(add_counter)207handle = get_handle(out, add_counter["add"])208if handle == add_counter["add"]["counter"]["handle"]:209 exit_err("handle not changed in re-added counter!")210print("Adding quota q2")211out = do_command(add_quota)212handle = get_handle(out, add_quota["add"])213if handle == add_quota["add"]["quota"]["handle"]:214 exit_err("handle not changed in re-added quota!")215# now multiple commands216# reset name changes again217add_table["add"]["table"]["name"] = "t"218add_chain["add"]["chain"]["name"] = "c"219add_set["add"]["set"]["name"] = "s"220add_counter["add"]["counter"]["name"] = "c"221add_quota["add"]["quota"]["name"] = "q"222do_flush()223print("doing multi add")224add_multi = [ add_table, add_chain, add_set, add_rule ]225out = do_command(add_multi)226thandle = get_handle(out, add_table["add"])227chandle = get_handle(out, add_chain["add"])228shandle = get_handle(out, add_set["add"])229rhandle = get_handle(out, add_rule["add"])230out = do_list_ruleset()231if thandle != get_handle(out, add_table["add"]):232 exit_err("table handle mismatch!")233if chandle != get_handle(out, add_chain["add"]):234 exit_err("chain handle mismatch!")235if shandle != get_handle(out, add_set["add"]):236 exit_err("set handle mismatch!")237if rhandle != get_handle(out, add_rule["add"]):...

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 autotest 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