测试自动化 - WinAppDriver 无法与 telerik RadComboBox 交互超过 1 秒

问题描述 投票:0回答:1

我正在使用 WinAppDriver 和 Appium 来自动化桌面应用程序测试。 当自动化测试机器人单击 wpf telerik radcombobox 时,我遇到问题。 下拉列表在不到 1 秒的时间内显示良好,然后它自行关闭,阻止机器人选择只能通过运行以下代码片段的下拉列表访问的项目:

[C#]

Using OpenQA.Selenium.Appium.windows;
Using OpenQA.Selenium.Interactions;

//Code to launch the driver

//Get the telerik RadComboBox
WindowsElement myRadComboBox = myWindowsDriver.FindElementByAccessibilityId("ComboBox_Automation_Id");

Actions actionsToInteractWithComboBox = new Actions(myWindowsDriver);

actionsToInteractWithComboBox.MoveToElement.Click(myRadComboBox);
actionsToInteractWithComboBox.Perform();

假设下拉列表包含 3 项“Al”、“Ar”和“Em”,第一项是文本框中默认显示的 Al。 当尝试发送键以显示“Ar”时,会发生相同的行为。我首先从文本框中手动清除“Al”,然后机器人执行单击并将“Ar”发送到组合,但显示“Al”,意味着“A”写得很好,但组合框从未收到“r”:

actionsToInteractWithComboBox.Click(myRadComboBox).SendKeys("Ar");
actionsToInteractWithComboBox.Perform();

我再次手动清除“Al”来确认此行为,这次机器人发送“E”,我能够显示“Em”:

actionsToInteractWithComboBox.MoveToElement.Click(myRadComboBox).SendKeys("E");
actionsToInteractWithComboBox.Perform();

无论组合框模式是“可编辑”还是“不可编辑”,都会发生这种情况。在可编辑的情况下,单击组合框内部时,时间不足以显示下拉列表,而在不可编辑的情况下,机器人只有时间在立即关闭之前显示它。

RadComboBox modes

似乎不久之后,组合框就会进入某种状态或触发一个事件,阻止它从 winAppDriver 接收进一步的命令。就像执行了双击一样。我想问题出在组合框本身而不是 WinAppDriver 上? 但是我不知道它是来自它的编码方式还是来自 telerik 组件本身。这是组合框的代码:

         <Controls:RadComboBox x:Name="ComboTitle" DisplayMode="{Binding DisplayModeIdentiteBloc}" Height="20" Grid.Row="1" Grid.Column="1" SelectedValue="{Binding Path=ParentEntity.Individuals, ValidatesOnDataErrors=true}" ItemsSource="{Binding TitleLookup}" DisplayMemberPath="Value" SelectedValuePath="Key" SelectionChanged="ComboTitle_SelectionChanged" IsAdornable="True"/>

注意:将密钥发送到 telerik 文本框不会显示此行为。 在单击组合框之前,我还尝试按位置移动光标,结果相同:

actionsToInteractWithComboBox.MoveToElement(myRadComboBox, myRadComboBox.Location.X, myRadComboBox.Location.Y);

感谢您的帮助

combobox automated-tests telerik winappdriver
1个回答
0
投票

这不是问题,我使用操作的方式错误。这是正确的 C# 代码:

Actions actionsComboBox = new Actions(App_WinAppDriver);

WindowsElement comboBox = App_WinAppDriver.FindElementByAccessibilityId("comboBoxAutomationId");

/*MoveToElement in the example below is specific to a Telerik radComboBox
 *which must be given the offset of the button to click on it and display
 *the drop-down list. When the MoveToElement instruction is given an offset,
/*the reference is the upper left corner of the user control. Please see the link below.

int halfPixelWidthOfButton = 6;

actionsComboBox.MoveToElement(comboBox, comboBox.Size.Width - halfPixelWidthOfButton, comboBox.Size.Height / 2);
actionsComboBox.ClickAndHold();
actionsComboBox.Perform();

MoveToElement 的 Appium 文档

此代码适用于 Telerik RadComboBox 和 WPF ComboBox,通过单击并按住命令显示下拉列表并保持打开状态,而不是像我最初那样简单单击。

© www.soinside.com 2019 - 2024. All rights reserved.