Pass Repository item dynamically through an excel sheet

Ranorex Studio, Spy, Recorder, and Driver.
Rajendra
Posts: 32
Joined: Wed Sep 28, 2011 1:57 pm

Pass Repository item dynamically through an excel sheet

Post by Rajendra » Mon Jan 20, 2014 11:25 am

Can we pass Repository item dynamically through an excel sheet?

For example:_______

I have a repository SampleRepository.rxrep file in which

Google /dom[@domain='www.google.co.in'] is the parent folder in the repository and
googleButton .//button[@id='gbqfb']
googleInput .//input[#'gbqfq']"

are the children objects.

I use below code to click a button
public static SampleRepository repo = SampleRepository.Instance;
repo.Google.googleButton.Click();

The above syntax is working fine
_____________________________________________________________________

Now, I want to send the object name "googleButton" through an excel sheet and accordingly the button should get clickable

So that, the modified syntax should be something like this

modifiedObjName = "googleButton"; <I am not sure how/what/where to assign this object>
repo.Google.modifiedObjName.Click();

Is it really possible?

Thanks,
Rajendra

Rajendra
Posts: 32
Joined: Wed Sep 28, 2011 1:57 pm

Re: Pass Repository item dynamically through an excel sheet

Post by Rajendra » Thu Jan 23, 2014 6:14 am

No help is coming around.

Atleast can you please confirm whether it is possible through coding or not?

Thanks,
Raj

krstcs
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: Pass Repository item dynamically through an excel sheet

Post by krstcs » Thu Jan 23, 2014 2:38 pm

It is not possible to pass repository objects into modules directly. You would need to do a lot of coding behind the scenes with reflection.

There are about 10 threads on similar topics if you want to see how others approached the issue and if their solutions fit your problem.

I would suggest that you might re-look at how you are testing because passing dynamic repository objects around is more trouble than it is worth in most situations, and is not how Ranorex was designed.


I would recommend looking into passing the XPath in dynamically instead. This would allow a similar result but XPaths can be handled like strings. However, this would still mean you would need to work directly in .NET code instead of the easier standard Action Table approach of Ranorex Studio.
Shortcuts usually aren't...

Rajendra
Posts: 32
Joined: Wed Sep 28, 2011 1:57 pm

Re: Pass Repository item dynamically through an excel sheet

Post by Rajendra » Wed Jan 29, 2014 11:28 am

Thank you for the confirmation.

Currently I am sending XPath dynamically and able to handle the scenarios quite well(though a much complicated way, as u said).

The problem is I am trying to create a keyword driven framework where each action, like CLICK, ENTERTEXT etc are sent as a keyword to the class file and XPath as a test data. Using Xpath I need to initiate the action.

Hence, I raised this question to see if there is a way to send repo objects/object names dynamically.

Unfortunately no.

Thanks,
Raj

krstcs
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: Pass Repository item dynamically through an excel sheet

Post by krstcs » Wed Jan 29, 2014 3:18 pm

It could be done, but, like I said, it would require a log of coding and work with reflection.


I structure and name my modules so that they are pretty much keyword driven.

I have modules called:

Click_OKButton
Click_CancelButton
Enter_UserName
Select_State

They are named simply by what action they take and what they take that action on. My modules do ONE thing and ONE thing only. Not just one action, but one set of actions that leads to one thing being done. For example, my "Enter_UserName" has about 5 actions in it (click the field, hit "Ctrl-A", hit "Del", type the username, validate the username is in the field), but to a user, that is ONE action. Same for "Select_State". I have to click the dropdown and then select the state, 2 actions to Ranorex, but ONE thing to the user. You wouldn't (normally) just click the dropdown by itself, if you weren't going to select something from the list. (There may be specific test cases for that, but they can be done with simple scripts separately.)

The other testers in my organization can then just drag these into the test suite/test case where they want them and they are done.

There are some conventions, such as my repository objects being named the same as the action object in the module names. So for the first module, there is a repository object called "OKButton".

Inputs are handled the same way. So, for the "Enter_UserName" module, there is a repository object of type "Input", called "UserName", and I pass in a variable called "UserName" to the module. This allows all of us to know, at a glance what the module does, what it does it too, and what it does it with.

Ranorex really isn't setup to use a DSL or key-word testing like you are trying to do, without a lot of work. My way of doing it allows.
Shortcuts usually aren't...

Rajendra
Posts: 32
Joined: Wed Sep 28, 2011 1:57 pm

Re: Pass Repository item dynamically through an excel sheet

Post by Rajendra » Thu Jan 30, 2014 7:01 am

krstcs,

That's a very good explanation. I really appreciate you for your time.

The understand that developing a keyword driven framework with Ranorex is some what cumbersome task. And involves lot of coding to be done.

Unfortunately , I am very poor at using Reflection methods. :oops:

The only reflection method I am using in my framework is in DRIVERS Class where I used to call the method/function/keyword name dynamically (this method/function/keyword name is taking from the excel sheet/database dynamically)

It would be very helpful for me, if you can share a piece of code her or privately.

The exact way I am using now is as below:

//controlType is nothing but a control name here; for example, TEXTBOX is a control name

MethodInfo methodInfo = typeof (KeywordSolutionBase).GetMethod(controlType.ToUpper());
methodInfo.Invoke(KeywordSolutionlib, _Data);

//_Data consists of array of objects; like the action need to be performed on that particular control name; Eg: EnterText
//Now, the above code redirect to the KeywordBase Class

/*************************************************************/

public void TEXTBOX(int testcaseId, string testTitle, string pageName, string controlType, string keywordName, string fieldName, string property, string testData, int tcMaxLogNo)
{
string sConnect = sResultString;
try
{
Ranorex.Text textbox = property;

//PROPERTY IS NOTHING BUT XPath
//This is where I want to modify the code. In such a way that it should represents a repo item
/****************************************
Instead of,
Ranorex.Text textbox = "/some xpath here";
textbox.Click();

I want to give a repo object dynamically like
repo.Google.textboxObject.Click();

**********************************************/


switch(keywordName.ToLower())
{
case "entertext":
textbox.TextValue = testData;
break;

case "click":
textbox.Click();
break;

case "doubleclick":
textbox.DoubleClick();
break;
}
}
catch(Exception e)
{
System.DateTime dt = System.DateTime.Now;
resultValue.setFlag(false);
CaptureImage(testTitle);
Report.Failure("Failed due to exception "+e.ToString());
Report.Info("Unexpected exception at " + " " + controlType + " "+ "___And the expection is__" + e.ToString());
Report.Screenshot();
this.ReportUpdateInDB("Failed", "Failed due to Exception:" + e.Message.Replace('\'',' '), testcaseId, testTitle, tcMaxLogNo, dt,controlType, sConnect);

}
}


Any help, is appreciated!

Thanks,
Raj