Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
amitbhoraniya opened this issue Jan 4, 2017 · 2 comments

Comments

@amitbhoraniya
Copy link
Collaborator

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'
NightFox7 added a commit to NightFox7/qaf that referenced this issue Jun 14, 2018
Locator description should be displayed in report instead of key (qaf-tm#65)

based on (qaf-tm#68)
@nikhilpuniyani27
Copy link

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
Copy link
Collaborator Author

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;
	}

}
  1. Register TestStepListener using below property.
qaf.listeners=com.infostretch.steps.StepListener

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants