@Override public List<Element> getElement(final LoadRunnerVUVisitor visitor, final MethodCall method, final MethodcallContext ctx) { Preconditions.checkNotNull(method); Preconditions.checkNotNull(method.getParameters(), method.getName() + " method must have a parameter"); Preconditions.checkArgument(!method.getParameters().isEmpty(), method.getName() + " method must have a parameter"); final String delayInS = method.getParameters().get(0); final String delayInMs = parseDelay(visitor, method, ctx, delayInS); return ImmutableList.of(ImmutableDelay.builder().name("delay").delay(delayInMs).isThinkTime(true).build()); }
@Override public List<Element> getElement(final LoadRunnerVUVisitor visitor, final MethodCall method, final CPP14Parser.MethodcallContext ctx) { return ImmutableList.of(containers.get(method.getName())); } }
public static Optional<String> getParameterStartingWith(MethodCall method, String name) { return method.getParameters().stream().filter(s -> s.toLowerCase().startsWith(name.toLowerCase()) || s.toLowerCase().startsWith("\"" + name.toLowerCase())).findFirst(); }
public static String getValueAndVerifyRestrictionForBoundary(final String leftBrace, final String rightBrace, MethodCall method, Optional<String> boundaryString) { String unquotedString = MethodUtils.normalizeString(leftBrace, rightBrace, boundaryString.orElseThrow(IllegalArgumentException::new)); String lbOptions = unquotedString.split("=")[0]; Arrays.asList(lbOptions.split("/")).stream().filter(MethodUtils::isRestrictedBoundary).forEach(option -> logger.error("the option \"" + option + "\" can not be taken into account for the LR function : " + method.getName()) ); return unquotedString.substring(lbOptions.length()+1); } }
private static ImmutableCustomAction createClientNum(final MethodCall method) { return createSetTextCustomAction( "clientnum", "${SAP_ACTIVE_SESSION}/${SAP_ACTIVE_WINDOW}/usr/txtRSYST-MANDT", "RSYST-MANDT", GUI_TEXT_FIELD, method.getParameters().get(2), Type.TEXT ); }
@Override public List<Element> getElement(final LoadRunnerVUVisitor visitor, final MethodCall method, final MethodcallContext ctx) { Preconditions.checkNotNull(method); Preconditions.checkNotNull(method.getParameters(), method.getName() + " method must have a parameter"); if(method.getParameters().isEmpty()){ visitor.readSupportedFunctionWithWarn(method.getName(), ctx, method.getName() + " method must have a parameter"); return Collections.emptyList(); } visitor.readSupportedFunction(method.getName(), ctx); final String returnValue = MethodUtils.normalizeString(visitor.getLeftBrace(), visitor.getRightBrace(), method.getParameters().get(0)); return ImmutableList.of(ImmutableEvalString.builder().name(MethodUtils.unquote(method.getName())).returnValue(returnValue).build()); } }
private static String parseDelay(final LoadRunnerVUVisitor visitor, final MethodCall method, final MethodcallContext ctx, final String delayInS) { final Pattern pattern = Pattern.compile("[a-z-_]", Pattern.CASE_INSENSITIVE); if(pattern.matcher(delayInS).find() && !delayInS.contains("{") && !delayInS.contains("}")){ visitor.readSupportedFunction(method.getName(), ctx); return MethodUtils.getVariableSyntax(delayInS)+"000"; } try { final String delayInMs = String.valueOf(Math.round(Double.parseDouble(delayInS) * 1000)); visitor.readSupportedFunction(method.getName(), ctx); return delayInMs; } catch (final NumberFormatException nfe) { final String warning = "A think time cannot be converted in milli seconds"; visitor.readSupportedFunctionWithWarn(method.getName(), ctx, warning); return delayInS + "000"; } }
private static ImmutableCustomAction createUsername(final MethodCall method) { return createSetTextCustomAction( "username", "${SAP_ACTIVE_SESSION}/${SAP_ACTIVE_WINDOW}/usr/txtRSYST-BNAME", "RSYST-BNAME", GUI_TEXT_FIELD, method.getParameters().get(0), Type.TEXT ); }
@Override public List<Element> getElement(final LoadRunnerVUVisitor visitor, final MethodCall method, final MethodcallContext ctx) { Preconditions.checkNotNull(method); Preconditions.checkNotNull(method.getParameters(), method.getName() + " method must have a parameter"); if(method.getParameters().isEmpty()){ visitor.readSupportedFunctionWithWarn(method.getName(), ctx, method.getName() + " method must have a parameter"); return Collections.emptyList(); } visitor.readSupportedFunction(method.getName(), ctx); final String returnValue = MethodUtils.normalizeString(visitor.getLeftBrace(), visitor.getRightBrace(), method.getParameters().get(0)); return ImmutableList.of(ImmutableEvalString.builder().name(MethodUtils.unquote(method.getName())).returnValue(returnValue).build()); } }
@Override public List<Element> getElement(final LoadRunnerVUVisitor visitor, final MethodCall method, final MethodcallContext ctx) { Preconditions.checkNotNull(method); visitor.readSupportedFunction(method.getName(), ctx); return ImmutableList.of(ImmutableClearCache.builder().name(method.getName()).build()); }
private static ImmutableCustomAction createPassword(final MethodCall method) { return createSetTextCustomAction( "password", "${SAP_ACTIVE_SESSION}/${SAP_ACTIVE_WINDOW}/usr/pwdRSYST-BCODE", "RSYST-BCODE", GUI_TEXT_FIELD, method.getParameters().get(1), Type.PASSWORD ); }
@Override public List<Element> getElement(final LoadRunnerVUVisitor visitor, final MethodCall method, final MethodcallContext ctx) { Preconditions.checkNotNull(method); if(method.getParameters() == null || method.getParameters().size()!=2){ visitor.readSupportedFunctionWithWarn(method.getName(), ctx, method.getName() + " method must have 2 parameters"); return Collections.emptyList(); } visitor.readSupportedFunction(method.getName(), ctx); final String variableValue = MethodUtils.unquote(method.getParameters().get(0)); final String variableName = MethodUtils.unquote(method.getParameters().get(1)); final String name = "Set variable " + MethodUtils.normalizeName(variableName); return ImmutableList.of(ImmutableSaveString.builder().name(name).variableName(variableName).variableValue(variableValue).build()); } }
private void logUnsupportedAttributes(final MethodCall method, final WarningCallbBack warningCallback, final String leftBrace, final String rightBrace) { for (final String unsupportedAttribute : UNSUPPORTED_ATTRIBUTE) { MethodUtils.getParameterValueWithName(leftBrace, rightBrace, method, unsupportedAttribute).ifPresent(value -> logWarn( "The option \"" + unsupportedAttribute + "\" has not been taken under account for the LR function with name : " + method.getName(), warningCallback)); } } }
private static ImmutableCustomAction createLanguage(final MethodCall method) { return createSetTextCustomAction( "language", "${SAP_ACTIVE_SESSION}/${SAP_ACTIVE_WINDOW}/usr/txtRSYST-LANGU", "RSYST-LANGU", GUI_TEXT_FIELD, method.getParameters().get(3), Type.TEXT ); }
@Override public List<Element> getElement(final LoadRunnerVUVisitor visitor, final MethodCall method, final MethodcallContext ctx) { if (method == null) { return Collections.emptyList(); } if (method.getParameters() == null || method.getParameters().isEmpty()) { visitor.readSupportedFunctionWithWarn(method.getName(), ctx, method.getName() + " must have a parameter."); return Collections.emptyList(); } visitor.readSupportedFunction(method.getName(), ctx); final String firstParameter = method.getParameters().get(0); final String transactionName = MethodUtils.normalizeName(firstParameter); final ImmutableContainer.Builder currentContainer = ImmutableContainer.builder().name(transactionName); visitor.getCurrentContainers().add(currentContainer); return Collections.emptyList(); } }
@Override public List<Element> getElement(final LoadRunnerVUVisitor visitor, final MethodCall method, final MethodcallContext ctx) { Preconditions.checkNotNull(method); visitor.readSupportedFunction(method.getName(), ctx); return ImmutableList.of(ImmutableClearCookies.builder().name(method.getName()).build()); } }
public static Page toElement(final LoadRunnerVUVisitor visitor, final MethodCall method) { Preconditions.checkNotNull(method); ImmutablePage.Builder pageBuilder = ImmutablePage.builder(); final URL mainUrl = Preconditions.checkNotNull(getUrlFromMethodParameters(visitor.getLeftBrace(), visitor.getRightBrace(), method)); final Optional<Properties> snapshotProperties = getSnapshotProperties(visitor, method); final Optional<RecordedFiles> recordedFiles = getRecordedFilesFromSnapshotProperties(visitor, snapshotProperties); final List<Header> recordedHeaders = getHeadersFromRecordedFile(recordedFiles.flatMap(RecordedFiles::recordedRequestHeaderFile)); pageBuilder.addChilds(buildGetRequestFromURL(visitor, mainUrl, recordedFiles, recordedHeaders)); MethodUtils.extractItemListAsStringList(visitor, method.getParameters(), EXTRARES, Optional.of(pageBuilder)).ifPresent(stringList -> pageBuilder.addAllChilds(getUrlList(stringList, mainUrl).stream().map(url -> WebRequest.buildGetRequestFromURL(visitor, url, Optional.empty(), recordedHeaders)).collect(Collectors.toList()))); return pageBuilder.name(MethodUtils.normalizeString(visitor.getLeftBrace(), visitor.getRightBrace(), method.getParameters().get(0))) .thinkTime(0) .build(); } }
@Override public List<Element> getElement(final LoadRunnerVUVisitor visitor, final MethodCall method, final MethodcallContext ctx) { Preconditions.checkNotNull(method); if(method.getParameters() == null || method.getParameters().isEmpty()){ visitor.readSupportedFunctionWithWarn(method.getName(), ctx, method.getName() + " method must have at least 1 parameter"); return Collections.emptyList(); } visitor.readSupportedFunction(method.getName(), ctx); return ImmutableList.of(ImmutableSaveString.builder() .name(MethodUtils.unquote(method.getName())) .variableName(SAP_ACTIVE_WINDOW) .variableValue(MethodUtils.unquote(method.getParameters().get(0))) .build()); } }
/** * Find the url in the LR function and parse it to an URL Object * @param method represent the LR function * @param urlTag tag used to find the correct keywords in the function (also used for parsing) */ @VisibleForTesting protected static URL getUrlFromMethodParameters(final String leftBrace, final String rightBrace, MethodCall method, String urlTag) { Optional<String> urlParam = MethodUtils.getParameterWithName(method, urlTag); try { String urlString = MethodUtils.unquote(urlParam.orElseThrow(IllegalArgumentException::new)); //the +1 is for the "=" that follows the url tag return getUrlFromParameterString(leftBrace, rightBrace, urlString.substring(urlTag.length()+1)); }catch (IllegalArgumentException e) { LOGGER.error("Cannot find URL in WebUrl Node:"+method.getName() + "\nThe error is : " + e); } return null; }
public static Page toElement(final LoadRunnerVUVisitor visitor, final MethodCall method) { Preconditions.checkNotNull(method); ImmutablePage.Builder pageBuilder = ImmutablePage.builder(); final PostRequest postRequest = buildPostFormRequest(visitor, method); pageBuilder.addChilds(postRequest); // we use the request headers of the main request for the resources. final List<Header> recordedHeaders = getHeadersFromRecordedFile(postRequest.getRecordedFiles().flatMap(RecordedFiles::recordedRequestHeaderFile)); MethodUtils.extractItemListAsStringList(visitor,method.getParameters(), EXTRARES, Optional.of(pageBuilder)) .ifPresent(stringList -> getUrlList(stringList, getUrl(visitor.getLeftBrace(), visitor.getRightBrace(), method)) .forEach(url -> pageBuilder.addChilds(buildGetRequestFromURL(visitor, url, Optional.empty(), recordedHeaders)))); return pageBuilder.name(MethodUtils.normalizeString(visitor.getLeftBrace(), visitor.getRightBrace(), method.getParameters().get(0))) .thinkTime(0) .build(); } }