Question

Is it possible to configure Ranorex to use the same user code to identify buttons in an application (instead of renaming them for each test) and also to have a set of user defined code for any new tests. I.e. a common user code base for all tests?

Was it helpful?

Solution

Yes it is possible and very handy. What you do is have a code module library that inherits from ITestModule, e.g.

public class GenericActionsLibrary : ITestModule

and then in the user code section of the recording module have the class inherit from your library.

public class TestLoginScreen : GenericActionsLibrary

In the recording module, each time you add a user code action, the drop-down list is filled with methods from both the user code module and the GenericActionsLibrary.

Your GenericActionsLibrary will need its own static reference to the repository.

OTHER TIPS

Here is how I did it. I'm using Visual Basic (VB) and not C# CS in Ranorex.

In Ranorex

  • "Add Code Module" MainLibrary
  • "Add Code Module" StartBrowser

Comment out three code blocks in the code module MainLibrary:

The first is

'Implements ITestModule

The second is

        ''' <summary>
        ''' Constructs a new instance.
        ''' </summary>
'        Public Sub New()
'            ' Do not delete - a parameterless constructor is required!
'        End Sub

The third location is

        ''' <summary>
        ''' Performs the playback of actions in this module.
        ''' </summary>
        ''' <remarks>You should not call this method directly, instead pass the module
        ''' instance to the <see cref="TestModuleRunner.Run(Of ITestModule)"/> method
        ''' that will in turn invoke this method.</remarks>
'        Sub Run() Implements ITestModule.Run
'            Mouse.DefaultMoveTime = 300
'            Keyboard.DefaultKeyPressTime = 100
'            Delay.SpeedFactor = 1.0
'        End Sub

Add Sub(s) for the action(s) you want to call from the other code module(s)

Public Sub OpenBrowser
    Host.Local.OpenBrowser("http://www.ranorex.com", "IE", "", False, False)
End Sub

In the code module, you are calling the method that's in MainLibrary. Add the Inherits statement before the Implements statement, then call the method from the MainLibrary in the ITestModule.Run code block:

   Public Class StartBrowser
        Inherits MainLibrary
        Implements ITestModule

        ''' <summary>
        ''' Constructs a new instance.
        ''' </summary>
        Public Sub New()
            ' Do not delete - a parameterless constructor is required!
        End Sub

        ''' <summary>
        ''' Performs the playback of actions in this module.
        ''' </summary>
        ''' <remarks>You should not call this method directly, instead pass the module
        ''' instance to the <see cref="TestModuleRunner.Run(Of ITestModule)"/> method
        ''' that will in turn invoke this method.</remarks>
        Sub StartBrowser_Run() Implements ITestModule.Run
            Mouse.DefaultMoveTime = 300
            Keyboard.DefaultKeyPressTime = 100
            Delay.SpeedFactor = 1.0

            'Call the public method from MainLibrary Class.
            OpenBrowser()
        End Sub

    End Class

On Ranorex's Website, it shows about creating library's that comes in handy when reusing for different projects.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top