c# - 在播放编码的 UI 测试时,某些元素花费的时间太长而无法识别

标签 c# visual-studio-2013 automated-tests ui-automation coded-ui-tests

假设我有一个启动 Google.com 并搜索字符串的自动化测试用例。

  • 启动 google.com
  • 搜索“马来西亚航空公司”

我已经确定了搜索字段的所有必要属性,以便播放可以很容易地找到它并运行它。但是,当我运行测试时,最多需要 10-14 秒才能在 Google.com 中找到搜索字段,然后在其中进行搜索。

我的代码是

BrowserWindow browser = BrowserWindow.Launch("www.google.com");
            UITestControl UISearch = new UITestControl(browser);
            UISearch.TechnologyName = "Web";
            UISearch.SearchProperties.Add("ControlType", "Edit");
            UISearch.SearchProperties.Add("Id", "lst-ib");
            Mouse.Click(UISearch);
            Keyboard.SendKeys(UISearch, "Malaysian Airline");

大家也可以试试看。 Google.com 上几乎没有其他东西,但仍然需要很长时间才能找到我已经给出可能且唯一唯一 ID 的元素。

最佳答案

使用 Selenium在 Firefox 上,\n 按下 Enter 需要 10 秒,避免了悬停和单击元素的成本。

[TestClass]
public class UnitTest1
{
    FirefoxDriver firefox;

    // This is the test to be carried out.
    [TestMethod]
    public void TestMethod1()
    {
        firefox = new FirefoxDriver();
        firefox.Navigate().GoToUrl("http://www.google.com/");
        IWebElement element = firefox.FindElement(By.Id("lst-ib"));
        element.SendKeys("Google\n");
    }

    // This closes the driver down after the test has finished.
    [TestCleanup]
    public void TearDown()
    {
        firefox.Quit();
    }
}

关于c# - 在播放编码的 UI 测试时,某些元素花费的时间太长而无法识别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29299423/

相关文章:

c# ReaderWriterLockSlim 在调用 ExitReadLock 的中断线程后损坏

c# - 签署 ILMerge 的 DLL

unit-testing - 应该测试内部实现,还是只测试公共(public)行为?

git - 在 Visual Studio 中使用 git 子模块的工作流程

python - 如何对 python 中的不同实现使用相同的单元测试?

c# - 组件测试 Azure Functions

c# - 交易陷入僵局

C# 类工厂

visual-studio-2013 - 如何禁用 nuget 机器范围的缓存?

c# - 为什么不 mc :Ignorable work for the Password property? 我该怎么办?