How to read test parameter value from TestSetting.runsettings file in Specflow 3+ .NET Core project ? Using Visual studio 2019.

85 views
Skip to first unread message

savita

unread,
Jul 30, 2019, 7:33:06 AM7/30/19
to SpecFlow

Hi Team,

I am unable to read Test parameter value placed in .runsettings file.

TestSettings.runsettings

<?xml version="1.0" encoding="utf-8" ?>
<RunSettings>
    <!-- Parameters used by tests at runtime -->
  <TestRunParameters>
    <Parameter name="seleniumBaseUrl" value="https://novasol" />
   
  </TestRunParameters>
 
</RunSettings>

Code part :

[Given(@"I am on Novasol website(.*)")]
        public void GivenIAmOnNovasolWebsite(string url)
        {
            var driver = _webDriver.Current;
         
            try
            {
                var testContext = ScenarioContext.Current.ScenarioContainer.Resolve<Microsoft.VisualStudio.TestTools.UnitTesting.TestContext>();
             }

It's throwing error :
Cannot create an instance of Microsoft.VisualStudio.TestTools.UnitTesting.TestContext because it is an abstract class.

I followed this answer but its not working for me.

I tried also this..but not successful..


namespace WebShopTestAutomation
{
    [Binding]

      public class CheckTheSearchFunctionalityToFindHolidayHomesSteps
    {

       
        private readonly WebDriver _webDriver;
        private readonly TestContext _testContext;
   
        private static string baseUrl { get; set; }

    
        public CheckTheSearchFunctionalityToFindHolidayHomesSteps(WebDriver webDriver, TestContext testContext)
        {
            _webDriver = webDriver;
            _testContext = testContext;
        }

        [Given(@"I am on Novasol website(.*)")]
        public void GivenIAmOnNovasolWebsite(string url)
        {
            var driver = _webDriver.Current;
      
            try
            {
                //var testContext = ScenarioContext.Current.ScenarioContainer.Resolve<Microsoft.VisualStudio.TestTools.UnitTesting.TestContext>();
                var textContext = _testContext.Properties["seleniumBaseUrl"].ToString();

              }

}

It's throwing error :
Cannot create an instance of Microsoft.VisualStudio.TestTools.UnitTesting.TestContext because it is an abstract class.

Phuoc Ha

unread,
Jul 31, 2019, 12:40:12 AM7/31/19
to SpecFlow
Hello Savita,

Don't create a TextContext in constructor like above.

Try to use it directly.
It's working for me now >>>

public static string seleniumBaseUrl = TestContext.Parameters["textContext "];

Regard,
Erit Ha.

Phuoc Ha

unread,
Jul 31, 2019, 12:45:17 AM7/31/19
to SpecFlow
I mean this

   var seleBaseUrl= TestContext.Properties["seleniumBaseUrl"].ToString();

Regards,
Erit Ha.

On Tuesday, July 30, 2019 at 6:33:06 PM UTC+7, savita wrote:

Andreas Willich

unread,
Jul 31, 2019, 3:14:00 AM7/31/19
to SpecFlow
Hi Savita

Support for TestRunParameter is an open feature request for the SpecFlow+Runner.

Best regards
Andi

--
You received this message because you are subscribed to the Google Groups "SpecFlow" group.
To unsubscribe from this group and stop receiving emails from it, send an email to specflow+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/specflow/0c60c507-11cf-4847-93b6-a53047bbe903%40googlegroups.com.

savita

unread,
Jul 31, 2019, 7:04:37 AM7/31/19
to SpecFlow
Hi Erit,

I tried both ways, but its not working...

Which way you did? As per Andreas comment this feature is still open to develop :(

Really appreciate if you can hep.

TestContexterror.png

testcontexterror2.png

Phuoc Ha

unread,
Aug 1, 2019, 12:57:27 PM8/1/19
to SpecFlow
Hi Savita,

I believed that you are missing download/import Nuget package Nunit framework.
Please check my screenshot below:


I hope you can resolve your issue soon.

Regards,
Erit Ha.
Reply all
Reply to author
Forward
0 new messages