Search code examples
c#testingranorextestautomationfx

How to call a running Ranorex test in a loop?


I have recorded & partly written a test for a Website, which works for a specific browser type. The user can modify a class field of the so-called EBrowserType type, which is an enum I have created. It contains all browser types that Ranorex can handle.

Now, I was asked to make a loop over the whole test, where all the browser types are called. I run into problems, as the existing test is a group of recordings, where the user clicked at some point into a text field of the opened browser of the requested browser type. This seems to be no more possible in a loop, as the code itself creates the browser & closes it after that.

In the original code, there is a SETUP part that openes the browser, and a recording that follows. enter image description here This recording is called SearchJobRegionRecording & starts with a mouse click into the search field of the browser. In the automatically created C# file, this looks as follows:

[TestModule("c7957eb6-feec-4dce-aef3-6af20fa71b8b", ModuleType.Recording, 1)]
public partial class SearchJobRegionRecording : ITestModule
{
    /// <summary>
    /// Holds an instance of the IVMJobsiteTest.IVMWebsiteTestRepository repository.
    /// </summary>
    public static IVMJobsiteTest.IVMWebsiteTestRepository repo = IVMJobsiteTest.IVMWebsiteTestRepository.Instance;
    […]

    [System.CodeDom.Compiler.GeneratedCode("Ranorex", "8.0")]
    void ITestModule.Run()
    {
        Mouse.DefaultMoveTime = 0;
        Keyboard.DefaultKeyPressTime = 0;
        Delay.SpeedFactor = 100.00;

        Init();

        Report.Log(ReportLevel.Info, "Mouse", "Mouse Left Click item 'Home.Text' at 128;8.", repo.Home.TextInfo, new RecordItemIndex(0));
        repo.Home.Text.Click("128;8");
        […]
    }
}

As you can see, a repo object is required to access the browser instance. enter image description here enter image description here My question: How can I get the browser instance in my browser-looping code? The only hint about the created browser seems to be the process ID.

Here is the respective part for the browser-looping code:

public void TestAllBrowsers()
{
    foreach (EBrowserType browser in Enum.GetValues(typeof(EBrowserType)))
    {
        foreach (Point size in sizes)
        {
            Report.Log(ReportLevel.Info, "Code", "Open with the " + browser + " browser of "
                       + size.X + '×' + size.Y + " size " + url);
                BaseCodeCollection.KillCurrentBrowser(browser);
                var height = (short) size.X;
                var width = (short) size.Y;

                int processID = BaseCodeCollection.OpenBrowser(height, width, url, browser, isVerbose);

                DetermineOriginalVacancies();

                EnterSearchWords(); // HERE, A RepoItemInfo or something like that should be passed so that a mouse click is possible.

                AnalyzeSearchResultsMethod();

                CloseBrowser();
        }
    }
}

Solution

  • I am not sure I understand the question but will try to give you as much hint as I can. I have successfully created a small test suite that basically does the following, without using any user code:

    • Iterate the list of supported browsers (IE, Chrome, etc):
      • Open Bing in a browser (StartBrowser)
      • Click search field (repo item) (ClickSearchTerm)
      • Iterate through search terms:
        • Enter text in search field (repo item) (SetSearchTerm)
        • Clear text in search field (repo item) (ClearSearchTerm)
      • Close browser instance (repo item) (CloseBrowser)

    All those steps are contained in a test case which iterates through the list of supported browser (IE and Chrome in my example but it would work with any browser that is supported by Ranorex).

    My repo items:

    Bing web document: /dom[@caption='Bing' and @page=''] (ensure spy is finding only one instance of web document or else CloseBrowser will fail)

    Bing search field (under Bing repository item): .//input[#'sb_form_q']

    The StartBrowser recording is simply an Open Browser action (with Url and Browser as arguments) followed with a 2s delay (to load page). The CloseBrowser recording is simply a Close application action with the Bing web document repo item as argument.

    Note that my example does not need the browser instance anywhere, that is why I do not exactly know if this answers your question. The only recording that requires a browser parameter is the StartBrowser recording. All other recordings are using repository items which are browser agnostic (which is one of the strength of using Ranorex).

    If my example does not help you with your issue, feel free to ask for more details.