【发布时间】:2021-11-02 20:35:05
【问题描述】:
我是 Python 和 Selenium 测试的新手,请有人解释一下为什么截屏和生成魅力报告不能一起工作。 附件是我的测试用例步骤中的示例代码。
@then('the home page does not open with invalid username')
def assert_login_unsuccessful(context):
try:
error_Message = login_error_message(context)
except:
assert False, "Test Failed"
context.driver.close()
if login_error_message(context) == "Please, enter valid credentials":
print("***Login Not Successful - Home page is not open***")
#allure.attach('screenshot2', context.driver.get_screenshot_as_png(), type=allure.attachment_type.PNG)
#myScreenshot = pyautogui.screenshot()
#myScreenshot.save(r'C:\Users\lakshmi krishnaswamy\screenshots\assert_login_unsuccessful_error_message_invalid_username.png')
assert True, "Test Passed"
context.driver.close()
我正在使用以下命令来运行 allure 行为并生成 json 文件
behave -f allure_behave.formatter:AllureFormatter -o reports/ features/d3a-login.feature
当我取消注释 pyautogyi 截图部分时,我收到以下错误
C:\Users\lakshmi krishnaswamy\PycharmProjects\d3aBehaveProjectTestSuite>behave -f allure_behave.formatter:AllureFormatter -o reports/ features/d3a-login.feature
DevTools listening on ws://127.0.0.1:55231/devtools/browser/52989908-98f0-4004-a586-b68ea6d9b82d
[2956:4420:0905/131111.519:ERROR:device_event_log_impl.cc(214)] [13:11:11.518] USB: usb_device_handle_win.cc:1048 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F)
DevTools listening on ws://127.0.0.1:59017/devtools/browser/31cb4a4f-fa22-419b-9f4a-48490751dd7a
[18084:16428:0905/131121.810:ERROR:device_event_log_impl.cc(214)] [13:11:21.810] USB: usb_device_handle_win.cc:1048 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F)
DevTools listening on ws://127.0.0.1:62188/devtools/browser/249a6670-fd77-484a-9552-5dd7f1adcd0a
[948:18280:0905/131128.924:ERROR:device_event_log_impl.cc(214)] [13:11:28.924] USB: usb_device_handle_win.cc:1048 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F)
Failing scenarios:
features/d3a-login.feature:17 Failure login to D3O with invalid username
0 features passed, 1 failed, 0 skipped
2 scenarios passed, 1 failed, 0 skipped
14 steps passed, 1 failed, 0 skipped, 0 undefined
Took 0m25.668s
Exception ignored in: <function Popen.__del__ at 0x000002B064F6FCA0>
Traceback (most recent call last):
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2032.0_x64__qbz5n2kfra8p0\lib\subprocess.py", line 1055, in __del__
self._internal_poll(_deadstate=_maxsize)
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2032.0_x64__qbz5n2kfra8p0\lib\subprocess.py", line 1457, in _internal_poll
if _WaitForSingleObject(self._handle, 0) == _WAIT_OBJECT_0:
OSError: [WinError 6] The handle is invalid
当我取消注释 allure attach 时,我收到如下所示的类似错误
C:\Users\lakshmi krishnaswamy\PycharmProjects\d3aBehaveProjectTestSuite>behave -f allure_behave.formatter:AllureFormatter -o reports/ features/d3a-login.feature
DevTools listening on ws://127.0.0.1:59812/devtools/browser/b1be990e-c456-4cae-b204-1e0242f55a9a
[8968:6156:0905/131625.417:ERROR:device_event_log_impl.cc(214)] [13:16:25.418] USB: usb_device_handle_win.cc:1048 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F)
DevTools listening on ws://127.0.0.1:49256/devtools/browser/45937e86-f1e4-4a17-a90f-7ca369dde276
[18080:10828:0905/131634.363:ERROR:device_event_log_impl.cc(214)] [13:16:34.364] USB: usb_device_handle_win.cc:1048 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F)
DevTools listening on ws://127.0.0.1:61518/devtools/browser/b31c1d7b-c0a5-465a-824a-82e5a3e3b59c
[23544:9780:0905/131641.853:ERROR:device_event_log_impl.cc(214)] [13:16:41.853] USB: usb_device_handle_win.cc:1048 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F)
Failing scenarios:
features/d3a-login.feature:17 Failure login to D3O with invalid username
0 features passed, 1 failed, 0 skipped
2 scenarios passed, 1 failed, 0 skipped
14 steps passed, 1 failed, 0 skipped, 0 undefined
Took 0m28.658s
Exception ignored in: <function Popen.__del__ at 0x0000017B2057FCA0>
Traceback (most recent call last):
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2032.0_x64__qbz5n2kfra8p0\lib\subprocess.py", line 1055, in __del__
self._internal_poll(_deadstate=_maxsize)
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2032.0_x64__qbz5n2kfra8p0\lib\subprocess.py", line 1457, in _internal_poll
if _WaitForSingleObject(self._handle, 0) == _WAIT_OBJECT_0:
OSError: [WinError 6] The handle is invalid
请告诉我如何用 allure 截取屏幕截图
【问题讨论】:
标签: python allure python-behave