1

In nUnit we can get current test name like TestContext.CurrentContext.Test.Name that I am passing in Sauce Labs with ChromeOptions to show method name in saucelabs like below

ChromeOptions options = new ChromeOptions();
options.AddAdditionalCapability("username", sauceUserName, true);
options.AddAdditionalCapability("accessKey", sauceAccessKey, true);
options.AddAdditionalCapability("name", TestContext.CurrentContext.Test.Name, true);

_driver = new RemoteWebDriver(new Uri("https://ondemand.saucelabs.com/wd/hub"), options.ToCapabilities(), TimeSpan.FromSeconds(600));

but TestContext is not present in xUnit. Please help how I can pass the context or method name?

Ravi
  • 408
  • 7
  • 22
  • Would this approach solve your issue? [https://stackoverflow.com/questions/16484839/get-name-of-running-test-in-xunit](https://stackoverflow.com/questions/16484839/get-name-of-running-test-in-xunit) – Fabio Feb 18 '20 at 09:25
  • I used this approach it giving name but the problem is above code is in constructor to share common setup like public MyPageTests() { ChromeOptions options = new ChromeOptions(); options.AddAdditionalCapability("username", TestData.config["SauceLabs:Username"], true); options.AddAdditionalCapability("accessKey", TestData.config["SauceLabs:AccessKey"], true); _driver = new RemoteWebDriver(new Uri(TestData.config["SauceLabs:RemoteAddress"]), options.ToCapabilities(), TimeSpan.FromSeconds(600)); } Any idea how I can use this approach in my case? – Ravi Feb 18 '20 at 09:55
  • Maybe this helps: https://github.com/SimonCropp/XunitContext#current-test – Fabian Feb 18 '20 at 09:59
  • @Fabian It works. Please put same in answer section so that I can mark it. Also need to add 3 nuget package 1. XunitContext 2. xunit.extensibility.core 3. xunit.extensibility.execution – Ravi Feb 18 '20 at 11:00

1 Answers1

1

As stated in the comments. Now as an answer:

There seems to be already a solution for this. See here.

Fabian
  • 1,100
  • 11
  • 14