Run a class from within another Class

Class library usage, coding and language questions.
alina
Posts: 10
Joined: Wed Oct 15, 2014 5:03 pm

Run a class from within another Class

Post by alina » Tue Nov 04, 2014 11:46 am

Hi I am trying to Call or Run a Class from within another Class.

i.e.

Class A
{
Code...
then call Class B
}

Class B
{
Some code
}

Have tried the Run and Call operators but nothing works, does anyone know how this is done?

thanks,

Alina

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 3930
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Run a class from within another Class

Post by odklizec » Tue Nov 04, 2014 1:40 pm

Hi,

I guess you want to call class B methods in class A, right? What you are looking for is called "inheritance". The code should look like this:

Code: Select all

Class A : B
{
     MethodB();
}

Class B
{
public MethodB()
     {
          ...
     }
}
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

alina
Posts: 10
Joined: Wed Oct 15, 2014 5:03 pm

Re: Run a class from within another Class

Post by alina » Wed Nov 05, 2014 11:08 am

Thanks Kurtz,

I supose i will need to create a method in Classs B, as it does not have one.
Hey, do you know how i can write some C# code tha would calculate a date and enter it ina date field.
I need to enter a week from today for e.g. but i d o not want to hard-code it as if i do that the test will fail wehn un in 6 months time for eg.

so each time the test it run, the date is entered as a week from today.
Could you shed any light on this?

THnaks,

Alina

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 3930
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Run a class from within another Class

Post by odklizec » Wed Nov 05, 2014 1:47 pm

Hi,

Here is the code to get the actual date+7 days and convert it to string:
strDate = System.DateTime.Now.AddDays(7).ToString("dd.MM.yy");
Create a new module variable in your recording (e.g. strDate).
Add a code action with the above code to your recording (before the place where you want to insert the obtained date to the date field).
Then use SetValue >> Text action with assigned $strDate value and assigned date field repo item.
Here is how your recording should look like...
strDate.png
strDate.png (24.19 KiB) Viewed 981 times
Of course, all this could be done without using the recording module (if you prefer this way).
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration