发生场景,使用HTMLReport运行测试用例
错误:
_ole32.CoCreateInstance(byref(clsid), punkouter, clsctx, byref(iid), byref(p))
File "_ctypes/callproc.c", line 947, in GetResult
OSError: [WinError -2147221008] 尚未调用 CoInitialize。
2020-10-22 10:42:12,131 19808 ERROR result.py(171) - 测试产生错误: test_division (calc.CalcTestCase)
Traceback (most recent call last):
File "D:\代码\js_learning\calc.py", line 37, in tearDown
self.wc.ButtonControl(Name='清除').Click()
File "D:\venv\northking\lib\site-packages\uiautomation\uiautomation.py", line 6007, in Click
point = self.MoveCursorToInnerPos(x, y, ratioX, ratioY, simulateMove)
File "D:\venv\northking\lib\site-packages\uiautomation\uiautomation.py", line 5968, in MoveCursorToInnerPos
rect = self.BoundingRectangle
File "D:\venv\northking\lib\site-packages\uiautomation\uiautomation.py", line 5390, in BoundingRectangle
rect = self.Element.CurrentBoundingRectangle
File "D:\venv\northking\lib\site-packages\uiautomation\uiautomation.py", line 5704, in Element
self.Refind(maxSearchSeconds=TIME_OUT_SECOND, searchIntervalSeconds=self.searchInterval)
File "D:\venv\northking\lib\site-packages\uiautomation\uiautomation.py", line 5949, in Refind
if not self.Exists(maxSearchSeconds, searchIntervalSeconds, False if raiseException else DEBUG_EXIST_DISAPPEAR):
File "D:\venv\northking\lib\site-packages\uiautomation\uiautomation.py", line 5891, in Exists
if prev and not prev._element and not prev.Exists(maxSearchSeconds, searchIntervalSeconds):
File "D:\venv\northking\lib\site-packages\uiautomation\uiautomation.py", line 5899, in Exists
control = FindControl(self.searchFromControl, self._CompareFunction, self.searchDepth, False, self.foundIndex)
File "D:\venv\northking\lib\site-packages\uiautomation\uiautomation.py", line 7722, in FindControl
control = GetRootControl()
File "D:\venv\northking\lib\site-packages\uiautomation\uiautomation.py", line 7504, in GetRootControl
return Control.CreateControlFromElement(AutomationClient.instance().IUIAutomation.GetRootElement())
File "D:\venv\northking\lib\site-packages\uiautomation\uiautomation.py", line 51, in instance
cls.instance = cls()
File "D:\venv\northking\lib\site-packages\uiautomation\uiautomation.py", line 62, in init
raise ex
File "D:\venv\northking\lib\site-packages\uiautomation\uiautomation.py", line 57, in init
self.IUIAutomation = comtypes.client.CreateObject("{ff48dba4-60ef-4201-aa87-54103eef594e}", interface=self.UIAutomationCore.IUIAutomation)
File "D:\venv\northking\lib\site-packages\comtypes\client_init.py", line 238, in CreateObject
obj = comtypes.CoCreateInstance(clsid, clsctx=clsctx, interface=interface)
File "D:\venv\northking\lib\site-packages\comtypes_init.py", line 1226, in CoCreateInstance
_ole32.CoCreateInstance(byref(clsid), punkouter, clsctx, byref(iid), byref(p))
File "_ctypes/callproc.c", line 947, in GetResult
OSError: [WinError -2147221008] 尚未调用 CoInitialize。
解决方法,进到comtypes里面加了一句代码:
源代码:
def CoCreateInstance(clsid, interface=None, clsctx=None, punkouter=None):
"""The basic windows api to create a COM class object and return a
pointer to an interface.
"""
if clsctx is None:
clsctx = CLSCTX_SERVER
if interface is None:
interface = IUnknown
p = POINTER(interface)()
iid = interface.iid
_ole32.CoCreateInstance(byref(clsid), punkouter, clsctx, byref(iid), byref(p))
return p
修改后:
def CoCreateInstance(clsid, interface=None, clsctx=None, punkouter=None):
"""The basic windows api to create a COM class object and return a
pointer to an interface.
"""
if clsctx is None:
clsctx = CLSCTX_SERVER
if interface is None:
interface = IUnknown
p = POINTER(interface)()
iid = interface.iid
CoInitialize()
_ole32.CoCreateInstance(byref(clsid), punkouter, clsctx, byref(iid), byref(p))
return p
增加了"CoInitialize()"
Then , It works!
2020-10-22 10:43:21,023 16136 INFO test_runner.py(154) - 预计并发线程数:1
2020-10-22 10:43:23,324 4712 INFO result.py(65) - 开始测试: test_division (calc.CalcTestCase)
2020-10-22 10:43:32,647 4712 INFO result.py(152) - 测试执行通过: test_division (calc.CalcTestCase)
2020-10-22 10:43:32,648 4712 INFO result.py(86) - 测试结束: test_division (calc.CalcTestCase)
2020-10-22 10:43:32,648 4712 INFO result.py(87) - 耗时: 9.322458267211914
2020-10-22 10:43:32,648 4712 INFO result.py(65) - 开始测试: test_minus (calc.CalcTestCase)
2020-10-22 10:43:41,308 4712 INFO result.py(152) - 测试执行通过: test_minus (calc.CalcTestCase)
2020-10-22 10:43:41,308 4712 INFO result.py(86) - 测试结束: test_minus (calc.CalcTestCase)
2020-10-22 10:43:41,308 4712 INFO result.py(87) - 耗时: 8.660779237747192
2020-10-22 10:43:41,308 4712 INFO result.py(65) - 开始测试: test_multiplication (calc.CalcTestCase)
2020-10-22 10:43:49,957 4712 INFO result.py(152) - 测试执行通过: test_multiplication (calc.CalcTestCase)
2020-10-22 10:43:49,957 4712 INFO result.py(86) - 测试结束: test_multiplication (calc.CalcTestCase)
2020-10-22 10:43:49,958 4712 INFO result.py(87) - 耗时: 8.64855146408081
2020-10-22 10:43:49,958 4712 INFO result.py(65) - 开始测试: test_plus (calc.CalcTestCase)
2020-10-22 10:43:58,605 4712 INFO result.py(152) - 测试执行通过: test_plus (calc.CalcTestCase)
2020-10-22 10:43:58,605 4712 INFO result.py(86) - 测试结束: test_plus (calc.CalcTestCase)
2020-10-22 10:43:58,605 4712 INFO result.py(87) - 耗时: 8.645690202713013
2020-10-22 10:43:59,407 16136 INFO test_runner.py(191) -
Pass test_division (calc.CalcTestCase) 测试除法计算12/3=4
Pass test_minus (calc.CalcTestCase) 测试减法计算7-5=2
Pass test_multiplication (calc.CalcTestCase) 测试乘法计算7*5=35
Pass test_plus (calc.CalcTestCase) 测试加法计算7+5=12
2020-10-22 10:43:59,411 16136 INFO test_runner.py(211) -
测试结束!
运行时间: 0:00:38.703584
共计执行用例数量:4
执行成功用例数量:4
执行失败用例数量:0
跳过执行用例数量:0
产生异常用例数量:0
网友评论