Skip to content

Commit

Permalink
[dotnet] fix test failures by ensuring new driver is created when nec…
Browse files Browse the repository at this point in the history
…essary
  • Loading branch information
titusfortner committed Jul 25, 2023
1 parent a07d1fd commit 91ef191
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
15 changes: 12 additions & 3 deletions dotnet/test/common/DriverTestFixture.cs
@@ -1,7 +1,7 @@
using NUnit.Framework;
using OpenQA.Selenium.Environment;
using System;
using OpenQA.Selenium.Remote;
using static NUnit.Framework.Interfaces.ResultState;

namespace OpenQA.Selenium
{
Expand All @@ -27,7 +27,7 @@ public abstract class DriverTestFixture
public string javascriptPage = EnvironmentManager.Instance.UrlBuilder.WhereIs("javascriptPage.html");

public string loginPage = EnvironmentManager.Instance.UrlBuilder.WhereIs("login.html");

public string clickEventPage = EnvironmentManager.Instance.UrlBuilder.WhereIs("clickEventPage.html");

public string resultPage = EnvironmentManager.Instance.UrlBuilder.WhereIs("resultPage.html");
Expand Down Expand Up @@ -113,7 +113,7 @@ public bool IsNativeEventsEnabled
[OneTimeSetUp]
public void SetUp()
{
driver = EnvironmentManager.Instance.GetCurrentDriver();
driver = EnvironmentManager.Instance.CreateFreshDriver();
}

[OneTimeTearDown]
Expand All @@ -122,6 +122,15 @@ public void TearDown()
// EnvironmentManager.Instance.CloseCurrentDriver();
}

[TearDown]
public void ResetOnError()
{
if (TestContext.CurrentContext.Result.Outcome == Error)
{
driver = EnvironmentManager.Instance.CreateFreshDriver();
}
}

/*
* Exists because a given test might require a fresh driver
*/
Expand Down
5 changes: 1 addition & 4 deletions dotnet/test/common/Environment/EnvironmentManager.cs
Expand Up @@ -138,10 +138,7 @@ private EnvironmentManager()
{
webServer.Stop();
}
if (driver != null)
{
driver.Quit();
}
CloseCurrentDriver();
}

public event EventHandler<DriverStartingEventArgs> DriverStarting;
Expand Down

0 comments on commit 91ef191

Please sign in to comment.