Extracts text from (X)HTML response using XPath query language
Example XPath queries:
Method from org.apache.jmeter.extractor.XPathExtractor Detail: |
public Object clone() {
XPathExtractor cloned = (XPathExtractor) super.clone();
return cloned;
}
|
public String getDefaultValue() {
return getPropertyAsString(DEFAULT);
}
|
public String getRefName() {
return getPropertyAsString(REFNAME);
}
|
public String getXPathQuery() {
return getPropertyAsString(XPATH_QUERY);
}
|
public boolean isQuiet() {
return getPropertyAsBoolean(QUIET, true);
}
|
public boolean isTolerant() {
return getPropertyAsBoolean(TOLERANT);
}
|
public void process() {
JMeterContext context = getThreadContext();
JMeterVariables vars = context.getVariables();
String refName = getRefName();
vars.put(refName, getDefaultValue());
vars.put(concat(refName,MATCH_NR), "0"); // In case parse fails // $NON-NLS-1$
vars.remove(concat(refName,"1")); // In case parse fails // $NON-NLS-1$
final SampleResult previousResult = context.getPreviousResult();
try{
Document d = parseResponse(previousResult);
getValuesForXPath(d,getXPathQuery(),vars, refName);
}catch(IOException e){// Should not happen
final String errorMessage = "error on ("+getXPathQuery()+")";
log.error(errorMessage,e);
throw new JMeterError(errorMessage,e);
} catch (ParserConfigurationException e) {// Should not happen
final String errrorMessage = "error on ("+getXPathQuery()+")";
log.error(errrorMessage,e);
throw new JMeterError(errrorMessage,e);
} catch (SAXException e) {// Can happen for bad input document
log.warn("error on ("+getXPathQuery()+")"+e.getLocalizedMessage());
} catch (TransformerException e) {// Can happen for incorrect XPath expression
log.warn("error on ("+getXPathQuery()+")"+e.getLocalizedMessage());
} catch (TidyException e) {
AssertionResult ass = new AssertionResult("TidyException"); // $NON-NLS-1$
ass.setFailure(true);
ass.setFailureMessage(e.getMessage());
previousResult.addAssertionResult(ass);
previousResult.setSuccessful(false);
}
}
Do the job - extract value from (X)HTML response using XPath Query.
Return value as variable defined by REFNAME. Returns DEFAULT value
if not found. |
public boolean reportErrors() {
return getPropertyAsBoolean(REPORT_ERRORS, false);
}
|
public void setDefaultValue(String val) {
setProperty(DEFAULT, val);
}
|
public void setNameSpace(boolean val) {
setProperty(new BooleanProperty(NAMESPACE, val));
}
|
public void setQuiet(boolean val) {
setProperty(QUIET, val, true);
}
|
public void setRefName(String refName) {
setProperty(REFNAME, refName);
}
|
public void setReportErrors(boolean val) {
setProperty(REPORT_ERRORS, val, false);
}
|
public void setShowWarnings(boolean val) {
setProperty(SHOW_WARNINGS, val, false);
}
|
public void setTolerant(boolean val) {
setProperty(new BooleanProperty(TOLERANT, val));
}
|
public void setXPathQuery(String val) {
setProperty(XPATH_QUERY,val);
}
|
public boolean showWarnings() {
return getPropertyAsBoolean(SHOW_WARNINGS, false);
}
|
public boolean useNameSpace() {
return getPropertyAsBoolean(NAMESPACE);
}
|