假设我有一个启动 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/