Open amitbhoraniya opened 7 years ago
Hi, In qmetry report it is showing locator key instead of descriptions of the locator. I am using BDD2 and CommonStep.sendkeys("","")
Could you please let me know if there is any workaround of this?
Hi Nikhil,
Below code snippet is a quick workaround for it.
package com.infostretch.steps;
import static com.qmetry.qaf.automation.core.ConfigurationManager.getBundle;
import java.util.Map;
import com.google.gson.Gson; import com.qmetry.qaf.automation.step.QAFTestStepAdapter; import com.qmetry.qaf.automation.step.StepExecutionTracker; import com.qmetry.qaf.automation.step.TestStep; import com.qmetry.qaf.automation.step.client.text.BDDDefinitionHelper.ParamType; import com.qmetry.qaf.automation.util.StringUtil;
public class StepListener extends QAFTestStepAdapter {
@Override
public void afterExecute(StepExecutionTracker stepExecutionTracker) {
stepExecutionTracker.getStep().setDescription(processArgs(stepExecutionTracker.getStep()));
}
private String processArgs(TestStep step) {
Object[] actualArgs = step.getActualArgs();
String description = step.getDescription();
if (null == actualArgs || actualArgs.length <= 0)
return description;
for (int i = 0; i < actualArgs.length; i++) {
if ((actualArgs[i] instanceof String)) {
description = StringUtil.replace(description, String.valueOf(actualArgs[i]),
getParam((String) actualArgs[i]), 1);
}
}
return description;
}
private String getParam(String text) {
String result = getBundle().getSubstitutor().replace(text);
String value = String.valueOf(getBundle().getObject(result));
ParamType ptype = ParamType.getType(value);
if (ptype.equals(ParamType.MAP)) {
Map<String, Object> kv = new Gson().fromJson(value, Map.class);
if (kv.containsKey("desc")) {
value = String.valueOf(kv.get("desc"));
} else if (kv.containsKey("description")) {
value = String.valueOf(kv.get("description"));
}
return value;
}
return result;
}
}
2. Register TestStepListener using below property.
```properties
qaf.listeners=com.infostretch.steps.StepListener
For locator arguments in BDD scenario currently it display locator key in report, it should display locator description for more readability. Currently its like
If user has provided description for this key then it should be like