简体   繁体   English

处理数组; 由iOS UI Automation中的方法返回

[英]Handling of array; returned by methods in iOS UI Automation

I have been able to use all the methods for automating iphone app test except with ones which returns array... eg elements() 除了返回数组的方法外,我已经能够使用所有方法来自动执行iphone应用程序测试...例如elements()

I have tried to do it using declaration of array as 我尝试使用数组声明作为

var arr  =  [];
var arr  =  UIATarget.localTarget().frontMostApp().mainWindow().tabBar().elements();
UIALogger.logPass("result"+ arr[0])     // just to get first element

But it is not working 但这不起作用

Can someone ans how to handle array . 有人可以处理array吗? What is the correcting required? 需要什么纠正?

What exactly do you want from such array? 您究竟想从这种阵列中得到什么?

Here is an example how to handle array of elements: 这是一个如何处理元素数组的示例:

function getAllNamesInList (list, index){

   var elem_list = list[index].elements();
   var elem_count = elem_list .length;
   var names = [];
   var elem_name;

   for (var elem_ind = 0;  elem_ind < elem_count ; elem_ind++){

      elem_name= elem_list [cell_ind].name();
      if (!elem_name){fail ("TEST_INFO: Empty Element name!!!");}
      names.push(elem_name);
   }

   return names;

};

Here is usage example of this function(): 这是此function()的用法示例:

Your case: 您的情况:

var app =  UIATarget.localTarget().frontMostApp();
var window = app.mainWindow();
var arr  = window.tabBar()
var current_names = [];

current_names = getAllNamesInList (arr , 0);
UIALogger.logMessage ("Here are ALL names from array " + current_names );

Other possible lists which can be transferred and used within this function(): 可以在此function()中转移和使用的其他可能列表:

var table_views = window.tableViews();
var tab_bar = app.tabBar();
var nav_bar = app.navigationBar();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM