Function does not appears in the library list

Ask general questions here.
User avatar
felixk91
Posts: 34
Joined: Wed Feb 10, 2016 11:16 pm

Function does not appears in the library list

Post by felixk91 » Wed Apr 13, 2022 3:41 am

Hi everyone,

I got two functions:

Code: Select all

        /// <summary>
        /// Function to start PopupWatcher for Load Area Values dialog and perform values setup
        /// Parameters:
        /// findElement = repository representstion of a dialog to look after
        /// callBackFunction = function that performs required steps for a dilog
        /// </summary>
        [UserCodeMethod]
        public static PopupWatcher StartDialogPopupWatcher(RepoItemInfo findElement, PopupItemCallback callBackFunktion)
        {
        	
            CheckArgumentNotNull(findElement, "findElement");
 
            var key = findElement.GetMetaInfos()["id"];

            if (watchers.ContainsKey(key))
            {
                throw new ArgumentException("Popup watcher with given parameters already exists.");
            }

            var watcher = new PopupWatcher();
            watcher.Watch(findElement, callBackFunktion);
            watcher.Start();
            watchers.Add(key, watcher);
            Report.Info("Popup watcher started.");
            return watcher;        	
        }

        /// <summary>
        /// Function to stop PopupWatcher for a dialog
        /// Parameters:
        /// findElement = repository representstion of a dialog to look after
        /// </summary>
        [UserCodeMethod]

        public static void StopDialogPopupWatcher(RepoItemInfo findElement)
        {
            CheckArgumentNotNull(findElement, "findElement");

            var key = findElement.GetMetaInfos()["id"];
            PopupWatcher watcher = null;
            if (watchers.TryGetValue(key, out watcher))
            {
	            watcher.Clear();
	            watcher.Stop();
	            Report.Info("Popup watcher stopped.");
	            watchers.Remove(key);
            }
            else
            {
                Report.Warn("The popup watcher you tried to remove does not exist.");
            }
        }
When I try to select a function from the library, I can see only one function which is StopDialogPopupWatcher.
What is wrong with the second function StartDialogPopupWatcher?
Why I can't see it in the list?

Thank you,
Felix.

User avatar
doke
Posts: 112
Joined: Fri Mar 29, 2019 2:33 pm

Re: Function does not appears in the library list

Post by doke » Wed Apr 13, 2022 7:15 am

Hi Felix,
Is this code part of a usercodecollection ?

Regards,
Don

User avatar
felixk91
Posts: 34
Joined: Wed Feb 10, 2016 11:16 pm

Re: Function does not appears in the library list

Post by felixk91 » Thu Apr 14, 2022 1:32 am

Hi doke,

This code is part of the user code of the module.
Here is the full code collection:

Code: Select all

///////////////////////////////////////////////////////////////////////////////
//
// This file was automatically generated by RANOREX.
// Your custom recording code should go in this file.
// The designer will only add methods to this file, so your custom code won't be overwritten.
// http://www.ranorex.com
//
///////////////////////////////////////////////////////////////////////////////

using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Drawing;
using System.Threading;
using WinForms = System.Windows.Forms;
using System.Diagnostics;

using Ranorex;
using Ranorex.Core;
using Ranorex.Core.Repository;
using Ranorex.Core.Reporting;
using Ranorex.Core.Testing;
using Ranorex.AutomationHelpers.UserCodeCollections;
using PrydaBuildTests.CommonUserCode;

namespace PrydaBuildTests.ScriptTestingRun
{
    public partial class ScriptTestingRun
    {
        /// <summary>
        /// This method gets called right after the recording has been started.
        /// It can be used to execute recording specific initialization code.
        /// </summary>
        private void Init()
        {
            // Your recording specific initialization code goes here.
        }
        
        private static readonly Dictionary<string, PopupWatcher> watchers = new Dictionary<string, PopupWatcher>();

        public static IList<PopupWatcher> Watchers { get { return new List<PopupWatcher>(watchers.Values); } }

        /// <summary>
        /// Function to start PopupWatcher for Load Area Values dialog and perform values setup
        /// Parameters:
        /// findElement = repository representstion of a dialog to look after
        /// callBackFunction = function that performs required steps for a dilog
        /// </summary>
        [UserCodeMethod]
        public static PopupWatcher StartDialogPopupWatcher(RepoItemInfo findElement, PopupItemCallback callBackFunktion)
        {
        	
            CheckArgumentNotNull(findElement, "findElement");
 
            var key = findElement.GetMetaInfos()["id"];

            if (watchers.ContainsKey(key))
            {
                throw new ArgumentException("Popup watcher with given parameters already exists.");
            }

            var watcher = new PopupWatcher();
            watcher.Watch(findElement, callBackFunktion);
            watcher.Start();
            watchers.Add(key, watcher);
            Report.Info("Popup watcher started.");
            return watcher;        	
        }

        /// <summary>
        /// Function to stop PopupWatcher for a dialog
        /// Parameters:
        /// findElement = repository representstion of a dialog to look after
        /// </summary>
        [UserCodeMethod]

        public static void StopDialogPopupWatcher(RepoItemInfo findElement)
        {
            CheckArgumentNotNull(findElement, "findElement");

            var key = findElement.GetMetaInfos()["id"];
            PopupWatcher watcher = null;
            if (watchers.TryGetValue(key, out watcher))
            {
	            watcher.Clear();
	            watcher.Stop();
	            Report.Info("Popup watcher stopped.");
	            watchers.Remove(key);
            }
            else
            {
                Report.Warn("The popup watcher you tried to remove does not exist.");
            }
        }


        /// <summary>
        /// Function to start Script testing process
        /// Parameters:
        /// args = nullable list of arguments for script testing command line 
        /// </summary>
        public static void StartScriptTesting(string args = null)
        {
        	var command = "C:\\Program Files (x86)\\Pryda\\Pryda Build\\5.1\\ScriptRunner.exe";
        	
        	if (args == null)
        	{
        		args = string.Empty;
        	}

    		var proc = new Process
			{
    			StartInfo = new ProcessStartInfo
   				 {
        			FileName = command,
        			Arguments = args,
        			UseShellExecute = false,
        			RedirectStandardOutput = true,
        			CreateNoWindow = true,
        			WorkingDirectory = @"C:\Program Files (x86)\Pryda\Pryda Build\5.1\"
    			}
			};

			proc.Start();
        }
        
        /// <summary>
        /// Function waiting for a process to finish
        /// Parameters:
        /// processName = process name, file name without extension 
        /// </summary>
        public static void WaitForProcessToEnd (string processName)
        {
        	while (true)
        	{
	        	Process[] processes = Process.GetProcessesByName(processName);
	        	if (processes.Length == 0)
	        		break;
	        	Thread.Sleep(1000);
        	}
        }

        public static void LoadAreaValuesSetup(RepoItemInfo info, string args = null)
        {
        	Report.Log(ReportLevel.Info, "Validation", "Validating Exists on item 'info'.", info);
        	if (!info.Exists())
        	{
        		Report.Log(ReportLevel.Failure, string.Format("Dialog {0} not exist", info.Name));
        		return;
        	}
        	
        	if (repo.LoadAreaValuesDialog.DescriptionDropdownList.Self.Enabled)
        	{
        		CommonFunctions.SelectItemInDropdownList(repo.LoadAreaValuesDialog.DescriptionDropdownList.SelfInfo, "Concrete tiles - heavy");
        	}
        	
        	if (repo.LoadAreaValuesDialog.FixingMethodDropdownList.Self.Enabled)
        	{
        		CommonFunctions.SelectItemInDropdownList(repo.LoadAreaValuesDialog.FixingMethodDropdownList.SelfInfo, "Battens");
        	}
        	
        	if (repo.LoadAreaValuesDialog.WeightTextbox.Enabled)
        	{
        		CommonFunctions.SetTextBoxValue(repo.LoadAreaValuesDialog.WeightTextboxInfo, "54.0");
        	}
        	
        	if (repo.LoadAreaValuesDialog.RestraintSpacingTextbox.Enabled)
        	{
        		CommonFunctions.SetTextBoxValue(repo.LoadAreaValuesDialog.RestraintSpacingTextboxInfo, "450");
        	}
        	
        	repo.LoadAreaValuesDialog.ButtonOK.Click();
        }

        private static void CheckArgumentNotNull(object argument, string argumentName)
        {
            if (argument == null)
            {
                throw new ArgumentNullException(argumentName);
            }
        }

     }
}
Thank you,
Felix.

csaszi89
Posts: 42
Joined: Mon Jan 17, 2022 12:10 pm

Re: Function does not appears in the library list

Post by csaszi89 » Mon Apr 25, 2022 8:46 am

Hi Felix,
try having

Code: Select all

[UserCodeCollection]
attribute on the class.
I am not sure whether it solves your problem, but give it a try.
Greetings,
Gyuri