0

I'd like to run my unit tests on different browsers with Selenium and xUnit. I couldn't find a proper solution throughout my research. I have found some variants with nUnit but they don't fit my needs.

The soulution should execute all tests in three different browsers (IE, Chrome, Firefox). Also the amount of browsers should be customizable.

Is there any proper solution?

2
  • Try to take a look at: stackoverflow.com/questions/28480545/… Commented Nov 30, 2018 at 13:17
  • @Kiksen This solution is with nUnit but I'm trying to find one with xUnit. Commented Nov 30, 2018 at 13:31

2 Answers 2

2

I've found a solution which doesn't actually execute the tests in multiple browsers at the same time, but it works when you execute the project manually and get the Driver Type dynamically:

switch (Configuration["DriverType"])
            {
                case "firefox":
                    var firefoxService = FirefoxDriverService.CreateDefaultService(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "geckodriver.exe");
                    firefoxService.FirefoxBinaryPath = Configuration["FirefoxPath"];

                    FirefoxOptions firefoxOptions = new FirefoxOptions();

                    firefoxOptions.SetPreference("browser.download.dir", Configuration["DownloadPath"]);
                    firefoxOptions.SetPreference("browser.download.useDownloadDir", true);
                    firefoxOptions.SetPreference("browser.helperApps.neverAsk.saveToDisk", "application/octet-stream");

                    Driver = new FirefoxDriver(firefoxService, firefoxOptions);

                    break;

                case "chrome":
                    var chromeOptions = new ChromeOptions();
                    chromeOptions.AddUserProfilePreference("safebrowsing.enabled", true);

                    Driver = new ChromeDriver(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), chromeOptions);

                    break;
            }

I use a PowerShell script to run the .dll and write the Driver Type to the appsettings.json File via that script. Example:

$file = Get-Content "appsettings.json" -raw | ConvertFrom-Json
$file.DriverType = "chrome"
Sign up to request clarification or add additional context in comments.

Comments

1

Right Now there is not perfect method to do this but you should try Watin.core Package. This package will support IE and firefox browser and if you want to execute the test in chrome browser then you are out of luck using Watin.core package.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.