Selenium 行为调试 vscode - python

Selenium behave debugging with vscode - python

我有一个用 electron 制作的桌面应用程序,它运行一个反应项目。我的应用程序已经存在一些测试,现在我想将它们放入 vscode 用于调试和实现它们。

我能够启动我的 exe,加载所有文件(例如,步骤文件中的断点在“给定”行中触发)并调试 enviroment.py 文件。我还能够(用于测试)在 before_all 功能中与我的应用进行交互。

我的问题是,当第一个触发 before_all 函数和下一个 after_all 函数时,其他以 0 steps passed, 0 failed, 0 skipped, 0 undefined.

结尾的文件(功能和步骤)被忽略

这是我在 launch.json.vscode 文件夹中的配置:

{
    "name": "Python: all",
    "type": "python",
    "request": "launch",
    "module": "behave",
    "console": "integratedTerminal",
    "args": [
        "--no-capture",
        "--no-capture-stderr",
        "${workspaceFolder}/features/steps"
    ]
}

如果有用,首先集成到 vscode 中,在 cmd 中使用以下命令一切正常:behave --no-capture > logs.txt

作为 foler 结构我有

root
-> features
-> -> steps

谢谢

更新 1:更多信息和代码 features/enviroment.py

#..imports..

apiPath = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
if apiPath not in sys.path:
    sys.path.append(apiPath)
    
def before_all(context):
    #..code..
    context.my_app.open_app()
    sleep(2)
    
    context.queries_logger = logging.getLogger('MainThread')
    context.queries_logger.setLevel(logging.INFO)

    context.formatter = logging.Formatter('%(asctime)-15s %(threadName)-15s'
                                  ' %(levelname)-8s %(module)-15s:%(lineno)-8s %(message)s')
                                                                  
def before_feature(context, feature):
    #..code.. NEVER RUNS!
    
def after_all(context):
    context.my_app.close_app()

features/blabla.特征

Feature: Test of the parameters configuration of the XXX

  @XXX_XX @wip
  Scenario: User sets ...
    Given User add a XXXXX in the configuration file
      When  User enters in the ....
      Then  User checks that .....

features/steps/blabla.步骤

from time import sleep
from behave import *

@Given("User add a XXXXX in the configuration file")
def add_xxxxxxx(context):
    #NEVER RUNS!

@When("User enters .....")
def enter_xxxxxx(context):
    #NEVER RUNS!

@Then("User checks .......")
def check_xxxxx(context):
    #NEVER RUNS!

我总是得到 0 features passed, 0 failed, 0 skipped

我找到了可行的解决方案。

"${workspaceFolder}/features" 而不是 "${workspaceFolder}/features/steps"

{
    "name": "Python: all",
    "type": "python",
    "request": "launch",
    "module": "behave",
    "console": "integratedTerminal",
    "args": [
        "--no-capture",
        "--no-capture-stderr",
        "${workspaceFolder}/features"
    ]
}

并修复了 os.path 目录,该目录在某些脚本中被正确编辑