我正在使用 Xcode“Instruments”工具为 iOS 应用程序构建自动化,我需要验证我在应用程序中创建的条目的标签是否正确。
出于某种原因,下面列出的代码不会导致可靠的通过或失败。相反,当它运行时,我在日志中收到“问题”警告,并且测试在没有明确关闭的情况下退出。
我想更改我的测试,以便检查我知道正在创建的标签名称,因为我可以在自动化运行后使用 AccessibilityViewer 看到它。
如果标签是正确的,那么我想将测试记录为通过。
我曾经UIATarget.localTarget().logElementTree()
映射我的元素树,并在我的条目创建后使用 AccessibilityInspector 来验证我的标签的名称。麻烦的是,我似乎无法获得验证此正确性的语法。
我的辅助功能检查员已验证标签名称为:MyDogs!它具有静态文本的特征,并给出 {{114, 0},{166,480}} 的框架
通过查看元素树——我希望我可以粘贴到这里,看起来标签会沿着这条路径找到:
\Target
-+
--\Application
---+
----\Window
-----+
------\TableView
-------+
--------\TableCell: name:MyDogs! rect:{0, 40},{480,166}}
---------|UIAStaticText: name:MyDogs! value:MyDogs! rect:{{0, 40},{480, 166}}
---------|UIAButton: name:story list share rect:{{439, 41},{33, 28}}
谁能告诉我如何验证这个标签?
我当前的代码看起来像这样(但没有检查标签——因为我不知道如何):
var testName = "LoginCreateEntry";
//Start test logging
UIALogger.logStart(testName);
//This is supposed to target the entry that my automation has created.
//The flow goes, run the automation that creates the entry, then verify that the entry
//got created as expected and is visible to the user in the iPhone interface.
var myEntry = target.frontMostApp().mainWindow().scrollViews().staticTexts()["My Dogs!"].value();
var entryName = "My Dogs!";
//Do a bunch of UI automation here to create my entry, which results in the entry
//appearing in the mainWindow with the label: My Dogs!
//If myEntry evaluates to true, then call this test a pass.
if (myEntry === entryName) {
UIALogger.logMessage("My entry was created!");
//Mark the test as a PASS
UIALogger.logPass(testName);
}
else {
UIALogger.logMessage("My entry was not created!");
//Mark the test as a FAIL
UIALogger.logFail(testName);
}
//End test
任何反馈或帮助将不胜感激!!
- - - - - - - - - - - - - - - - -更新 - - - - - - - - ----------------------
谢谢大家的帮助!我实际上得到了标题的值,并将在下面显示我的解决方案。但无论我做什么,我都无法让通过/失败日志记录功能正常工作——其他人也遇到过这个问题。我一直在愤怒
Issue: Script ended without explicting closing this test
我的测试结束时的消息。我越来越相信这是 Instruments 的错误。
这是我更新的测试:
var target = UIATarget.localTarget();
var app = UIATarget.localTarget().frontMostApp();
var testName = "LoginCreateEntry";
//Start test logging
UIALogger.logStart( testName );
//Do lots of gui automation stuff here to create the entry which will appear in my app interface.
//I want to verify that the title I gave the entry matches what appears in the app interface
var window = app.mainWindow();
var tableView = window.tableViews()[0];
var tableGroup = tableView.groups()[0];
var entryName = "My Dogs!";
var myEntry = tableView.cells()[0].name(); //<-- This is what I needed!!!
UIALogger.logMessage("My Story Title: " + myEntry); //Print out entry name in log
if (myEntry === entryName) {
UIALogger.logMessage("My entry was created!");
//Mark the test as a PASS
UIALogger.logPass (testName);
} else {
UIALogger.logMessage("My entry was not created!");
//Mark the test as a FAIL
UIALogger.loFails (testName);
}
//End test