MauriceDev
MauriceDev

Reputation: 31

Cross-Browser-Testing in xUnit with Selenium

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?

Upvotes: 0

Views: 1537

Answers (2)

Krishna chauhan
Krishna chauhan

Reputation: 11

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.

Upvotes: 1

MauriceDev
MauriceDev

Reputation: 31

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"

Upvotes: 2

Related Questions