【问题标题】:Cross-Browser-Testing in xUnit with Selenium使用 Selenium 在 xUnit 中进行跨浏览器测试
【发布时间】:2019-05-02 14:59:17
【问题描述】:

我想使用 Selenium 和 xUnit 在不同的浏览器上运行我的单元测试。在整个研究过程中,我找不到合适的解决方案。我发现了一些带有 nUnit 的变体,但它们不符合我的需要。

解决方案应该在三种不同的浏览器(IE、Chrome、Firefox)中执行所有测试。浏览器的数量也应该是可定制的。

有没有合适的解决办法?

【问题讨论】:

标签: selenium testing selenium-webdriver cross-browser xunit


【解决方案1】:

目前还没有完美的方法来做到这一点,但你应该试试 Watin.core 包。 这个包将支持 IE 和 firefox 浏览器,如果你想在 chrome 浏览器中执行测试,那么使用 Watin.core 包就很不走运了。

【讨论】:

    【解决方案2】:

    我找到了一个解决方案,它实际上不会同时在多个浏览器中执行测试,但是当您手动执行项目并动态获取驱动程序类型时它可以工作:

    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;
                }
    

    我使用 PowerShell 脚本运行 .dll 并通过该脚本将驱动程序类型写入 appsettings.json 文件。示例:

    $file = Get-Content "appsettings.json" -raw | ConvertFrom-Json
    $file.DriverType = "chrome"
    

    【讨论】:

      猜你喜欢
      • 2020-02-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-03
      • 1970-01-01
      • 1970-01-01
      • 2020-01-14
      • 1970-01-01
      相关资源
      最近更新 更多