首页 > 解决方案 > 尝试从“Systems.Windows.Forms”中使用,以便我可以在我的 C# 测试应用程序中从剪贴板中读取

问题描述

在Visual Studio 2019社区版中为 C# 测试程序设置有点困难的时间Windows.System.Forms是为了访问该类而使用的参考,Clipboard以便我可以从 Windows 10 桌面剪贴板设置和获取文本信息。

当我去添加参考时,我找不到Windows.System.Forms,而是看到Windows_System_Forms。我试图将其作为参考,我得到:

警告 MSB3290 无法为类型库“{215d64d2-031c-33c7-96e3-61794cd1ee61}”创建包装程序集。类型库“System_Windows_Forms”是从 CLR 程序集导出的,不能作为 CLR 程序集重新导入。

我怎样才能包含System.Windows.Forms,以便下面的代码可以工作?

[Then(@"validation text is ""(.*)""")]
public void ThenTestIs(string res)
{
    // Setup waiting for test selectors to render
    driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5);
    WebDriverWait wait = new WebDriverWait(driver, new TimeSpan(0, 0, 5));

    string xpath = (string)Properties.MflixXpaths.Default["mflix_result"];
    xpath = xpath.Replace("TEST", testName);

    driver.FindElement(By.XPath(xpath)).Click();
    string val = Clipboard.GetText();
    Assert.AreEqual(val, res);
}

标签: c#unit-testingvisual-studio-2019

解决方案


推荐阅读