No suitable constructor was found using Playwright with NUnit

I have a base class as

public class PlaywrightFixture
    {
        public Task<IPlaywright> Playwright { get; set; } = default;
        public Task<IBrowser> Browser { get; set; } = default;
        
        private readonly PlaywrightFixture _playwrightFixture;
        private static string _readonlypageUrl;
        private readonly IConfiguration _iAppSettingConfiguration;
        private UserCredentials _userCredentials = new UserCredentials(null, null);

        public PlaywrightFixture(PlaywrightFixture playwrightFixture)
        {
            _iAppSettingConfiguration = IAppSettingConfiguration.InitConfiguration();
            _readonlypageUrl = _iAppSettingConfiguration["baseUrl"];
        
            _iAppSettingConfiguration.GetSection("user").Bind(_userCredentials);
        
            _playwrightFixture = playwrightFixture;
            //_playwrightFixture.Playwright = Playwright.CreateAsync();
            _playwrightFixture.Browser = _playwrightFixture.Playwright.Result.Chromium.LaunchAsync(
                new BrowserTypeLaunchOptions
                {
                    Headless = false,
                    SlowMo = 200,
                });
        }
    }

Unit test case

 public class GivenAccount : PlaywrightFixture   
    {
        private readonly PlaywrightFixture _playwrightFixture;
        private static string _readonlypageUrl;
        private readonly IConfiguration _iAppSettingConfiguration;
        private UserCredentials _userCredentials = new UserCredentials(null, null);
        
        public GivenAccount(PlaywrightFixture playwrightFixture) : base(playwrightFixture)
        {
        }
       
        [Test]
        public async Task Then_Login_Page_Should_Load()
        {
            var page = await _playwrightFixture.Browser.Result.NewPageAsync();
            await page.GotoAsync(_readonlypageUrl);
            string title = await page.TitleAsync();
            Assert.AreEqual("6clicks", title);
        }
    }

Exception as

OneTimeSetUp: No suitable constructor was found
  Exception doesn't have a stacktrace



-----

No suitable constructor was found
  Exception doesn't have a stacktrace

1 answer

  • answered 2022-03-23 09:16 Charlie

    You have created a fixture, GivenAccount, which is based on PlaywriteFixture. Its constructor takes a single parameter, which is another PlaywriteFixture.

    However, you are not giving NUnit an argument to use in constructing your fixture. You should do this using [TestFixturesource("name_of_your_source")] on the GivenAccount class.

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum