【发布时间】:2020-01-06 05:25:27
【问题描述】:
我们正在尝试使用 Selenium 来测试我们的 MVC 应用程序。在 VS2017 的 localhost 上,它运行正确,测试打开 IE,运行测试然后关闭 IE。
在 TFS 构建服务器上,测试以某种方式在后台启动 IE(在任务管理器中我看到两个 iexplorer.exe 进程),但 IE 的窗口不可见。测试找到元素,但他们无法在文本框中写入文本,总是出现“元素无法通过键盘交互,因为它不可聚焦”之类的错误
Localy 我运行 Win10 和 IE11,TFS 构建服务器运行 Windows Server 2012 R2 和 IE11。
//initialize driver in test constructor
InternetExplorerOptions options = new InternetExplorerOptions();
options.IntroduceInstabilityByIgnoringProtectedModeSettings = true;
options.RequireWindowFocus = true;
driver = new InternetExplorerDriver(options);
driver.Manage().Window.Maximize();
//test itself
driver.Navigate().GoToUrl(appURL);
var x = driver.FindElement(By.Id("FiltrADuvodDotazu_DuvodDotazu"));
x.SendKeys("Automatizovaný test"); //here I get error
有没有办法以可见的方式运行 IE,以便测试可以与之交互?
【问题讨论】:
-
您需要在 IE 不支持的无头模式下运行浏览器 - stackoverflow.com/questions/46645307/…
-
但是在本地测试和在 TFS 构建服务器上测试有什么不同呢?本地一切运行正确
-
本地你有一个 UI,在 TFS 中没有 UI 可以交互。
-
构建服务器也有一个UI,那为什么在本地它运行UI而在构建服务器上UI没有启动?这就是我不明白的
-
除非构建代理帐户已登录,否则没有可用的 UI/桌面。因此,您的选择是通过以构建代理帐户登录或使用无头来创建 UI。有些人可能会考虑让服务器环境登录存在安全风险。
标签: c# selenium internet-explorer tfs