How to get name of element from repository

Best practices, code snippets for common functionality, examples, and guidelines.
IvanT
Posts: 51
Joined: Wed Feb 06, 2019 8:00 pm

How to get name of element from repository

Post by IvanT » Thu Feb 13, 2020 8:12 pm

I have element in repository with name ButtonOk (this name i gave) how can i get this name from user code?

User avatar
N612
Posts: 135
Joined: Mon Jul 11, 2016 4:01 pm

Re: How to get name of element from repository

Post by N612 » Thu Feb 13, 2020 10:14 pm

The easiest way: drag and drop the repository element into your code method. Ranorex will automatically create a repository object (if needed), and a variable to that specific element.

Otherwise, you can do it manually. Example below:

Code: Select all

var repo = SampleSolutionRepository.Instance;
var okButton = repo.PopupWindow.OkButton;

IvanT
Posts: 51
Joined: Wed Feb 06, 2019 8:00 pm

Re: How to get name of element from repository

Post by IvanT » Fri Feb 14, 2020 10:29 pm

no.
i have method:
private void Example(Ranorex.Text Element, expectedValue){
if(Element.getattributevalue<string>("text").equals(expectedValue)){
report.success(here i want to take name of element in repository, not his parameter "name" )

User avatar
N612
Posts: 135
Joined: Mon Jul 11, 2016 4:01 pm

Re: How to get name of element from repository

Post by N612 » Sat Feb 15, 2020 1:05 am

Ah, I see. The name is available on the repository items "Info" object. This means you will need to ask for a RepoItemInfo instead of a Ranorex.Text. If calling this from code, you can get the info object by adding "Info" to the end of the repository item name (example below). If calling from a recording module, Ranorex will automatically pass the repository info object to the method.

Code: Select all

private void Init()
{
	var repo = SampleSolutionRepository.Instance;
	var okButton = repo.MyForm.OkButtonInfo;
	myMethod(okButton);
}

public void myMethod(RepoItemInfo buttonInfo)
{
	Report.Success(buttonInfo.Name);
}