Best Cerberus-source code snippet using org.cerberus.util.ParamRequestMaker.addParam
Source:ExecutionQueueWorkerThread.java
...63 public static String PARAMETER_OUTPUT_FORMAT_VALUE = "verbose-txt";64 private ParamRequestMaker makeParamRequest() {65 ParamRequestMaker paramRequestMaker = new ParamRequestMaker();66 try {67 paramRequestMaker.addParam(RunTestCaseV001.PARAMETER_TEST, URLEncoder.encode(getToExecute().getTest(), "UTF-8"));68 paramRequestMaker.addParam(RunTestCaseV001.PARAMETER_TEST_CASE, URLEncoder.encode(getToExecute().getTestCase(), "UTF-8"));69 paramRequestMaker.addParam(RunTestCaseV001.PARAMETER_COUNTRY, getToExecute().getCountry());70 paramRequestMaker.addParam(RunTestCaseV001.PARAMETER_ENVIRONMENT, getToExecute().getEnvironment());71 paramRequestMaker.addParam(RunTestCaseV001.PARAMETER_ROBOT, getToExecute().getRobot());72 paramRequestMaker.addParam(RunTestCaseV001.PARAMETER_ROBOTEXECUTOR, getRobotExecutor());73 paramRequestMaker.addParam(RunTestCaseV001.PARAMETER_ROBOT_IP, getToExecute().getRobotIP());74 paramRequestMaker.addParam(RunTestCaseV001.PARAMETER_ROBOT_PORT, getToExecute().getRobotPort());75 paramRequestMaker.addParam(RunTestCaseV001.PARAMETER_BROWSER, getToExecute().getBrowser());76 paramRequestMaker.addParam(RunTestCaseV001.PARAMETER_BROWSER_VERSION, getToExecute().getBrowserVersion());77 paramRequestMaker.addParam(RunTestCaseV001.PARAMETER_PLATFORM, getToExecute().getPlatform());78 paramRequestMaker.addParam(RunTestCaseV001.PARAMETER_SCREEN_SIZE, getToExecute().getScreenSize());79 if (getToExecute().getManualURL() >= 1) { // 1 (Activate) or 2 (Override)80 if (getToExecute().getManualURL() == 1) { // set manual url only if 1. if 2, manual url == false and, we ovveride host, contextroot, login and env data if attributs available81 paramRequestMaker.addParam(RunTestCaseV001.PARAMETER_MANUAL_URL, ParameterParserUtil.DEFAULT_BOOLEAN_TRUE_VALUE);82 }83 addIfNotNullOrEmpty(paramRequestMaker, RunTestCaseV001.PARAMETER_MANUAL_HOST, getToExecute().getManualHost(), true);84 addIfNotNullOrEmpty(paramRequestMaker, RunTestCaseV001.PARAMETER_MANUAL_CONTEXT_ROOT, getToExecute().getManualContextRoot(), true);85 addIfNotNullOrEmpty(paramRequestMaker, RunTestCaseV001.PARAMETER_MANUAL_LOGIN_RELATIVE_URL, getToExecute().getManualLoginRelativeURL(), true);86 addIfNotNullOrEmpty(paramRequestMaker, RunTestCaseV001.PARAMETER_MANUAL_ENV_DATA, getToExecute().getManualEnvData(), false);87 }88 paramRequestMaker.addParam(RunTestCaseV001.PARAMETER_TAG, URLEncoder.encode(getToExecute().getTag(), "UTF-8"));89 paramRequestMaker.addParam(RunTestCaseV001.PARAMETER_SCREENSHOT, Integer.toString(getToExecute().getScreenshot()));90 paramRequestMaker.addParam(RunTestCaseV001.PARAMETER_VERBOSE, Integer.toString(getToExecute().getVerbose()));91 paramRequestMaker.addParam(RunTestCaseV001.PARAMETER_TIMEOUT, getToExecute().getTimeout());92 paramRequestMaker.addParam(RunTestCaseV001.PARAMETER_PAGE_SOURCE, Integer.toString(getToExecute().getPageSource()));93 paramRequestMaker.addParam(RunTestCaseV001.PARAMETER_SELENIUM_LOG, Integer.toString(getToExecute().getSeleniumLog()));94 paramRequestMaker.addParam(RunTestCaseV001.PARAMETER_EXECUTION_QUEUE_ID, Long.toString(getToExecute().getId()));95 paramRequestMaker.addParam(RunTestCaseV001.PARAMETER_NUMBER_OF_RETRIES, Long.toString(getToExecute().getRetries()));96 paramRequestMaker.addParam(RunTestCaseV001.PARAMETER_EXECUTOR, getToExecute().getUsrCreated());97 paramRequestMaker.addParam(RunTestCaseV001.PARAMETER_MANUAL_EXECUTION, getToExecute().getManualExecution());98 paramRequestMaker.addParam(RunTestCaseV001.PARAMETER_OUTPUT_FORMAT, PARAMETER_OUTPUT_FORMAT_VALUE);99 paramRequestMaker.addParam(RunTestCaseV001.PARAMETER_SYNCHRONEOUS, ParameterParserUtil.DEFAULT_BOOLEAN_TRUE_VALUE);100 } catch (UnsupportedEncodingException ex) {101 LOG.error("Error when encoding string in URL : ", ex);102 }103 return paramRequestMaker;104 }105 /**106 * The associated {@link RuntimeException} for any errors during the run107 * process108 */109 public static class RunQueueProcessException extends RuntimeException {110 public RunQueueProcessException(String message) {111 super(message);112 }113 public RunQueueProcessException(String message, Throwable cause) {114 super(message, cause);115 }116 }117 public ITestCaseExecutionQueueDepService getQueueDepService() {118 return queueDepService;119 }120 public void setQueueDepService(ITestCaseExecutionQueueDepService queueDepService) {121 this.queueDepService = queueDepService;122 }123 public String getRobotExecutor() {124 return robotExecutor;125 }126 public void setRobotExecutor(String robotExecutor) {127 this.robotExecutor = robotExecutor;128 }129 public String getSelectedRobotHost() {130 return selectedRobotHost;131 }132 public void setSelectedRobotHost(String selectedRobotHost) {133 this.selectedRobotHost = selectedRobotHost;134 }135 public String getSelectedRobotExtHost() {136 return selectedRobotExtHost;137 }138 public void setSelectedRobotExtHost(String selectedRobotExtHost) {139 this.selectedRobotExtHost = selectedRobotExtHost;140 }141 public TestCaseExecutionQueue getToExecute() {142 return toExecute;143 }144 private void setToExecute(TestCaseExecutionQueue toExecute) {145 this.toExecute = toExecute;146 }147 public ITestCaseExecutionQueueService getQueueService() {148 return queueService;149 }150 public void setQueueService(ITestCaseExecutionQueueService queueService) {151 this.queueService = queueService;152 }153 public void setRetriesService(IRetriesService retriesService) {154 this.retriesService = retriesService;155 }156 public void setCerberusExecutionUrl(String url) {157 this.cerberusExecutionUrl = url;158 }159 public void setQueueId(long queueId) {160 this.queueId = queueId;161 }162 public void setExecThreadPool(ExecutionQueueThreadPool etp) {163 this.execThreadPool = etp;164 }165 public void setFuture(Future<?> future) {166 this.future = future;167 }168 public int getToExecuteTimeout() {169 return toExecuteTimeout;170 }171 public void setToExecuteTimeout(int toExecuteTimeout) {172 this.toExecuteTimeout = toExecuteTimeout;173 }174 @Override175 public void run() {176 try {177 LOG.debug("Start to execute : " + queueId + " with RobotHost : " + selectedRobotHost+ " with RobotExtensionHost : " + selectedRobotExtHost);178 // Flag the queue entry to STARTING179 queueService.updateToStarting(queueId, selectedRobotHost, selectedRobotExtHost);180 LOG.debug("Get queue exe to execute : " + queueId);181 // Getting the queue full object.182 setToExecute(queueService.convert(queueService.readByKey(queueId, false)));183 StringBuilder url = new StringBuilder();184 url.append(cerberusExecutionUrl);185 url.append(RunTestCaseV001.SERVLET_URL);186 url.append("?");187 url.append(makeParamRequest().mkString().replace(" ", "+"));188 LOG.debug("Make http call : " + queueId);189 // Make the http call and parse the output.190 runParseAnswer(runExecution(url), cerberusExecutionUrl + RunTestCaseV001.SERVLET_URL, url.toString());191 } catch (Exception e) {192 LOG.warn("Execution in queue " + queueId + " has finished with error");193 try {194 queueService.updateToError(queueId, e.getMessage());195 queueDepService.manageDependenciesEndOfQueueExecution(queueId);196 } catch (CerberusException again) {197 LOG.error("Unable to mark execution in queue " + queueId + " as in error", again);198 }199 }200 }201 /**202 * Request execution of the inner {@link TestCaseExecutionQueue} to the203 * {@link RunTestCase} servlet204 *205 * @return the execution answer from the {@link RunTestCase} servlet206 * @throws RunQueueProcessException if an error occurred during request207 * execution208 * @see #run()209 */210 private String runExecution(StringBuilder url) {211 try {212 LOG.debug("Trigger Execution to URL : " + url.toString());213 LOG.debug("Trigger Execution with TimeOut : " + toExecuteTimeout);214 CloseableHttpClient httpclient = HttpClientBuilder.create().disableAutomaticRetries().build();215 RequestConfig requestConfig = RequestConfig.custom()216 .setConnectTimeout(toExecuteTimeout)217 .setConnectionRequestTimeout(toExecuteTimeout)218 .setSocketTimeout(toExecuteTimeout)219 .build();220 HttpGet httpGet = new HttpGet(url.toString());221 httpGet.setConfig(requestConfig);222 CloseableHttpResponse response = httpclient.execute(httpGet);223 HttpEntity entity = response.getEntity();224 String responseContent = EntityUtils.toString(entity);225 return responseContent;226 } catch (Exception e) {227 final StringBuilder errorMessage = new StringBuilder("An unexpected error occurred during test case execution: ");228 if (e instanceof HttpResponseException) {229 errorMessage.append(String.format("%d (%s)", ((HttpResponseException) e).getStatusCode(), e.getMessage()));230 } else {231 errorMessage.append(e.getMessage());232 errorMessage.append(". Check server logs");233 }234 LOG.error(errorMessage.toString(), e);235 throw new RunQueueProcessException(errorMessage.toString(), e);236 }237 }238 /**239 * Parse the answer given by the {@link RunTestCase}240 * <p>241 * @param answer the {@link RunTestCase}'s answer242 * @throws RunQueueProcessException if an error occurred if execution was on243 * failure or if answer cannot be parsed244 * @see #run()245 */246 private void runParseAnswer(String answer, String cerberusUrl, String cerberusFullUrl) {247 // Check answer format248 Matcher matcher = EXECUTION_ID_FROM_ANSWER_PATTERN.matcher(answer);249 if (!matcher.find()) {250 LOG.error("Bad answer format (could not find 'RunID = '). URL Called: " + cerberusFullUrl);251 LOG.error("Bad answer format (could not find 'RunID = '). Answer: " + answer);252 throw new RunQueueProcessException("Error occured when calling the service to run the testcase. Service answer did not have the expected format (missing 'RunID = '). Probably due to bad cerberus_url value. URL Called: '" + cerberusUrl + "'.");253 }254 // Extract the return code255 Long executionID;256 try {257 executionID = Long.parseLong(matcher.group(1));258 } catch (NumberFormatException e) {259 LOG.error("Bad answer format (executionId is not numeric). Answer: " + answer);260 throw new RunQueueProcessException("Bad return code format: " + matcher.group(1));261 }262 // Check if return code is in error263 if (executionID == 0) {264 Matcher descriptionMatcher = RETURN_CODE_DESCRIPTION_FROM_ANSWER_PATTERN.matcher(answer);265 if (!descriptionMatcher.find()) {266 LOG.error("Bad answer format (could not find 'ReturnCodeDescription = '). URL Called: " + cerberusFullUrl);267 LOG.error("Bad answer format (could not find 'ReturnCodeDescription = '). Answer: " + answer);268 throw new RunQueueProcessException("Error occured when calling the service to run the testcase. Service answer did not have the expected format (missing 'ReturnCodeDescription = '). Probably due to bad cerberus_url value. URL Called: '" + cerberusUrl + "'.");269 }270 throw new RunQueueProcessException(descriptionMatcher.group(1));271 }272 }273 @Override274 public String toString() {275 return this.cerberusExecutionUrl;276 }277 private void addIfNotNullOrEmpty(ParamRequestMaker paramRequestMaker, String key, String value, boolean encode) throws UnsupportedEncodingException {278 if (!StringUtil.isNullOrEmpty(value)) {279 paramRequestMaker.addParam(key, encode ? URLEncoder.encode(value, "UTF-8") : value);280 }281 }282}...
addParam
Using AI Code Generation
1org.cerberus.util.ParamRequestMaker prm = new org.cerberus.util.ParamRequestMaker();2prm.addParam("param1", "value1");3prm.addParam("param2", "value2");4prm.addParam("param3", "value3");5org.cerberus.util.ParamRequestMaker prm = new org.cerberus.util.ParamRequestMaker();6prm.addParam("param1", "value1");7prm.addParam("param2", "value2");8prm.addParam("param3", "value3");9org.cerberus.util.ParamRequestMaker prm = new org.cerberus.util.ParamRequestMaker();10prm.addParam("param1", "value1");11prm.addParam("param2", "value2");12prm.addParam("param3", "value3");13org.cerberus.util.ParamRequestMaker prm = new org.cerberus.util.ParamRequestMaker();14prm.addParam("param1", "value1");15prm.addParam("param2", "value2");16prm.addParam("param3", "value3");17org.cerberus.util.ParamRequestMaker prm = new org.cerberus.util.ParamRequestMaker();18prm.addParam("param1", "value1");19prm.addParam("param2", "value2");20prm.addParam("param3", "value3");21org.cerberus.util.ParamRequestMaker prm = new org.cerberus.util.ParamRequestMaker();22prm.addParam("param1", "value1");23prm.addParam("param2", "value2");24prm.addParam("param3", "value3");25org.cerberus.util.ParamRequestMaker prm = new org.cerberus.util.ParamRequestMaker();26prm.addParam("param1", "value1");27prm.addParam("param2", "value2");28prm.addParam("param3", "value3
addParam
Using AI Code Generation
1import org.cerberus.util.ParamRequestMaker2import org.cerberus.util.HttpRequest3import org.cerberus.util.HttpResponse4def paramRequestMaker = new ParamRequestMaker(url)5def httpRequest = new HttpRequest()6paramRequestMaker.addParam("test", "TEST")7paramRequestMaker.addParam("testcase", "TESTCASE")8paramRequestMaker.addParam("system", "SYSTEM")9def response = httpRequest.executeGet(paramRequestMaker.buildUrl())10def httpResponse = new HttpResponse(response)11log.info(httpResponse.getBody())12{13 "contentTable": {14 {
addParam
Using AI Code Generation
1import org.cerberus.util.ParamRequestMaker2import org.cerberus.util.HttpRequestMaker3import org.cerberus.util.HttpRequestMaker.Method4def params = new ParamRequestMaker()5params.addParam("param1", "value1")6params.addParam("param2", "value2")7request.setMethod(Method.POST)8request.setParams(params)9def response = request.execute()10import org.cerberus.util.ParamRequestMaker11import org.cerberus.util.HttpRequestMaker12import org.cerberus.util.HttpRequestMaker.Method13def params = new ParamRequestMaker()14params.addParam("param1", "value1")15params.addParam("param2", "value2")16request.setMethod(Method.POST)17request.addParam(params)18def response = request.execute()19import org.cerberus.util.HttpRequestMaker20import org.cerberus.util.HttpRequestMaker.Method21request.setMethod(Method.POST)22request.addParam("param1", "value1")23request.addParam("param2", "value2")24def response = request.execute()25import org.cerberus.util.HttpRequestMaker26import org.cerberus.util.HttpRequestMaker.Method27request.setMethod(Method.POST)28request.addParam(["param1":"value1", "param2":"value2"])29def response = request.execute()30import org.cerberus.util.HttpRequestMaker31import org.cerberus.util.HttpRequestMaker.Method32request.setMethod(Method.POST)33request.addParam(["param1":"value1", "param2":"value2"])
addParam
Using AI Code Generation
1import org.cerberus.util.ParamRequestMaker;2ParamRequestMaker prm = new ParamRequestMaker();3prm.addParam("name", "value", "type");4prm.addParam("name1", "value1", "type1");5prm.addParam("name2", "value2", "type2");6prm.addParam("name3", "value3", "type3");7prm.addParam("name4", "value4", "type4");8prm.addParam("name5", "value5", "type5");9prm.addParam("name6", "value6", "type6");10prm.addParam("name7", "value7", "type7");11prm.addParam("name8", "value8", "type8");12prm.addParam("name9", "value9", "type9");13prm.addParam("name10", "value10", "type10");14prm.addParam("name11", "value11", "type11");15prm.addParam("name12", "value12", "type12");16prm.addParam("name13", "value13", "type13");17prm.addParam("name14
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!