c# - 在 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();
}
解决方案
推荐阅读
- user-interface - matplotlib中执行start_event_loop后如何继续主代码
- ruby-on-rails - Rails 在生产环境中运行服务器时重新加载 ActionView::Template
- java - 谷歌地图没有加载
- gradle - Pact Gradle 状态 url 响应
- python - Jenkins 作业在构建期间无法将整数参数传递给 python 脚本
- mysql - 在mysql中显示两列的计数
- php - 服务器中的PHP版本问题?
- php - curl,未收到从 CLI 调用的 php 响应
- r - R Prophet 在循环中使 Rstudio 崩溃
- excel - 表单中的表单 - VBA 右键单击复制/粘贴多页