How to use ErrCheckBool method in robotframework-androidlibrary

Best Python code snippet using robotframework-androidlibrary_python

winprocess.py

Source:winprocess.py Github

copy

Full Screen

...39LPVOID = c_void_p40LPBYTE = POINTER(BYTE)41LPDWORD = POINTER(DWORD)42LPBOOL = POINTER(BOOL)43def ErrCheckBool(result, func, args):44 """errcheck function for Windows functions that return a BOOL True45 on success"""46 if not result:47 raise WinError()48 return args49# AutoHANDLE50class AutoHANDLE(HANDLE):51 """Subclass of HANDLE which will call CloseHandle() on deletion."""52 53 CloseHandleProto = WINFUNCTYPE(BOOL, HANDLE)54 CloseHandle = CloseHandleProto(("CloseHandle", windll.kernel32))55 CloseHandle.errcheck = ErrCheckBool56 57 def Close(self):58 if self.value and self.value != HANDLE(-1).value:59 self.CloseHandle(self)60 self.value = 061 62 def __del__(self):63 self.Close()64 def __int__(self):65 return self.value66def ErrCheckHandle(result, func, args):67 """errcheck function for Windows functions that return a HANDLE."""68 if not result:69 raise WinError()70 return AutoHANDLE(result)71# PROCESS_INFORMATION structure72class PROCESS_INFORMATION(Structure):73 _fields_ = [("hProcess", HANDLE),74 ("hThread", HANDLE),75 ("dwProcessID", DWORD),76 ("dwThreadID", DWORD)]77 def __init__(self):78 Structure.__init__(self)79 80 self.cb = sizeof(self)81LPPROCESS_INFORMATION = POINTER(PROCESS_INFORMATION)82# STARTUPINFO structure83class STARTUPINFO(Structure):84 _fields_ = [("cb", DWORD),85 ("lpReserved", LPWSTR),86 ("lpDesktop", LPWSTR),87 ("lpTitle", LPWSTR),88 ("dwX", DWORD),89 ("dwY", DWORD),90 ("dwXSize", DWORD),91 ("dwYSize", DWORD),92 ("dwXCountChars", DWORD),93 ("dwYCountChars", DWORD),94 ("dwFillAttribute", DWORD),95 ("dwFlags", DWORD),96 ("wShowWindow", WORD),97 ("cbReserved2", WORD),98 ("lpReserved2", LPBYTE),99 ("hStdInput", HANDLE),100 ("hStdOutput", HANDLE),101 ("hStdError", HANDLE)102 ]103LPSTARTUPINFO = POINTER(STARTUPINFO)104SW_HIDE = 0105STARTF_USESHOWWINDOW = 0x01106STARTF_USESIZE = 0x02107STARTF_USEPOSITION = 0x04108STARTF_USECOUNTCHARS = 0x08109STARTF_USEFILLATTRIBUTE = 0x10110STARTF_RUNFULLSCREEN = 0x20111STARTF_FORCEONFEEDBACK = 0x40112STARTF_FORCEOFFFEEDBACK = 0x80113STARTF_USESTDHANDLES = 0x100114# EnvironmentBlock115class EnvironmentBlock:116 """An object which can be passed as the lpEnv parameter of CreateProcess.117 It is initialized with a dictionary."""118 def __init__(self, dict):119 if not dict:120 self._as_parameter_ = None121 else:122 values = ["%s=%s" % (key, value)123 for (key, value) in dict.iteritems()]124 values.append("")125 self._as_parameter_ = LPCWSTR("\0".join(values))126 127# CreateProcess()128CreateProcessProto = WINFUNCTYPE(BOOL, # Return type129 LPCWSTR, # lpApplicationName130 LPWSTR, # lpCommandLine131 LPVOID, # lpProcessAttributes132 LPVOID, # lpThreadAttributes133 BOOL, # bInheritHandles134 DWORD, # dwCreationFlags135 LPVOID, # lpEnvironment136 LPCWSTR, # lpCurrentDirectory137 LPSTARTUPINFO, # lpStartupInfo138 LPPROCESS_INFORMATION # lpProcessInformation139 )140CreateProcessFlags = ((1, "lpApplicationName", None),141 (1, "lpCommandLine"),142 (1, "lpProcessAttributes", None),143 (1, "lpThreadAttributes", None),144 (1, "bInheritHandles", True),145 (1, "dwCreationFlags", 0),146 (1, "lpEnvironment", None),147 (1, "lpCurrentDirectory", None),148 (1, "lpStartupInfo"),149 (2, "lpProcessInformation"))150def ErrCheckCreateProcess(result, func, args):151 ErrCheckBool(result, func, args)152 # return a tuple (hProcess, hThread, dwProcessID, dwThreadID)153 pi = args[9]154 return AutoHANDLE(pi.hProcess), AutoHANDLE(pi.hThread), pi.dwProcessID, pi.dwThreadID155CreateProcess = CreateProcessProto(("CreateProcessW", windll.kernel32),156 CreateProcessFlags)157CreateProcess.errcheck = ErrCheckCreateProcess158# flags for CreateProcess159CREATE_BREAKAWAY_FROM_JOB = 0x01000000160CREATE_DEFAULT_ERROR_MODE = 0x04000000161CREATE_NEW_CONSOLE = 0x00000010162CREATE_NEW_PROCESS_GROUP = 0x00000200163CREATE_NO_WINDOW = 0x08000000164CREATE_SUSPENDED = 0x00000004165CREATE_UNICODE_ENVIRONMENT = 0x00000400...

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 robotframework-androidlibrary 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