【发布时间】:2021-07-08 21:17:18
【问题描述】:
我是升 C 的绝对初学者。
我的代码没有从app.config. 读取值我无法弄清楚缺少什么。
该代码会打开 Chrome,但不会转到 Google 网站。
如果有人能提供帮助,非常感谢。
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using System.Configuration;
using System.IO;
using System.Reflection;
namespace TestProject1
{
[TestClass]
public class UnitTest1
{
public static IWebDriver driver { get; set; }
[TestMethod]
public void TestMethod1()
{
var chromeOptions = new ChromeOptions();
chromeOptions.AddArgument("-no-sandbox");
driver = new ChromeDriver(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), chromeOptions);
driver.Navigate().GoToUrl(ConfigurationManager.AppSettings["URL"]);
}
}
}
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="URL" value="https://www.google.com/" />
</appSettings>
</configuration>
【问题讨论】:
-
The code opens the Chrome but doesn't go to Google什么代码?请更新您的帖子以包含不起作用的代码,而不仅仅是代码图像。 -
请将代码和数据添加为文本 (using code formatting),而不是图像。图片:A)不允许我们复制粘贴代码/错误/数据进行测试; B) 不允许根据代码/错误/数据内容进行搜索;和many more reasons。除了代码格式的文本之外,只有在图像添加了一些重要的东西,而不仅仅是文本代码/错误/数据传达的内容时,才应该使用图像。
-
在配置文件中注意你的上限;它应该是
<appSettings>而不是<AppSettings> -
尝试将
AppSettingsxml节点重命名为appSettings
标签: c# selenium-webdriver automated-tests app-config