在UI测试中找不到搜索栏

时间:2019-11-03 17:51:54

标签: ios swift xcode-ui-testing

我有一个这样创建的搜索控制器:

private static String dirPath = "https://hauteuchdrum.informatik.uni-siegen.de/propra/aufgaben/ws1920/index.php";
         public ArrayList<String> Bestellung(){
            File file = new File (dirPath + "//array_complex.json");
            ArrayList <String> test = new ArrayList<String>();
            try {
                String str = "{ \"Bestellnummer\": [1,2,3,4,5] }";

                // holt alle 47550 bestellungen vom json  
                for (int i=1; i<2;i++) {
                String POST_PARAMS = "json={\"bid\":\"bid\", \"getorder\":\""+i+"\"}";
                    //System.out.println(POST_PARAMS);

                JSONObject obj1 = new JSONObject(POST_PARAMS);
                JSONArray arr=obj1.getJSONArray("Bestellnummer");
                for (int z=0; z<arr.length();z++) {
                    String post_id = arr.getJSONObject(z).getString("Bestellnummer");
                    System.out.println(post_id);
                }
                 URL obj = new URL("https://hauteuchdrum.informatik.uni-siegen.de/propra/aufgaben/ws1920/index.php");
                 HttpURLConnection postConnection = (HttpURLConnection) obj.openConnection();
                 postConnection.setRequestMethod("POST");
                 postConnection.setRequestProperty("connection", "Keep-Alive");
                 postConnection.setDoOutput(true);
                 java.io.OutputStream os = postConnection.getOutputStream();
                    os.write(POST_PARAMS.getBytes());
                    os.flush();
                    os.close();

                    int responseCode = postConnection.getResponseCode();
                    //System.out.println("POST Response Code :  " + responseCode);
                   // System.out.println("POST Response Message : " + postConnection.getResponseMessage());
                    if (responseCode == HttpURLConnection.HTTP_OK) { //success
                        BufferedReader in = new BufferedReader(new InputStreamReader(postConnection.getInputStream()));
                        String inputLine;
                        StringBuffer response = new StringBuffer();
                        while ((inputLine = in.readLine()) != null) {
                            response.append(inputLine);
                        } 
                        in.close();
                        // print result
                      //  System.out.println(response.toString());
                        test.add(response.toString());
                     //   java.util.Iterator<String> it = test.iterator();
                     // while (it.hasNext()) {
                       //   System.out.println(it.next());
                    //    }

                    }
        }
            }
            catch (Exception e) {
                System.out.println();
            }
            return test;
        }

稍后,将搜索控制器添加到视图控制器,并且其搜索栏成为层次结构的一部分。我正在尝试在UI测试中测试搜索栏的存在:

let searchController = UISearchController(searchResultsController: nil)
let searchBar = searchController.searchBar
searchBar.isAccessibilityElement = true
searchBar.accessibilityIdentifier = "ComplaintSearchBar"
searchBar.accessibilityTraits = .searchField

但是测试一直失败,找不到搜索栏。我对搜索栏比搜索栏更感兴趣,但是问题是,在iOS 12及更低版本中,无法(通过使用valueForKey期待黑客攻击)来获取搜索栏。有什么方便的解决方案吗?

0 个答案:

没有答案