Skip to content

Can not initialize Seleno - System.TypeInitializationException #231

@oesolberg

Description

@oesolberg

I am new to Seleno so I might have misunderstood something,

I am trying to get Seleno to work. Following the course Automated ASP.NET MVC Testing: End to End on Pluralsight by Jason Roberts.

But for some reason I cant get Seleno to work.
I create a solution with the ASP.Net MVC (.net 4.6). Works like it should.
WebApplication (solution)
\WebApplication
\Tests

After doing the Install-packages I have the following packages-config
I add a test project with the following packages:
package id="Castle.Core" version="3.3.3" targetFramework="net46"
package id="Microsoft.AspNet.Mvc" version="5.2.3" targetFramework="net46"
package id="Microsoft.AspNet.Razor" version="3.2.3" targetFramework="net46"
package id="Microsoft.AspNet.WebPages" version="3.2.3" targetFramework="net46"
package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net46"
package id="NUnit" version="3.0.1" targetFramework="net46"
package id="Selenium.Support" version="2.45.0" targetFramework="net46"
package id="Selenium.WebDriver" version="2.49.0" targetFramework="net46"
package id="TestStack.Seleno" version="0.9.11" targetFramework="net46"

I tried to make a little test but I always get the following error on initialising the BrowserHost.

System.TypeInitializationException : The type initializer for 'Tests.BrowserHost' threw an exception.
----> System.NullReferenceException : Object reference not set to an instance of an object.

at Tests.DudeTest.Something() in c:\dev\WebApplication\Tests\DudeTest.cs:line 12
--NullReferenceException
at TestStack.Seleno.Configuration.WebServers.ProjectLocation.GetSolutionFolderPath() in c:\ConsoleBuildAgent\work\6625a30e8ee728ba\src\TestStack.Seleno\Configuration\WebServers\ProjectLocation.cs:line 42
at TestStack.Seleno.Configuration.WebServers.ProjectLocation.FromFolder(String webProjectFolderName) in c:\ConsoleBuildAgent\work\6625a30e8ee728ba\src\TestStack.Seleno\Configuration\WebServers\ProjectLocation.cs:line 33
at TestStack.Seleno.Configuration.SelenoHost.Run(String webProjectFolder, Int32 portNumber, Action`1 configure) in c:\ConsoleBuildAgent\work\6625a30e8ee728ba\src\TestStack.Seleno\Configuration\SelenoHost.cs:line 51
at Tests.BrowserHost..cctor() in c:\dev\WebApplication\Tests\BrowserHost.cs:line 17

I found that this has been a problem before, but then the solution was to have the .sln file correctly located. As it is now I think I have It right.

Is there anything I am missing or am I using the wrong .Net version?

BrowserHost.cs

using TestStack.Seleno.Configuration;
namespace Tests
{
public static class BrowserHost
{
public static readonly SelenoHost Instance=new SelenoHost();
public static readonly string RootUrl;
static BrowserHost()
{
Instance.Run("WebApplication", 12345);
RootUrl = Instance.Application.Browser.Url;
}
}
}

TestClass.cs

using NUnit.Framework;
using OpenQA.Selenium;

namespace Tests
{
[TestFixture]
public class DudeTest
{
[Test]
public void Something()
{
BrowserHost.Instance.Application.Browser.Navigate().GoToUrl(BrowserHost.RootUrl+@"Lub");

        var emailBox = BrowserHost.Instance.Application.Browser.FindElement(By.Id("email"));
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions