public static RTCStats getPCStatOnce(WebDriver webDriver, String peerConnection, JsonArray selectedStats, int batchId, String platform) throws KiteTestException {
    try {
      RTCStats rtn;
      switch(platform.toLowerCase()) {
        case "android":
          waitAround(300);
          ((AndroidElement) ((AndroidDriver) webDriver).findElementsByClassName("android.widget.EditText").get(0)).click();
          ((AndroidElement) ((AndroidDriver) webDriver).findElementsByClassName("android.widget.EditText").get(0)).sendKeys("JSON.stringify(window.KITEStats)");
          ((AndroidElement) ((AndroidDriver) webDriver).findElementsByClassName("android.view.View").get(10)).findElementsByClassName("android.widget.TextView").get(2).click();

          Gson gson = new Gson();
          List<Map> list = gson.fromJson(((AndroidElement) ((AndroidDriver) webDriver).findElementsByClassName("android.widget.TextView").get(17)).getText(), new TypeToken<ArrayList<Map>>() {}.getType());
          ((AndroidElement) ((AndroidDriver) webDriver).findElementsByClassName("android.widget.EditText").get(0)).click();
          ((AndroidElement) ((AndroidDriver) webDriver).findElementsByClassName("android.widget.EditText").get(0)).sendKeys("const getStatsValues = () => peer.getStats().then(data => {  return [...data.values()];}); const stashStats = async () => {  window.KITEStats = await getStatsValues();  return 0;};stashStats(); clear();");
          ((AndroidElement) ((AndroidDriver) webDriver).findElementsByClassName("android.view.View").get(12)).findElementsByClassName("android.widget.TextView").get(1).click(); // execute
          rtn = new RTCStats(peerConnection,
                  list, selectedStats);
          rtn.setRoomUrl("N/A");

          break;
        case "ios":
          int tries = 0;
          waitAround(300);
          ((IOSDriver) webDriver).findElementByClassName("XCUIElementTypeTextView").click();
          ((IOSDriver) webDriver).findElementByClassName("XCUIElementTypeTextView").sendKeys("JSON.stringify(window.KITEStats)");
          do {
            ((IOSElement) ((IOSDriver) webDriver).findElementsById("Live Viewer").get(0)).click();
            waitAround(200);
            tries++;
          } while (tries<5 && ((IOSDriver) webDriver).isKeyboardShown());

          WebDriverUtils.scroll_ios((IOSDriver) webDriver,0.5, 0.8, 0.5, 0.2);
          waitAround(300);
          ((IOSDriver) webDriver).findElementById("Execute").click();
          waitAround(300);


          gson = new Gson();
           try {
            list = gson.fromJson(((IOSElement) ((IOSDriver) webDriver).findElementsByClassName("XCUIElementTypeStaticText").get(14)).getText(), new TypeToken<ArrayList<Map>>() {
            }.getType());
          } catch(Exception e) {
            list = gson.fromJson(((IOSElement) ((IOSDriver) webDriver).findElementsByClassName("XCUIElementTypeStaticText").get(6)).getText(), new TypeToken<ArrayList<Map>>() {
            }.getType());
          }
          ((IOSDriver) webDriver).findElementByClassName("XCUIElementTypeTextView").click();
          ((IOSDriver) webDriver).findElementByClassName("XCUIElementTypeTextView").sendKeys("const getStatsValues = () => peer.getStats().then(data => {  return [...data.values()];}); const stashStats = async () => {  window.KITEStats = await getStatsValues();  return 0;};stashStats(); clear();"); // write command
          tries = 0;
          do {
            ((IOSElement) ((IOSDriver) webDriver).findElementsById("Live Viewer").get(0)).click();
            waitAround(200);
            tries++;
          } while (tries<5 && ((IOSDriver) webDriver).isKeyboardShown());

          WebDriverUtils.scroll_ios((IOSDriver) webDriver,0.5, 0.8, 0.5, 0.2);
          waitAround(300);
          ((IOSDriver) webDriver).findElementById("Execute").click(); // execute

          try {
            rtn = new RTCStats(peerConnection,
                    list, selectedStats);
            rtn.setRoomUrl("N/A");
          } catch(Exception e) {
            logger.info(e);
            logger.info("Couldn't do stats");
            throw e;
          }
          break;
        default:
          String stashStatsScript = "const getStatsValues = () =>" +
                  peerConnection + "  .getStats()" +
                  "    .then(data => {" +
                  "      return [...data.values()];" +
                  "    });" +
                  "const stashStats = async () => {" +
                  "  window.KITEStats = await getStatsValues();" +
                  "  return 0;" +
                  "};" +
                  "stashStats();";
          String getStashedStatsScript = "return window.KITEStats;";
          executeJsScript(webDriver, stashStatsScript);
          waitAround(Timeouts.ONE_SECOND_INTERVAL);
          rtn = new RTCStats(peerConnection,
                  (List<Map>) executeJsScript(webDriver, getStashedStatsScript), selectedStats);
          rtn.setRoomUrl(webDriver.getCurrentUrl());
          break;
      }

      rtn.setBatch(batchId);
      return rtn;

    } catch (Exception e) {
//      throw new KiteTestException("Could not get stats from peer connection", Status.BROKEN, e);
      // todo: put the e back
      throw new KiteTestException("Could not get stats from peer connection: " + e.getLocalizedMessage(), Status.BROKEN);
    }
  }
Stashes stats into a global variable and collects them 1s after

@param webDriver      used to execute command.
@param peerConnection the peer connection
@param selectedStats  array of chosen stats

@return String. pc stat once
@throws KiteTestException the KITE test exception
KITE-Framework/src/main/java/org/webrtc/kite/stats/StatsUtils.java