qmetry / qaf

Quality Automation Framework for web, mobileweb, mobile native and rest web-service using Selenium, webdrier, TestNG and Java Jersey
https://qmetry.github.io/qaf
MIT License
254 stars 138 forks source link

QAF Report should display description for locator instead of locator key #65

Open amitbhoraniya opened 7 years ago

amitbhoraniya commented 7 years ago

For locator arguments in BDD scenario currently it display locator key in report, it should display locator description for more readability. Currently its like

click on 'btn.search.loc'

If user has provided description for this key then it should be like

click on 'Search Button'
nikhilpuniyani27 commented 4 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?

amitbhoraniya commented 4 years ago

Hi Nikhil,

Below code snippet is a quick workaround for it.

  1. Create a TestStepListener
    
    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