TestProject Forum

Stub OpenSDK C# test fails in ChromeDriver constructor

Trying to convert my .NET test project from SDK to OpenSDK. I’m getting a NullReferenceException on the following line:

this.driver = new ChromeDriver(token: DevToken, chromeOptions: options, projectName: "Foo", jobName: "Bar", disableReports: false);

Here’s what I get:

System.NullReferenceException
  HResult=0x80004003
  Message=Object reference not set to an instance of an object.
  Source=TestProject.OpenSDK
  StackTrace:
   at TestProject.OpenSDK.Internal.CallStackAnalysis.SpecFlowAnalyzer.IsSpecFlow(MethodBase method)
   at TestProject.OpenSDK.Internal.CallStackAnalysis.StackTraceHelper.<>c.<TryDetectSpecFlow>b__9_1(MethodBase m)
   at System.Linq.Enumerable.TryGetFirst[TSource](IEnumerable`1 source, Func`2 predicate, Boolean& found)
   at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source, Func`2 predicate)
   at TestProject.OpenSDK.Internal.CallStackAnalysis.StackTraceHelper.TryDetectSpecFlow()
   at TestProject.OpenSDK.Drivers.BaseDriver..ctor(Uri remoteAddress, String token, DriverOptions driverOptions, String projectName, String jobName, Boolean disableReports)
   at TestProject.OpenSDK.Drivers.Web.ChromeDriver..ctor(Uri remoteAddress, String token, ChromeOptions chromeOptions, String projectName, String jobName, Boolean disableReports)
   at MyProject.Tests.Ui.UnitTest1..ctor() in C:\dev\MYPROJECT\UnitTest1.cs:line 27

What I already tried

I thought: maybe I need the TestProject.OpenSDK.SpecFlowPlugin NuGet package, so I installed that and rebuilt. Same error.

NOTE: my TestProject.SDK was working fine and launching Chrome and sending reports to the cloud dashboard…

Hello @zblocker
Can you please share the code which triggers this error?
By the way, you can also open the issue directly to the developers at

First of all, @ran.tzur, great suggestion about opening a GitHub issue, I will do that and link back here.

New OpenSDK code (that fails)

UnitTest1.cs

using Microsoft.IdentityModel.Tokens;
using OpenQA.Selenium;
using System;
using System.IdentityModel.Tokens.Jwt;
using System.Linq;
using System.Security.Claims;
using System.Text;
using TestProject.OpenSDK.Drivers.Web;
using Xunit;
using Xunit.Sdk;

namespace MyProject.Tests.Ui
{
    public class UnitTest1: IDisposable
    {
        private const string DevToken = "*****REDACTED*******";

        private ChromeDriver driver;

        public UnitTest1()
        {
            var options = new OpenQA.Selenium.Chrome.ChromeOptions();
            // Browse via the browsermob-proxy instance (one of the containers in the integration test group.)
            options.AddArguments($"--proxy-server=localhost:8081");
            options.AddArguments("--headless");

            this.driver = new ChromeDriver(token: DevToken, chromeOptions: options, projectName: "MyProject.Tests.Ui", jobName: "Proof-of-concept", disableReports: false);
        }

        public void Dispose()
        {
            this.driver.Close();
            this.driver.Dispose();
        }

        [Fact]
        public void Test1()
        {
            this.driver.Navigate().GoToUrl($"http://my-project/some-path");

            driver.FindElementByClassName("some-specific-button").Click();

            Assert.True(driver.FindElements(By.ClassName("expected-confirmation-message")).Any());
        }
    }
}

MyProject.csproj

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netcoreapp2.2</TargetFramework>

    <IsPackable>false</IsPackable>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.IdentityModel.Tokens" Version="6.8.0" />
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
    <PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.8.0" />
    <PackageReference Include="TestProject.OpenSDK" Version="0.65.0" />
    <PackageReference Include="TestProject.OpenSDK.SpecFlowPlugin" Version="0.65.0" />
    <PackageReference Include="xunit" Version="2.4.0" />
    <PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
  </ItemGroup>

</Project>

The old SDK code (that did work)

BasicTest1.cs

using Microsoft.IdentityModel.Tokens;
using OpenQA.Selenium;
using System;
using System.Collections.Generic;
using System.IdentityModel.Tokens.Jwt;
using System.Linq;
using System.Security.Claims;
using System.Text;
using TestProject.Common.Attributes;
using TestProject.SDK;
using TestProject.SDK.Tests;
using TestProject.SDK.Tests.Helpers;

namespace MyProject.Tests.Ui
{
    [Test(Name = "Basic Test 1")]
    class BasicTest1 : IWebTest
    {
        public ExecutionResult Execute(WebTestHelper helper)
        {
            // Get driver initialized by TestProject Agent
            // No need to specify browser type, it can be done later via UI
            var driver = helper.Driver;

            driver.Navigate().GoToUrl($"http://my-project/some-path");

            driver.FindElementByClassName("some-specific-button").Click();

            if (driver.FindElements(By.ClassName("expected-confirmation-message")).Any())
                return ExecutionResult.Passed;

            return ExecutionResult.Failed;
        }
    }
}

UnitTest1.cs

using OpenQA.Selenium.Chrome;
using System;
using TestProject.Common.Enums;
using TestProject.SDK;
using Xunit;
using Xunit.Sdk;

namespace MyProject.Tests.Ui
{
    public class UnitTest1: IDisposable
    {
        private Runner runner;

        public UnitTest1()
        {
            var options = new ChromeOptions();
            // Browse via the browsermob-proxy instance (one of the containers in the integration test group.)
            options.AddArguments($"--proxy-server=localhost:8081");
            options.AddArguments("--headless");

            this.runner = new RunnerBuilder("******REDACTED*******")
                .AsWeb(AutomatedBrowserType.Chrome)
                .WithOptions(options)
                .Build();
        }

        public void Dispose()
        {
            this.runner.Dispose();
        }

        [Fact]
        public void Test1()
        {
            var result = this.runner.Run(new BasicTest1());
            if (result.ResultType == ExecutionResultType.Failed)
            {
                if (result.FailureType == ExecutionFailureType.InnerException)
                {
                    throw result.Exception;
                }
                else
                {
                    throw new XunitException(result.Message);
                }
            }
        }
    }
}

MyProject.csproj

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netcoreapp2.2</TargetFramework>

    <IsPackable>false</IsPackable>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.IdentityModel.Tokens" Version="6.8.0" />
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
    <PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.8.0" />
    <PackageReference Include="TestProject.SDK" Version="0.65.0" />
    <PackageReference Include="xunit" Version="2.4.0" />
    <PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
  </ItemGroup>

</Project>

Hello again @zblocker
Just to update, the issue seems related to xUnit fixtures.

here is the issue I opened

Can you tell me how to embed in the project. Step by step?
I can’t figure out. I’m having the exact same issue

at TestProject.OpenSDK.Internal.CallStackAnalysis.NUnitAnalyzer.<>c.b__4_0(Attribute a)\r\n at System.Linq.Enumerable.Any[TSource](IEnumerable1 source, Func2 predicate)\r\n at TestProject.OpenSDK.Internal.CallStackAnalysis.NUnitAnalyzer.IsTestClass(MethodBase method)\r\n at TestProject.OpenSDK.Internal.CallStackAnalysis.StackTraceHelper.<>c__DisplayClass10_0.b__2(IMethodAnalyzer a)\r\n at System.Linq.Enumerable.Any[TSource](IEnumerable1 source, Func2 predicate)\r\n at TestProject.OpenSDK.Internal.CallStackAnalysis.StackTraceHelper.b__10_1(MethodBase m)\r\n at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable1 source, Func2 predicate)\r\n at TestProject.OpenSDK.Internal.CallStackAnalysis.StackTraceHelper.TryDetectTestMethod()\r\n at TestProject.OpenSDK.Internal.CallStackAnalysis.StackTraceHelper.GetInferredTestName()\r\n at TestProject.OpenSDK.Internal.Helpers.CommandExecutors.ReportingCommandExecutor.ReportTest(Boolean force)\r\n at TestProject.OpenSDK.Internal.Helpers.CommandExecutors.ReportingCommandExecutor.ReportCommand(Command command, Response response)\r\n at TestProject.OpenSDK.Internal.Helpers.CommandExecutors.CustomHttpCommandExecutor.Execute(Command commandToExecute, Boolean skipReporting)\r\n at TestProject.OpenSDK.Internal.Helpers.CommandExecutors.CustomHttpCommandExecutor.Execute(Command commandToExecute)\r\n at TestProject.OpenSDK.Drivers.BaseDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)\r\n at OpenQA.Selenium.Remote.RemoteWebDriver.set_Url(String value)\r\n at OpenQA.Selenium.Remote.RemoteNavigator.GoToUrl(String url)\r\n at

The discussion continues in the GitHub issue that I created.

Can you tell me what is the workaround you did? My driver still crashes.
My framework is in dot net and after installing open SDK, chromedriver crashes.

I haven’t solved it yet either. Check out the GitHub issue. I plan on continuing the conversation there.

While we work on a solution to this issue, there is a way to work around this.

If you don’t create your driver inside a setup or test method instead of inside the test class constructor, you won’t suffer from the error messages displayed in this issue.