private void handleErrorResponse(Object object) {
   ErrorResponse response = (ErrorResponse) object;
   ITestResult testResult = new FailureResult(response.getMessage());
   testResult.setScreenShot(response.screenshot);
   if (valueResponseMap.keySet().contains(response.getId())) {
     valueResponseMap.put(response.getId(), testResult);
   } else if (existsResponseMap.keySet().contains(response.getId())) {
     existsResponseMap.put(response.getId(), testResult);
   } else {
     // notify runner
     LOG.error("Error result received {}", response.getMessage());
   }
 }
  @Override
  public ITestResult processAndWaitForValue(IIdRequest request)
      throws IllegalAccessException, TimeoutException, ErrorResultReceivedException {

    final String idRequest = request.getId();
    if (idRequest == null) {
      throw new IllegalAccessException("Request requires an Id to wait for a value.");
    }
    init();
    valueResponseMap.put(idRequest, VOID_RESULT);
    client.sendRequest(request);
    ValueResponse valueResponse = waitForValue(request);
    ITestResult res = new SuccessResult(valueResponse.value);
    res.setScreenShot(valueResponse.getBase64ScreenShot());
    return res;
  }
 private ValueResponse waitForValue(final IIdRequest request)
     throws TimeoutException, ErrorResultReceivedException {
   client.keepAlive();
   final String idRequest = request.getId();
   ValueResponse res = null;
   int countTimeOut = WAIT_TIMEOUT;
   int incOffset = 500;
   if (valueResponseMap.containsKey(idRequest)) {
     while (VOID_RESULT.equals(valueResponseMap.get(idRequest))) {
       try {
         client.keepAlive();
         Thread.sleep(incOffset);
         countTimeOut = countTimeOut - incOffset;
         if (countTimeOut <= 0) {
           valueResponseMap.remove(idRequest);
           throw new TimeoutException(
               "No Response received for request: "
                   + idRequest
                   + " after "
                   + (WAIT_TIMEOUT / 1000)
                   + "s !");
         }
       } catch (InterruptedException e) {
         e.printStackTrace();
       }
     }
     if (valueResponseMap.get(idRequest) instanceof ITestResult) {
       ITestResult result = (ITestResult) valueResponseMap.get(idRequest);
       ValueResponse valueResponse =
           new ValueResponse(idRequest, result.getMessage(), result.getScreenShot());
       valueResponseMap.remove(idRequest);
       return valueResponse;
     }
     res = (ValueResponse) valueResponseMap.get(idRequest);
     valueResponseMap.remove(idRequest);
   }
   return res;
 }