首页 > 解决方案 > 从代理或客户端运行数据表的 Specflow 测试在 Azure 管道 VS 测试任务上失败

问题描述

BLUF : 没有 Specflow 数据表测试从 Azure Pipeline 运行良好使用 Specflow 数据表测试从 Azure Pipeline 失败

设置

  1. SpecFlow 3.1 或 3.3
  2. MSTest 作为测试运行者
  3. 包.config
  4. .feature.cs 文件是使用 SpecFlow.Tools.MsBuild.Generation NuGet 包生成的
  5. VS 2019
  6. Visual Studio 扩展设置中的 SpecFlowSingleFileGenerator 自定义工具选项已禁用
  7. .NET Framework 4.5.1(自托管计算机上的框架 .NET 4.7)
  8. TFS/VSTS/Azure DevOps – 任务 – Visual Studio 测试任务 2.*

配置

  1. Visual Studio C# Selenium 测试项目
  2. 使用范围报告
  3. DotNetSeleniumExtras 页面对象
  4. MSTestTestAdapter 和框架
  5. Selenium 和 Chrome 驱动程序
  6. 特征文件中的数据表
  7. 构建或发布管道上的 Azure Visual Studio 任务
  8. 测试程序集使用 .exe 而不是 .dll 运行
  9. Azure VSTest 任务使用 testhost.x86.exe

行动:

  1. 在 Visual Studio 中使用数据表创建 Selenium Specflow 测试
  2. 推送到回购
  3. 使用 Visual Studio 测试任务设置构建或发布管道(测试的行为方式相同)
  4. 运行管道

结果:

  1. 通过 Visual Studio 测试资源管理器从客户端机器上运行带有或不带有数据表的测试而不会出现错误
  2. 通过 Visual Studio 测试资源管理器或使用 vstest.console.exe 从命令行运行时,使用或不使用数据表的测试在自定义本地代理计算机上运行时不会出现错误
  3. 没有数据表的测试通过 Visual Studio 测试资源管理器从自定义本地代理计算机运行,或者在命令行使用 vstest.console.exe 运行时没有错误

使用数据表的测试失败,并出现来自 Azure Pipeline Visual Studio 任务的以下错误

dmp 文件错误:进程名称:testhost.x86.exe:C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\Common7\IDE\Extensions\TestPlatform\testhost.x86.exe 进程架构:x86 异常代码: 0xC0000005 异常信息:线程试图读取或写入它没有适当访问权限的虚拟地址。堆信息:不存在

系统信息

Azure PipelineError 输出:

Test method HappyTest.Features.CPUF.YPUCC_1 threw exception: 
System.NullReferenceException: Object reference not set to an instance of an object.

AventStack.ExtentReports.Model.ExceptionInfo..ctor(Exception ex)

AventStack.ExtentReports.ExtentTest.Log(Status status, Exception ex, MediaEntityModelProvider provider)

AventStack.ExtentReports.ExtentTest.Fail(Exception ex, MediaEntityModelProvider provider)

UtilityLibrary.Utilities.Hooks.Hooks.InsertReportingSteps(ScenarioContext InjectedText) in D:\DevOpsAgent\_work\8\s\UtilityLibrary\Utilities\Hooks\Hooks.cs: line 188 lambda_method(Closure , IContextManager , ScenarioContext )

TechTalk.SpecFlow.Bindings.BindingInvoker.InvokeBinding(IBinding binding, IContextManager contextManager, Object[] arguments, ITestTracer testTracer, TimeSpan& duration) in D:\a\1\s\TechTalk.SpecFlow\Bindings\BindingInvoker.cs: line 69

TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.InvokeHook(IBindingInvoker invoker, IHookBinding hookBinding, HookType hookType) in D:\a\1\s\TechTalk.SpecFlow\Infrastructure\TestExecutionEngine.cs: line 351

TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.FireEvents(HookType hookType) in D:\a\1\s\TechTalk.SpecFlow\Infrastructure\TestExecutionEngine.cs: line 340

TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.FireScenarioEvents(HookType bindingEvent) in D:\a\1\s\TechTalk.SpecFlow\Infrastructure\TestExecutionEngine.cs: line 321

TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.OnStepEnd() in D:\a\1\s\TechTalk.SpecFlow\Infrastructure\TestExecutionEngine.cs: line 304

TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.ExecuteStep(IContextManager contextManager, StepInstance stepInstance) in D:\a\1\s\TechTalk.SpecFlow\Infrastructure\TestExecutionEngine.cs: line 470

TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.Step(StepDefinitionKeyword stepDefinitionKeyword, String keyword, String text, 
String multilineTextArg, Table tableArg) in D:\a\1\s\TechTalk.SpecFlow\Infrastructure\TestExecutionEngine.cs: line 581

TechTalk.SpecFlow.TestRunner.Given(String text, String multilineTextArg, Table tableArg, String keyword) in D:\a\1\s\TechTalk.SpecFlow\TestRunner.cs: line 79

HappyTest.Features.CPUF.YPUCC(Anonymized Data Fields Here) in D:\DevOpsAgent\_work\8\s\HappyTest\Features\CreatePersonalUser.feature: line 12

HappyTest.Features.CPUF.YPUCC_1() in D:\DevOpsAgent\_work\8\s\HappyTest\Features\CreatePersonalUser.feature: line 11

-> Loading plugin D:\DevOpsAgent\_work\8\s\HappyTest\bin\Release\TechTalk.SpecFlow.MSTest.SpecFlowPlugin.dll

-> Using app.config

Given The user navigates to Sbn Test
:: The page type is HappyTest.Pages.BasePage
:: Sbn Test Page Displayed
-> done: BaseScenarioSteps.GivenUserNavigatesToSbnTest() (2.0s)
Given The user selects Personal Subscribe Yearly
:: The page type is HappyTest.Pages.SbnHome
-> error: Timed out after 10 seconds
:: WebDriver Stopped

YAML

    pool:
      name: qa-automation
      demands:
      - msbuild
      - visualstudio
    
    variables:
      BuildPlatform: ''
      BuildConfiguration: 'Debug'
    
    steps:
    - task: NuGetToolInstaller@1
      displayName: 'Use NuGet 5.3.1'
      inputs:
        versionSpec: 5.3.1
    
    - task: NuGetCommand@2
      displayName: 'NuGet restore'
      inputs:
        restoreSolution: SeleniumTest.sln
    
    - task: VSBuild@1
      displayName: 'Build solution SeleniumTest.sln'
      inputs:
        solution: SeleniumTest.sln
        platform: '$(BuildPlatform)'
        configuration: '$(BuildConfiguration)'
    
    - task: PublishSymbols@2
      displayName: 'Publish symbols path'
      inputs:
        PublishSymbols: false
    
    - task: CopyFiles@2
      displayName: 'Copy Files to: $(build.artifactstagingdirectory)'
      inputs:
        SourceFolder: '$(system.defaultworkingdirectory)'
        Contents: '**\bin\$(BuildConfiguration)\**'
        TargetFolder: '$(build.artifactstagingdirectory)'
        CleanTargetFolder: true
        OverWrite: true
    
    - task: PublishBuildArtifacts@1
      displayName: 'Publish Artifact: drop'
    
    - task: VisualStudioTestPlatformInstaller@1
      displayName: 'Visual Studio Test Platform Installer'
      inputs:
        versionSelector: latestStable
    
    - task: VSTest@2
      displayName: 'VsTest - testAssemblies'
      inputs:
        testAssemblyVer2: |
         !**\*TestAdapter.dll
         **\HappyTest.exe
         !**\obj\**
        runTestsInIsolation: true
        otherConsoleOptions: '/Tests:Happy_1'
        testRunTitle: 'Validate Specflow Data Table Tests'
        diagnosticsEnabled: true
        collectDumpOn: always

VS 操作尝试失败

  1. 将 SpecFlow 更新到 Beta 3.3
  2. 更新了 Selenium 和大多数其他软件包
  3. 更新了 app.config 中的依赖项
  4. 将 .NET Framework 更新到 4.6.2,然后恢复
  5. 在浏览器渲染之前和之后添加了额外的等待
  6. 尝试在构建平台上的 x86 与 x64 与任何 cpu 架构之间切换
  7. 使用完整的 app.config
  8. 添加了 60 秒 WebDriverWait

Azure 操作尝试失败:

  1. 更改了构建和发布任务的多个参数
  2. 将所有变量从发布更改为调试
  3. 在 Azure 和本地代理上尝试测试
  4. 将 Visual Studio 版本从 2017 更改为 2019 和最新的 VS 构建任务
  5. 隔离检查运行测试
  6. 推送包文件夹以释放 Drop

标签: visual-studioseleniumazure-pipelinesspecflowselenium-extent-report

解决方案


推荐阅读