I am running Ranorex version: 9.1.2+git.afa46adf
and .NET Runtime version: 4.0.30319.42000
(upgrading to 9.2 is not an option at this moment in time).
In summary
I would like to use the Validate.NotExisits method on a RepoItemInfo object that relates to a web element that does not exist and is saved as a RepoItemInfo variable in c# code without throwing "no element found" error when creating the repoItemInfo variable. I have attached a compressed folder containing the files "WebflowIndexFormFieldFunctions.cs" and "IndexField.cs".
Where:
WebflowIndexFormFieldFunctions.cs contains the c# method run by the CodeModule IndexField.
IndexField.cs is the code module used in the test suite.
My code flow
- My code module IndexField takes a string parameter and changes a repository variable (file: IndexField.cs)
private static R4ItemRepository r4Repo; /// <summary> /// Constructs a new instance. /// </summary> public IndexField() { r4Repo = new R4ItemRepository(); } [TestVariable("2a058703-65c5-4cb4-9ebf-d9f1705c1ca8")] public string fieldToIndex { get { return r4Repo.HeaderIndexName; } set { r4Repo.HeaderIndexName = value; } }
- It passes the reference to the static repository (and other string variables) to my IndexFields function (file: IndexField.cs)
WebflowIndexFormFieldFunctions webflowFunctions = new WebflowIndexFormFieldFunctions(); void ITestModule.Run() { Mouse.DefaultMoveTime = 300; Keyboard.DefaultKeyPressTime = 100; Delay.SpeedFactor = 1.0; webflowFunctions.IndexFields(r4Repo, headerIndexingValue, disabled, mandatory, readOnly, specialFeature); }
- The IndexFields function creates a repoItemInfo and repoItem variable that reference the repository item to validate. (File: WebflowIndexFieldFormFuncitons.cs)
public void IndexFields(R4ItemRepository r4Repo, string indexValue, string disabled, string mandatory, string readOnly, string specialFeature) { bool disabledBool = Convert.ToBoolean(disabled); if (disabledBool) { } string headerName = r4Repo.HeaderIndexName; Report.Info("Creating variables"); string repoItemName = r4Repo.DocumationWorkflow.IndexingPanel.HeaderIndexScreen.HeaderField.Name; Report.Info("Created Repo item name"); RepoItemInfo repoItemInfo = r4Repo.DocumationWorkflow.IndexingPanel.HeaderIndexScreen.HeaderFieldInfo; Report.Info("Created Repo item info"); InputTag repoItem = r4Repo.DocumationWorkflow.IndexingPanel.HeaderIndexScreen.HeaderField; Report.Info("Created Repo item"); . . .
- Later in the IndexFields method the ValidateFieldDisabled method is called that validates if the web element exists if it should and validates it doesn't exist when it shouldn't. (File: WebflowIndexFieldFormFuncitons.cs)
public bool ValidateFieldDisabled(RepoItemInfo repoItemInfo, string disabled) { bool disabledBool = Convert.ToBoolean(disabled); if (disabledBool) { Report.Info("Expected field to be disabled. Checking the field does not exist."); Validate.NotExists(repoItemInfo); return true; } else { Report.Info($"Expected field to be enabled. Checking field exists."); Validate.Exists(repoItemInfo); return false; } }
When either of the lines are executed
RepoItemInfo repoItemInfo = r4Repo.DocumationWorkflow.IndexingPanel.HeaderIndexScreen.HeaderFieldInfo; InputTag repoItem = r4Repo.DocumationWorkflow.IndexingPanel.HeaderIndexScreen.HeaderField;the attached error is thrown.
Expected
I expected the variables to be initialised as when the HeaderField repository item exists the code is executed without error.
Also, when I create a recording module and use the validate action on the HeaderField repo item it works and validates successfully when the repoitem references a web element that doesn't exist.
I could implement this into my test but I would much prefer to perform the validation in the IndexFields method called in IndexField.cs as this would be easier to maintain and would keep the test suite looking neat and easy to read. It would also keep all the relevant actions in one place making it easier to reuse the steps in other test cases.
Thanks in advance