Example #1
0
        /// <summary>
        /// This function parses the if flow and starts executing. Used in both Test Set and Test Case.
        /// </summary>
        /// <param name="ifXMLNode"> XML Node that has the if block. </param>
        /// <param name="performAction"> Perfoms the action. </param>
        private void RunThenElseLayer(XmlNode ifXMLNode, bool performAction = true)
        {
            bool ifCondition = false;

            // we check condition if we have to perfom this action.
            if (performAction)
            {
                string elementXPath = this.ReplaceIfToken(ifXMLNode.Attributes["elementXPath"].Value, this.XMLDataFile);
                string condition    = ifXMLNode.Attributes["condition"].Value;

                ITestingDriver.ElementState state = condition == "EXIST" ? ITestingDriver.ElementState.Visible : ITestingDriver.ElementState.Invisible;

                ifCondition = InformationObject.TestAutomationDriver.CheckForElementState(elementXPath, state);
            }

            // inside the testCaseFlow, you can only have either RunTestCase element or an If element.
            foreach (XmlNode ifSection in ifXMLNode.ChildNodes)
            {
                switch (ifSection.Name)
                {
                case "Then":
                    // we run this test case only if performAction is true, and the condition for the element has passed.
                    this.AddNodesToStack(ifSection, performAction && ifCondition);
                    break;

                case "ElseIf":
                    // we check the condition if performAction is true and the previous if condition was false.
                    // we can only run the test case if performAction is true, previous if condition was false, and the current if condition is true.
                    bool secondIfCondition = false;

                    if (performAction && !ifCondition)
                    {
                        string elementXPath = this.ReplaceIfToken(ifXMLNode.Attributes["elementXPath"].Value, this.XMLDataFile);
                        string condition    = ifSection.Attributes["condition"].Value;

                        ITestingDriver.ElementState state = condition == "EXIST" ? ITestingDriver.ElementState.Visible : ITestingDriver.ElementState.Invisible;

                        secondIfCondition = InformationObject.TestAutomationDriver.CheckForElementState(elementXPath, state);
                    }

                    this.AddNodesToStack(ifSection, performAction && !ifCondition && secondIfCondition);

                    // update ifCondition to reflect if elseIf was run
                    ifCondition = !ifCondition && secondIfCondition;
                    break;

                case "Else":
                    // at this point, we only run this action if performAction is true and the previous ifCondition was false.
                    this.AddNodesToStack(ifSection, performAction && !ifCondition);
                    break;

                default:
                    Logger.Warn($"We currently do not deal with this. {ifSection.Name}");
                    break;
                }
            }
        }
        /// <inheritdoc/>
        public override void Execute()
        {
            base.Execute();
            string xPath     = this.Arguments["object"];
            bool   invisible = bool.Parse(this.Arguments["value"]);

            ITestingDriver.ElementState state = invisible ? ITestingDriver.ElementState.Invisible : ITestingDriver.ElementState.Visible;

            InformationObject.TestAutomationDriver.WaitForElementState(xPath, state);
        }