Python 如何使用pywinauto运行简单的pytest bdd测试?
我正在尝试设置pytest bdd pywinauto测试,但无法使其正常工作 我找不到任何pywinauto的简单示例。pytest bdd的官方文档只有一个selenium示例,但我无法理解它,因为我不熟悉它 这是我的项目结构,同一文件夹中只有两个文件: 食物特征 测试_foo.py 这是Python 如何使用pywinauto运行简单的pytest bdd测试?,python,pytest,pywinauto,Python,Pytest,Pywinauto,我正在尝试设置pytest bdd pywinauto测试,但无法使其正常工作 我找不到任何pywinauto的简单示例。pytest bdd的官方文档只有一个selenium示例,但我无法理解它,因为我不熟悉它 这是我的项目结构,同一文件夹中只有两个文件: 食物特征 测试_foo.py 这是foo.feature文件内容: Feature: Type stuff The user should be able to type stuff into notepad. Scena
foo.feature
文件内容:
Feature: Type stuff
The user should be able to type stuff into notepad.
Scenario: Type a sentence
Given Application object exists
When I start notepad
And Focus on the window
And I type some stuff
Then Typed stuff should be visible
这是test\u foo.py
文件内容:
Feature: Type stuff
The user should be able to type stuff into notepad.
Scenario: Type a sentence
Given Application object exists
When I start notepad
And Focus on the window
And I type some stuff
Then Typed stuff should be visible
导入pytest
从pytest_bdd导入场景中,给定解析器
从pywinauto.application导入应用程序
从pywinauto.keyboard导入发送键
@场景(‘foo.feature’、‘键入句子’)
def test_foo():
通过
@pytest.fixture()
def app():
返回应用程序()
@给定(“应用程序对象存在”)
def应用程序_存在(应用程序):
在locals()中断言“app”
@何时(“我启动记事本”)
def启动记事本(应用程序):
app.start(“notepad.exe”)
@当(“聚焦在窗口上”)
def记事本焦点(应用程序):
app.top_window().set_focus()
@当(“我输入一些东西”)
def type_stuff():
发送_键(“你好,世界!”,带_空格=True)
@然后(“键入的内容应可见”)
def键入的内容可见(应用程序):
编辑字段=app.top\u window().window(class\u name='edit')
断言编辑字段.text()[0]=“你好,世界!”
由于某种原因,我无法让“then”夹具工作。测试失败,出现以下错误:
E pytest_bdd.exceptions.StepDefinitionNotFoundError: Step definition is not found: When "I type some stuff
E Then Typed stuff should be visible". Line 9 in scenario "Type a sentence" in the feature "C:\Users\...\foo.feature
如果我从
foo.feature
文件中删除“then”测试,测试将运行,文本将输入记事本。由于某种原因,“then”会把事情搞得一团糟,编辑器里什么也打不出来。Hi Joe,你找到办法了吗?如果是的话,我很想知道!:)嗨,乔,你找到办法了吗?如果是的话,我很想知道!:)