摘要
在我的WPF应用程序中,我需要一个带左侧按钮的TabControl,所以我用我想要的布局定义了一个ControlTemplate,它运行正常.
但是,我的测试人员的自动测试工具无法看到选项卡的任何内容,包括当前选定的选项卡.
问题:如何通过自动化测试工具保持我的TabControl可测试,同时仍然定义ControlTemplate?
细节
我正在使用WPF 3.5开发WPF应用程序
我的测试人员正在使用一个名为QTP的自动测试工具
他说他可以使用UISpy.exe测试任何你能看到的内容
示例WPF应用程序(Xaml):
<Window x:Class="TabControlTest.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Tab Control Test"
Height="300"
Width="300">
<Window.Resources>
<ControlTemplate x:Key="ButtonsOnLeftTabLayout"
TargetType="{x:Type TabControl}">
<DockPanel>
<StackPanel DockPanel.Dock="Left"
IsItemsHost="True" />
<ContentPresenter Content="{TemplateBinding SelectedContent}" />
</DockPanel>
</ControlTemplate>
</Window.Resources>
<TabControl Template="{StaticResource ButtonsOnLeftTabLayout}">
<TabItem Header="Tab 1">
<StackPanel>
<Button HorizontalAlignment="Center">Button 1</Button>
</StackPanel>
</TabItem>
<TabItem Header="Tab 2">
<StackPanel>
<Button HorizontalAlignment="Center">Button 2</Button>
</StackPanel>
</TabItem>
</TabControl>
</Window>
Run Code Online (Sandbox Code Playgroud)
到目前为止我的搜索结果:
(搜索之后我终于找到了答案,但它花了比我想象的更长的时间,而且AutomationPeer的早期发现确实是错误的,所以我把它写成一个SO问题并自我回答,以防它在将来帮助其他人)
我有一个小托盘应用程序,它注册一个系统范围的热键.当用户在任何应用程序中的任何位置选择文本并按下此热键时,我希望能够捕获所选文本.我目前正在使用AutomationElements执行此操作:
//Using FocusedElement (since the focused element should be the control with the selected text?)
AutomationElement ae = AutomationElement.FocusedElement;
AutomationElement txtElement = ae.FindFirst(TreeScope.Subtree,Condition.TrueCondition);
if(txtElement == null)
return;
TextPattern tp;
try
{
tp = txtElement.GetCurrentPattern(TextPattern.Pattern) as TextPattern;
}
catch(Exception ex)
{
return;
}
TextPatternRange[] trs;
if (tp.SupportedTextSelection == SupportedTextSelection.None)
{
return;
}
else
{
trs = tp.GetSelection();
string selectedText = trs[0].GetText(-1);
MessageBox.Show(selectedText );
}
Run Code Online (Sandbox Code Playgroud)
这适用于某些应用程序(例如记事本,视觉工作室编辑框等)但不适用于所有应用程序(例如Word,FireFox,Chrome等).
这里的任何人都有任何关于如何在任何应用程序中检索所选文本的想法?
我的应用程序中有一个搜索字段,我已将此字段的键盘返回键类型设置为UIReturnKeyNext.我正在尝试编写一个UIAutomation测试,Next使用以下行单击键盘上的按钮:
UIATarget.localTarget().frontMostApp().mainWindow().keyboard().keys().firstWithName("next");
Run Code Online (Sandbox Code Playgroud)
此调用失败,因为找不到名为"next"的键.我使用以下方法对我的应用中的所有元素进行了转储:
UIATarget.localTarget().frontMostApp().logElementTree();
Run Code Online (Sandbox Code Playgroud)
这表明键盘上确实有一个名为"next"的键,但不知怎的,我上面显示的检索它的尝试仍然失败.然而,我可以使用此方法检索其他键(如字母'u'的键).这里有一个已知的问题还是我做错了什么?
我尝试了其他变种而没有运气:
UIATarget.localTarget().frontMostApp().mainWindow().keyboard().elements()["next"];
Run Code Online (Sandbox Code Playgroud)
这是我的UIAKeyboard中元素的屏幕截图:

我想获得的价值"HELLO"的UILabel在iPad模拟器中.我已启用辅助功能并将标签设置为"Label Access".但是当我调用时target.logElementTree(),名称和值都被设置为"LabelAccess",并且就apple文档而言,值字段应该包含设置的字符串(在本例中"Hello").有人知道解决这个问题吗?
PS:我使用的是最新的iOS SDK和Xcode. Apple Stack Exchange



这是一段UI代码
<select id="order_unit_line_rate_806782_is_addenda_enabled" class="selects_for_487886" onchange="select_addendum(806782, this);dateShowMemory(this.options[this.selectedIndex].value, '806782');" uniqueattr="Dynamic Site Accelerator / Dynamic Site Accelerator / Additional Usage Commitment / drop down" name="order_unit_line_rate[806782][is_addenda_enabled]">
<option value="0" uniqueattr="Dynamic Site Accelerator / Dynamic Site Accelerator / Additional Usage Commitment / Fee"> Fee </option>
<option value="1" uniqueattr="Dynamic Site Accelerator / Dynamic Site Accelerator / Additional Usage Commitment / See Attached Addendum"> See Attached Addendum </option>
</select>
Run Code Online (Sandbox Code Playgroud)
当<option>标签被嵌套在里面<select>的标签.我需要click()在第二个<option>元素上,它是下拉列表中的一个项目.当我尝试使用id/uniqueattr click()在<select>标签上时,可以点击下拉列表.
如何遍历<option>嵌套在下面的标签<select>并单击右侧的项目?
我使用uiautomatorviewer来做UI自动化.但是当我尝试拍摄快照以列出UI时,它显示adb未安装.
我知道从Xcode 4.2它开始可以UIAutomation通过命令行运行脚本.我试过这个,在模拟器中对我来说非常好.我想知道如何在实际设备中运行.我搜索并获得在设备上运行的命令,
instruments -w <device_id> -t /Developer/Platforms/iPhoneOS.platform/Developer/Library/Instruments/PlugIns/AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate
application -e UIASCRIPT
script -e UIARESULTSPATH <results path>
我应该在申请中给出什么,是通往ipa的路径还是其他什么?
提前谢谢
command-line instruments ui-automation ios ios-ui-automation
所以我有一个UIAutomator测试脚本,我在测试执行期间希望它运行一些adb命令.我该怎么做呢 ?
我在想有没有办法在UI自动化类中调用脚本?或者有没有办法直接执行"adb命令"?
这是我的代码:
package com.uia.example.my;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import com.android.uiautomator.core.UiObjectNotFoundException;
import com.android.uiautomator.testrunner.UiAutomatorTestCase;
public class ADBCommandTest extends UiAutomatorTestCase{
public void testDemo() throws UiObjectNotFoundException{
System.out.println("Entering the shell script");
try {
ProcessBuilder pb = new ProcessBuilder("./run.sh");
Process p = pb.start();
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = null;
while ((line = reader.readLine()) != null)
{
System.out.println(line);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Run Code Online (Sandbox Code Playgroud)
这是我得到的错误:
INSTRUMENTATION_STATUS: current=1
INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner
INSTRUMENTATION_STATUS: …Run Code Online (Sandbox Code Playgroud) 我试图通过UI Automation自动测试我的应用程序(主要TestStack.White用于提供友好的界面;它System.Windows.Automation用作后端).我有一个约200行的表,我需要测试它的值(实际上我只想测试第一行和最后几行).我发现使用COM-interop UIAutomationCore本身,我可以在几分之一秒内枚举行,但只有当我不使用White或System.Windows.Automation.一旦System.Windows.Automation初始化,未来的UI自动化行动枚举行是缓慢的:
First COM run: it took 0.04 seconds to get 102 rows!
First System.Windows.Automation run: it took 7.18 seconds to get 102 rows!
Second COM run: it took 7.87 seconds to get 102 rows!
Run Code Online (Sandbox Code Playgroud)
我创建了一个简单的WinForms测试应用程序(TableTest.exe以验证它是否System.Windows.Automation与我的应用程序无关:
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
var form = new Form() { Text = "TableTest", WindowState = FormWindowState.Maximized };
var dgv = new DataGridView() { Name = "DGV", Dock = DockStyle.Fill, …Run Code Online (Sandbox Code Playgroud) c# white-framework ui-automation winforms microsoft-ui-automation
有一个现有的基于JavaFX的应用程序,我应该为其编写自动化测试.我刚开始使用TestFX(版本4.0.13-alpha)并寻找建议,如何记录和识别应用程序的UI对象.我尝试使用代码来初始化按钮,但无法单击它.
Button button = new Button("click me!");
Run Code Online (Sandbox Code Playgroud)
我找到了这些 GUI检查工具,但不确定哪一个可以与TestFX一起使用.
ui-automation ×10
instruments ×3
ios ×3
adb ×2
android ×2
c# ×2
.net ×1
automation ×1
command-line ×1
iphone ×1
java ×1
javafx ×1
qtp ×1
scripting ×1
selenium ×1
testfx ×1
webdriver ×1
winforms ×1
wpf ×1
xcode ×1