WinAppDriver在一台机器上找到元素,但在其他机器上找不到

时间:2019-11-18 21:10:58

标签: c# selenium winappdriver

我有一个自动化测试环境,该环境由一台开发机和两个以自动化方式运行测试的盒子组成。所有三台计算机都运行Windows10。所有三台计算机都使用与WinAppDriver相同的版本,所有三台计算机都使用最新版本的Google Chrome。这三个都在计算机上已登录的本地管理员帐户下运行。

我最初在IE中构建了所有测试,但由于浏览器不稳定,一直试图将其转换为Chrome。

在这种情况下,我使用WinAppDriver来检测浏览器何时向用户显示下载对话框。在所有机器上的IE中似乎都可以正常工作。它甚至可以在开发机上的Chrome中正常运行,但不能在测试机上的Chrome中运行。

到目前为止,除了MSBuild是由测试计算机上的TFS和开发人员计算机上的Visual Studio启动的事实之外,到目前为止,我无法弄清测试计算机上可能存在的差异。

这是正在运行的开发机返回的结果的图像。 Working machine

以下是其中一台测试机的结果图像。 enter image description here

第二张图片: enter image description here

如您所见,除了测试计算机的全面失败之外,唯一的不同似乎是对初始浏览器挂钩的响应。工作的人不返回sessionId,而失败的人则返回sessionId。对我来说,这表明产品版本有所不同,但是我确认WinAppDriver的两个版本相同。

我曾尝试过多个版本的XPath查找,以防万一这是问题所在,但是它们都在开发机上工作,而没有一个在测试机上工作。

有人知道为什么我的测试箱无法专门在Chrome中执行此查找吗?

编辑:已要求输入代码,但屏幕截图有点多余,但在这里。

this.BaseBrowser.NavigateToUrl(new System.Uri(string.Format("{0}&Export=Excel", MainDocument.PageUrl)));

var wait = new OpenQA.Selenium.Support.UI.WebDriverWait(BaseBrowser.Window, new TimeSpan(0, 0, 0, 0, 5000)); // wait for 5 seconds
IWebElement export_cancel = 
        (Settings.TestBrowser == Brow.IE) ? wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementExists(By.XPath("//ToolBar/Button[@Name=\"Cancel\"]"))) :
        (Settings.TestBrowser == Brow.Chrome) ? wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementExists(By.XPath("//Pane/Pane/Pane/Group/Button[@Name=\"Close\"]"))) :
        null;   // exception thrown on this if statement if browser is Chrome;
Mouse.Click(export_cancel);

该异常的文本也显示在屏幕截图中:

  

WebDriverException->在页面上找不到元素   使用给定的搜索参数。 StackTrace:位于   OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(响应   errorResponse)   OpenQA.Selenium.Remote.RemoteWebDriver.Execute(字符串   driverCommandToExecute,Dictionary'2 parameters)at   OpenQA.Selenium.Remote.RemoteWebDriver.FindElement(字符串机制,   字符串值)   OpenQA.Selenium.Remote.RemoteWebDriver.FindElementByXPath(String   xpath)在OpenQA.Selenium.By。<> c__DisplayClass19_0.b__0(ISearchContext   在OpenQA.Selenium.By.FindElement(ISearchContext上下文)处   OpenQA.Selenium.Remote.RemoteWebDriver.FindElement(by by)在   SeleniumExtras.WaitHelpers.ExpectedConditions。<> c__DisplayClass6_0.b__0(IWebDriver   司机)   OpenQA.Selenium.Support.UI.DefaultWait'1.Until [TResult](Func'2   条件)

编辑2:将WinAppDriver挂接到浏览器进程的BaseBrowser.Window方法摘录:

System.Diagnostics.Process[] localByName = System.Diagnostics.Process.GetProcessesByName(this.BaseProcessName);
foreach (System.Diagnostics.Process item in localByName)
{
    if (item.MainWindowTitle == string.Format(BaseProcessTitleFormat, this.Title))
    {
        DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
        desiredCapabilities.SetCapability("appTopLevelWindow", item.MainWindowHandle.ToString("x"));
        RemoteWebDriver session = new RemoteWebDriver(new Uri(windowsAppDriverUrl), desiredCapabilities, new TimeSpan(0, 1, 30));
        _Window = session;
        break;
    }
}
return _Window;

0 个答案:

没有答案