Page 1 of 1

Run a class from within another Class

Posted: Tue Nov 04, 2014 11:46 am
by alina
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

Re: Run a class from within another Class

Posted: Tue Nov 04, 2014 1:40 pm
by odklizec
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()
     {
          ...
     }
}

Re: Run a class from within another Class

Posted: Wed Nov 05, 2014 11:08 am
by alina
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

Re: Run a class from within another Class

Posted: Wed Nov 05, 2014 1:47 pm
by odklizec
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
Of course, all this could be done without using the recording module (if you prefer this way).