我正在尝试使用Apple的UIAutomation为具有服务器端组件的iOS应用程序编写单元测试.为了在各种状态下设置测试服务器(以及模拟通过我的服务器进行通信的两个客户端),我想在基于javascript的测试中发出HTTP get请求.
任何人都可以提供一个示例,说明如何直接从UIAutomation javascript测试中发出HTTP GET请求,或者如何从我的UIAutomation javascript测试中调用shell脚本?
FWIW,UIAutomation运行时中缺少所有浏览器提供的大多数核心对象.例如,尝试使用XMLHTTPRequest,您将收到一个异常报告,它无法找到该变量.
谢谢!
我是iOS UIAutomation的新手,这是我面临的问题
我有一个视图层次结构如下所示,并希望访问自动化sctipt中的CustomView2元素
UIWindow> UIScrollView> CustomView1(多个)> CustomView2(多个)
scrollview具有CustomView1类型的子视图,而CustomView1又具有CustomView2类型的子视图.
我已将可访问性信息分配给层次结构中的所有视图,但我无法访问自动化脚本中的CustomView2元素.
当我在UIScrollView上执行logElementTree()时,我得到的只是CustomView2的实例,而CustomView2甚至不在UIWindow的树结构中.
请建议是否有任何遗漏或出现任何问题.
这是我正在使用的代码
var mainWindow = application.mainWindow();
var scrollView = mainWindow.scrollViews()[0];
var custom1 = scrollView.elements().withName("CustomView1");
for(var index=0; index<custom1.length; index++){
currentIndustry.tap();
custom1[index].logElementTree();
var custom2 = custom1[index].elements().withName("CustomView2");
UIALogger.logPass("Custom2 Length : " + custom2.length);
}
Run Code Online (Sandbox Code Playgroud)
由custom1 [index] .logElementTree()打印的树; 不包含CustomView2的实例
PS我需要访问CustomView1和CustomView2元素
有没有人在带有示例项目的UIAutomation测试脚本上找到任何示例?到目前为止,我发现只有WWDC2010视频涵盖了这个主题,但没有样本脚本/项目可以使用.
在Xcode/Instruments中编辑脚本时,有没有办法实现代码建议/自动完成?
对不起,"这不应该工作吗?" 题.但我无法想出一个更好的方式来表达这一点.
enum MyEnum {
case A, B, C
}
let tuple = (MyEnum.C, MyEnum.A)
var x: String
switch tuple {
case (.A, _):
x = "(A, something)"
case (_, .A):
x = "(something, A)"
case (_, .B):
x = "(something, B)"
case (.C, .C):
x = "(C, C)"
default:
x = "default"
}
x // -> "default"
Run Code Online (Sandbox Code Playgroud)
x
求值为"default"
,表示采用了默认分支.
但是,我期待"(something, A)"
和第二个案例陈述相匹配.根据我的理解,(_, .A)
应该匹配第一个元组元素和.A
第二个元素中的任何内容.
如果我将(_, .A)
表壳移到顶部,它会按照我的预期进行匹配.其他元组也匹配我期望的位置.
我错过了什么?为什么这不符合第二种情况?
我正在开发一个通用的iOS应用程序,但是一些用户设置在iPad上没那么明显.
我可以在iPad上指定单独的Settings.bundle或Root.plist吗?
标题已经解释了.我正在寻找一种解决方案,将UIAutomation脚本中使用target.captureScreenWithName拍摄的屏幕截图与一些参考图像进行比较.这对测试一些自定义视图非常好.
我可以使用Xcode的自动缩进来缩进延续线吗?
我想要:
BOOL someLongVariableName = someLongValue
| someOtherLongValue
| moreLongValues
BOOL someOtherLongVariableName =
someEvenLongerValue;
[someLongVariableName
performSomeAction:someLongArgument]
Run Code Online (Sandbox Code Playgroud)
我目前得到:
BOOL someLongVariableName = someLongValue
| someOtherLongValue
| moreLongValues
BOOL someOtherLongVariableName =
someEvenLongerValue;
[someLongVariableName
performSomeAction:someLongArgument]
Run Code Online (Sandbox Code Playgroud)
要明确:
我能够看到视图,但我无法看到/点击其中的按钮.该按钮具有UIA_loginview_loginbutton的辅助功能标签,并且启用了辅助功能.为什么它没有显示在logElementTree()上?
var target = UIATarget.localTarget();
var application = target.frontMostApp();
var window = application.mainWindow();
var view = window.elements().firstWithName("UIA_loginview_view");
UIATarget.localTarget().logElementTree();
UIATarget.localTarget().frontMostApp().logElementTree();
if(view == null || view.toString() == "[object UIAElementNil]")
{
UIALogger.logFail("View not found - "+view.toString());
}
else
{
UIALogger.logPass("View found - "+view.toString());
UIALogger.logMessage("View Elements length - "+view.buttons().length);
view.buttons()["UIA_loginview_loginbutton"].tap();
}
Run Code Online (Sandbox Code Playgroud)
日志元素树://显示我的视图,但不显示其中的按钮
4)UIAElement [name:UIA_loginview_view value:(null)NSRect:{{0,20},{320,460}}]
我想为一个相当复杂的iPhone应用程序编写UIAutomation(基于JavaScript)测试.我不想使用一个单独的大文件,而是通过使用几个文件来分离测试函数和帮助程序.这有可能吗?你如何构建你的UIAutomation测试?
我有一个简单的函数,应该检查视图是否在home接口,如果没有,将它带到家里:
function returnHome() {
if (UIATarget.localTarget().frontMostApp().navigationBar().name() == mainTitle) return true;
// set tab bar to calculations
UIALogger.logMessage("Set tab bar to main.");
if (UIATarget.localTarget().frontMostApp().tabBar().selectedButton().name() != mainTabName) {
UIATarget.localTarget().frontMostApp().tabBar().buttons()[mainTabName].tap();
}
// go back to the home
UIALogger.logMessage("Go back to home.");
var backButton = UIATarget.localTarget().frontMostApp().mainWindow().buttons()["Back"];
if (backButton.isValid()) {
backButton.tap();
} else {
UIALogger.logError("Could not find 'Back' button!");
}
}
Run Code Online (Sandbox Code Playgroud)
现在,我无法通过错误"无法找到'返回'按钮!".它在那里,在左角,盯着我,嘲弄我!
在UIATarget.localTarget().frontMostApp().logElementTree()
给了我下面的树:
2) UIAApplication [name:MyApplication value:(null) rect:{{x:0, y:20}, {width:320, height:460}}]
3) UIAWindow [name:(null) value:(null) rect:{{x:0, y:0}, {width:320, height:480}}]
4) UIAImage [name:(null) value:(null) …
Run Code Online (Sandbox Code Playgroud) iphone ×7
ios ×6
xcode ×3
cocoa-touch ×2
instruments ×2
javascript ×2
indentation ×1
ipad ×1
scrollview ×1
swift ×1
universal ×1