0

PRoj file

Sdk="Microsoft.NET.Sdk" 
"DotNetSeleniumExtras.PageObjects.Core" V="4.3.0" "itext7" V="7.2.5" "Microsoft.Extensions.Configuration" V="7.0.0" "Microsoft.Extensions.Configuration.Json" V="7.0.0" "Microsoft.NET.Test.Sdk" V="17.5.0" "coverlet.collector" V="3.1.2" "MSTest.TestAdapter" V="3.0.2" "MSTest.TestFramework" V="3.0.2" "Selenium.Support" V="4.9.0" "Selenium.WebDriver" V="4.9.0" "Selenium.WebDriver.ChromeDriver" V="112.0.5615.4900" "SeleniumExtras.WaitHelpers" V="1.0.2"
public static void ClassInit(TestContext context)
{
   var _configuration = new ConfigurationBuilder()
       .SetBasePath(Directory.GetCurrentDirectory())
       .AddJsonFile(@"TestData.json", optional: false, reloadOnChange: true)
       .Build();

   if (_configuration != null)
   {
      pageLoadTimeout =    Convert.ToInt16(_configuration["TestDataCollection:PageLoadTimeout"]);
      ePortalUsername = _configuration["TestDataCollection: ePortalUsername"];
      ePortalPassword = _configuration["TestDataCollection: ePortalPassword"];
    }

    if (TestContext != null)
    {
       browser = browser = Convert.ToString(TestContext.Properties["Browser"]);
       url = Convert.ToString(TestContext.Properties["OLSPortalUrl"]);
    }
}

Here's json file

{
  "__comments": "Test data is collection of TestDataInstance. Each instance contains testing   accounts and data",
  "TestDataCollection": [
   {
      "ePortalUserName": "some username",
      "ePortalPassword": "some password",
      "OLSPortalUrl": "http://www-test.someurl.com/",
      "PageLoadTimeout": "40"
   }
  ]
}

Here's my runsettings file

<?xml version="1.0" encoding="utf-8" ?>
<RunSettings>
     <TestRunParameters>
        <Parameter name="Browser" value="Chrome" />
        <Parameter name="Environment" value="TEST" />
        <Parameter name="OLSPortalUrl" value="http://www-test.paccarfinancial.com/" />
     </TestRunParameters>
</RunSettings>

Test output:

Building Test Projects
========== Starting test run ==========
========== Test run finished: 0 Tests (0 Passed, 0 Failed, 0 Skipped) run in < 1 ms ==========

Here is my Testclass and TestMethod

[TestClass]
public class Tests : BaseTestClass
{
    [TestCategory("Test"), TestMethod]
    public void PAC041_01_Navigate()
    {            
        if (browser != null && url != null)
        {
            driver = Utility.InitBrowser(browser, pageLoadTimeout);
            Utility.NavigateToUrl(url);
            Assert.AreEqual("Home Page", driver.Title);
            driver.Quit();
        }
    }
}

I tried removing json file and keeping only runsettings file still my tests are not picked up. Since i am on .NET core AppSettings is not supports so I have to use json for the testdata. I am not sure what wrong i am doing here. Can some one please help me with this?

Madhavi
  • 1
  • 2
  • In VS, open the **Output** window for Test discovery (not "Build") and show us what it says. – Dai May 04 '23 at 16:30
  • @Dai , Building Test Projects ========== Starting test run ========== ========== Test run finished: 0 Tests (0 Passed, 0 Failed, 0 Skipped) run in < 1 ms ========== This is what it says. I don't have Test discovery but this is the output for Tests – – Madhavi May 04 '23 at 20:10
  • Show us your `csproj` file. I think you might have incorrect or insufficient NuGet `` entries. – Dai May 04 '23 at 21:09
  • _"here it is"_ - where? you haven't edited your question to add it – Dai May 04 '23 at 21:40
  • since comment window accept less chars, I pasted the files and versions from proj file. I was pulled into a meeting before . So i was not able to edit it. – Madhavi May 04 '23 at 21:47
  • 1
    Don't use comments for posting code: edit your original post instead. – Dai May 04 '23 at 21:54
  • Added to the post. – Madhavi May 05 '23 at 15:06
  • Don't you also need a `[ClassInitialize]` over your ClassInit method? (but still, the `[TestClass]` should already be found) – Hans Kesting May 05 '23 at 15:15
  • Yes, they are there. forgot to paste it here – Madhavi May 05 '23 at 15:46
  • I figured out why it was not working. In ClassInit, i was not using the TestContext variable declared in the method, was rather using TextContext variable defined globally. Removed the Textcontext defined globally and using the variable declared in the ClassInit method. Thanks Dar for atleast looking into it. – Madhavi May 08 '23 at 18:34

0 Answers0