Start recording from user code

Class library usage, coding and language questions.
tbailey
Posts: 3
Joined: Fri Apr 17, 2015 5:00 pm

Start recording from user code

Post by tbailey » Fri Apr 17, 2015 5:06 pm

I have a recording "hello.rxrec" that I'm trying to run from VB code in another record.

From what I read, I only need to use "hello.Start()". However, I get an error "test is not declared. It may be inaccessible due to its protection level."

This seems like it should be pretty simple, not sure what I'm doing wrong.

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

Re: Start recording from user code

Post by krstcs » Fri Apr 17, 2015 8:27 pm

First, why are you trying to start a module from another module? Modules are designed to be run in test cases from the suite.

In this case though, you would need to declare a variable for the test module and instantiate it, then call the Start() method on the variable like this:

Code: Select all

Hello helloModule = new Hello(); //instantiate the variable (helloModule) as a type of Hello
helloModule.Start(); //call Start() on the variable
Test modules are just .NET classes. They conform to specific interfaces that Ranorex has designed, but they still need to be instantiated before you can work with them.


Second, when raising issues please include the following information:

Ranorex version
Windows version
System under test (SUT) technology (if applicable)
Any error messages (if applicable)
The code you are using (if applicable)
Shortcuts usually aren't...

tbailey
Posts: 3
Joined: Fri Apr 17, 2015 5:00 pm

Re: Start recording from user code

Post by tbailey » Mon Apr 20, 2015 3:49 pm

Thanks for the reply.

I'm testing logging into a web app. If the user is already logged in, all my tests fail, so I need to run a specific recording to log out if I detect that the web app is already logged in.

I didn't include the version information because my issue wasn't really version specific.

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

Re: Start recording from user code

Post by krstcs » Mon Apr 20, 2015 4:03 pm

Please read the following post from the Ranorex team about what information to include when raising issues on the forums: http://www.ranorex.com/forum/please-rea ... -t871.html. This information helps everyone stay on the same page when talking about what is going on.

As for your situation, you should consider creating the logout module so that it can tell if it needs to logout or not and then just include it in all tests. You can create the logout module so that it handles either path with user code. This will keep you from needing to start modules from other modules.

Basically it would look like this in your user-code:

Code: Select all

if (loggedIn) {
  Report.Info("USER", "Logged in.  Logging user out.");
  DoLogoutStuff();
} else {
  Report.Info("USER", "Not logged in.");
}
Shortcuts usually aren't...