首页 > 解决方案 > 在 Selenium C# 中为多个项目使用单个文件中的相同浏览器类型

问题描述

我正在尝试使用Parallel.RunSettings文件从一个地方传递 45 个项目的浏览器类型,并在 Visual Studio 的测试设置下添加此文件。
但是该值没有被读取NullReferenceException

我错过了任何步骤吗?

目前,我们在各自的app.config文件中为每个项目传递浏览器类型,但我想从一个地方进行。

这是我的代码:

Parallel.runsettings

<?xml version="1.0" encoding="utf-8"?>
<RunSettings>
    <RunConfiguration>
        <MaxCpuCount>4</MaxCpuCount>
    </RunConfiguration>
    <TestRunParameters>
        <Parameter name="browsertype" value="Firefox" />
    </TestRunParameters>
</RunSettings>


获取值的代码:

public string GetBrowser
{
    get
    {
        var value =Convert.ToString(testContext.Properties["browsertype"]);
        return value;
    }
}

//Code To Launch the browser:

if (config.GetBrowser == "Firefox")
{
    this.WebDriver = new FirefoxDriver();
}
else if (config.GetBrowser == "Chrome")
{
    var chromeOptions = new ChromeOptions();
    chromeOptions.AddAdditionalCapability("useAutomationExtension", false);
    this.WebDriver = new ChromeDriver(chromeOptions);
}
else if (config.GetBrowser == "IE")
{
    this.WebDriver = new InternetExplorerDriver();
}

标签: c#seleniumbrowsermultiple-projects

解决方案


推荐阅读