程序问答   发布时间:2022-06-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Selenium 使用 vscode 进行调试 - python大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决SELEnium 使用 vscode 进行调试 - python?

开发过程中遇到SELEnium 使用 vscode 进行调试 - python的问题如何解决?下面主要结合日常开发的经验,给出你关于SELEnium 使用 vscode 进行调试 - python的解决方法建议,希望对你解决SELEnium 使用 vscode 进行调试 - python有所启发或帮助;

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

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

我的问题是,当首先触发 before_all@H_772_6@ 函数和下一个 after_all@H_772_6@ 函数时,其他以 0 steps passed,0 Failed,0 skipped,0 undefined@H_772_6@ 结尾的文件(功能和步骤)会被忽略。

这是我在 launch.Json@H_772_6@ 中的配置到 .vscode@H_772_6@ 文件夹:

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

如果有用,首先在 cmd 中使用以下命令可以很好地集成到 vscode:behave --no-capture > logs.txt@H_772_6@

作为文件夹结构我有

root
-> features
-> -> steps
@H_772_6@

谢谢

更新 1:更多信息和代码 功能/环境.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()
@H_772_6@

功能/blabla.feature

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 .....
@H_772_6@

功能/步骤/blabla.step

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!
@H_772_6@

而且我总是得到 0 features passed,0 skipped@H_772_6@

解决方法

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

"${workspaceFolder}/features" 代替 "${workspaceFolder}/features/steps"

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

并用正确的脚本修复了在某些脚本中编辑的 os.path 目录

大佬总结

以上是大佬教程为你收集整理的Selenium 使用 vscode 进行调试 - python全部内容,希望文章能够帮你解决Selenium 使用 vscode 进行调试 - python所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。