How do I test multiple browsers with selenium and a single NUnit suite and keep it DRY?

前端 未结 5 1316
眼角桃花
眼角桃花 2021-02-14 17:51

I\'m looking for a way to reuse one NUnit test suite without duplicating the entire suite for each browser. It seems like I would need a new fixture for each browser. Can I send

5条回答
  •  暖寄归人
    2021-02-14 18:10

    [SetUp]
        public void CreateDriver()
        {
    
    
            //driver = new TWebDriver();
            if (typeof(TWebDriver).Name == "ChromeDriver")
            {
                ChromeOptions options = new ChromeOptions();
                options.AddArguments("--incognito");
                driver = new ChromeDriver(options);
            }
            else if (typeof(TWebDriver).Name == "FirefoxDriver")
            {
                FirefoxOptions options = new FirefoxOptions();
                options.UseLegacyImplementation = false;
                options.SetPreference("browser.private.browsing.autostart", true);
                options.AddArgument("-private");
                driver = new FirefoxDriver(options);
            }
            else if (typeof(TWebDriver).Name == "InternetExplorerDriver")
            {
                InternetExplorerOptions options = new InternetExplorerOptions();
                options.BrowserCommandLineArguments = "-private";
                options.EnsureCleanSession = true;
                options.IgnoreZoomLevel = true;
                options.EnablePersistentHover = true;
    
                driver = new InternetExplorerDriver(options);
    
            } else
                driver = new TWebDriver();
        }
    

提交回复
热议问题