如何使用iOS上的Instruments验证表格视图中标签的名称?

前端之家收集整理的这篇文章主要介绍了如何使用iOS上的Instruments验证表格视图中标签的名称?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用 Xcode“Instruments”工具为iOS应用程序构建自动化,我需要验证我在我的应用程序中创建的条目的标签是否正确.

由于某种原因,下面列出的代码不会导致稳定的通过或失败.相反,当它运行时,我在日志中得到一个“问题”警告,并且测试退出而没有明确关闭.

我想更改我的测试,以便检查我知道正在创建的标签名称,因为我可以在自动化运行后使用AccessibilityViewer查看它.

如果标签是正确的,那么我想将测试记录为通过.

我已经使用了UIATarget.localTarget().logElementTree()来映射我的元素树,并且在创建条目后我使用了AccessibilityInspector来验证我的标签名称.麻烦的是,我似乎无法获得验证这个正确的语法.

我的辅助功能检查器已验证标签名称为:MyDogs!它具有静态文本的特征,并给出了{{114,0},{166,480}}的框架

通过查看元素树 – 我希望我可以粘贴在这里,看起来像沿着这条路径找到标签

  1. \Target
  2. -+
  3. --\Application
  4. ---+
  5. ----\Window
  6. -----+
  7. ------\TableView
  8. -------+
  9. --------\TableCell: name:MyDogs! rect:{0,40},{480,166}}
  10. ---------|UIAStaticText: name:MyDogs! value:MyDogs! rect:{{0,166}}
  11. ---------|UIAButton: name:story list share rect:{{439,41},{33,28}}

谁能告诉我如何验证这个标签

我当前的代码看起来像这样(但不检查标签 – 因为我不知道如何):

  1. var testName = "LoginCreateEntry";
  2.  
  3. //Start test logging
  4. UIALogger.logStart(testName);
  5.  
  6. //This is supposed to target the entry that my automation has created.
  7. //The flow goes,run the automation that creates the entry,then verify that the entry
  8. //got created as expected and is visible to the user in the iPhone interface.
  9.  
  10. var myEntry = target.frontMostApp().mainWindow().scrollViews().staticTexts()["My Dogs!"].value();
  11.  
  12. var entryName = "My Dogs!";
  13.  
  14. //Do a bunch of UI automation here to create my entry,which results in the entry
  15. //appearing in the mainWindow with the label: My Dogs!
  16.  
  17. //If myEntry evaluates to true,then call this test a pass.
  18.  
  19. if (myEntry === entryName) {
  20. UIALogger.logMessage("My entry was created!");
  21.  
  22. //Mark the test as a PASS
  23. UIALogger.logPass(testName);
  24. }
  25. else {
  26.  
  27. UIALogger.logMessage("My entry was not created!");
  28.  
  29. //Mark the test as a FAIL
  30. UIALogger.logFail(testName);
  31. }
  32.  
  33. //End test

任何反馈或帮助将非常感谢!!

——————————— UPDATE —————- ———————-

感谢你的帮助!我实际上得到了标题的价值,并将在下面显示我的解决方案.但是无论我做什么,我都无法使通过/失败记录功能正常工作 – 问题也是encountered by others.我一直在激动不已

问题:脚本结束时没有说明关闭此测试

我测试结束时的消息.我开始相信这是仪器的一个错误.

这是我更新的测试:

  1. var target = UIATarget.localTarget();
  2. var app = UIATarget.localTarget().frontMostApp();
  3.  
  4. var testName = "LoginCreateEntry";
  5.  
  6. //Start test logging
  7. UIALogger.logStart( testName );
  8.  
  9. //Do lots of gui automation stuff here to create the entry which will appear in my app interface.
  10. //I want to verify that the title I gave the entry matches what appears in the app interface
  11.  
  12. var window = app.mainWindow();
  13. var tableView = window.tableViews()[0];
  14. var tableGroup = tableView.groups()[0];
  15. var entryName = "My Dogs!";
  16.  
  17. var myEntry = tableView.cells()[0].name(); //<-- This is what I needed!!!
  18.  
  19. UIALogger.logMessage("My Story Title: " + myEntry); //Print out entry name in log
  20.  
  21. if (myEntry === entryName) {
  22.  
  23. UIALogger.logMessage("My entry was created!");
  24.  
  25. //Mark the test as a PASS
  26. UIALogger.logPass (testName);
  27.  
  28. } else {
  29.  
  30. UIALogger.logMessage("My entry was not created!");
  31.  
  32. //Mark the test as a FAIL
  33. UIALogger.loFails (testName);
  34.  
  35. }
  36. //End test

解决方法

我建议使用 tuneup_js.使用该库,您可以轻松创建测试用例并检查标签是否存在且与My Dogs相同

你可以像这样使用它

  1. test("LoginCreateEntry",function(target,app){
  2. //Create Entry
  3. //....
  4. var myEntry = target.frontMostApp().mainWindow().scrollViews().staticTexts()["My Dogs!"].name();
  5.  
  6. //Check is Label is equal to My Dogs
  7. //Test "LoginCreateEntry" will fail if myEntry is not equal to My Dogs
  8. assertEquals(myEntry,"My Dogs");
  9. });

附:你应该使用.name()而不是.value()来获取标签名称

猜你在找的iOS相关文章