Description of RecordedAction.
Inheritance: IRecordedActionItem
Exemplo n.º 1
0
        internal static IRecordedCodeSequence RecordCodeSequence(
            TranscriptCmdletBase cmdlet,
            List <IRecordedCodeSequence> recordingCollection,
            object resultElement,
            IRecordedCodeSequence codeSequence)
        {
            RecordedWebElement elementItem = null;
            RecordedAction     actionItem  = null;
            RecordedData       dataItem    = null;

            var resultWebElement =
                resultElement as IWebElement;
            //RecordedData resultDataCollection =
            //    resultElement as RecordedData;
            var resultDataCollection =
                resultElement as ReadOnlyCollection <object>;

            if (null == codeSequence)
            {
                codeSequence = new RecordedCodeSequence();
            }

            if (null == resultElement)
            {
                return(codeSequence);
            }
//Console.WriteLine(@"\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ resultElement.GetType().Name = " + resultElement.GetType().Name);
            if (null != resultWebElement)
            {
                if (IsNotFakeWebElement(resultWebElement))
                {
                    codeSequence =
                        RecordWebItem(cmdlet, codeSequence, resultWebElement, elementItem);
                }
                else     // if (Recorder.isNotFakeWebElement(resultWebElement)) {

                {
                    codeSequence =
                        RecordActionItem(cmdlet, codeSequence, resultWebElement, actionItem);
                } // else
            }

            if (null != resultDataCollection)
            {
                Console.WriteLine(@"////////////////////////////////////////////////////////// null != resultDataCollection " + resultDataCollection.GetType().Name);
                codeSequence =
                    RecordDataItem(cmdlet, codeSequence, resultDataCollection, dataItem);
            }

            cmdlet.WriteVerbose(cmdlet, "RecordCodeSequence");

            return(codeSequence);
        }
 private IRecordedCodeSequence generateActionItem(
     IRecordedCodeSequence codeSequence,
     IWebElement webElement,
     RecordedAction recordingItem)
 {
     IRecordedCodeSequence result =
         Recorder.RecordActionItem(
             (new TranscriptCmdletBase()),
             codeSequence,
             webElement,
             recordingItem);
     return result;
 }
Exemplo n.º 3
0
        internal static IRecordedCodeSequence RecordActionItem(
            TranscriptCmdletBase cmdlet, 
            IRecordedCodeSequence codeSequence, 
            IWebElement resultWebElement, 
            RecordedAction actionItem)
        {
            if (null == codeSequence) {
                codeSequence = new RecordedCodeSequence();
            }
            if (null == resultWebElement) {
                return codeSequence;
            }
            
            actionItem = new RecordedAction();
            string elementId = string.Empty;
            string elementName = string.Empty;
            string elementClass = string.Empty;
            string elementTagName = string.Empty;
            string elementText = string.Empty;
            
            try {
            
                switch (resultWebElement.TagName) {
                    case Recorder.constAuxElementClicked:
                        actionItem.UserData.Add("code", codeGenElementClick);
                        break;
                        
#region temporaly commented
//                            case Recorder.constAuxElementData:
//                                try { elementId = resultWebElement.GetAttribute("id"); } catch {}
//                                try { elementName = resultWebElement.GetAttribute("name"); } catch {}
//                                try { elementClass = resultWebElement.GetAttribute("class"); } catch {}
//                                try { elementTagName = resultWebElement.TagName; } catch {}
//                                try { elementText = resultWebElement.Text; } catch {}
//                                if (string.Empty != elementId && "null" != elementId) {
//                                    actionItem.UserData.Add("code", codeGenIdParameter + elementId + "'");
//                                    actionItem.UserData.Add("comment1", codeGenNameComment + elementName + "'");
//                                    actionItem.UserData.Add("comment2", codeGenClassComment + elementClass + "'");
//                                    actionItem.UserData.Add("comment3", codeGenTagParameter + elementTagName + "'");
////    Console.WriteLine("\"code\" added 2");
//                                } else if (string.Empty != elementName && "null" != elementName) {
//                                    actionItem.UserData.Add("code", codeGenNameParameter + elementName + "'");
//                                    actionItem.UserData.Add("comment1", codeGenClassComment + elementClass + "'");
//                                    actionItem.UserData.Add("comment2", codeGenTagParameter + elementTagName + "'");
////    Console.WriteLine("\"code\" added 3");
//                                } else if (string.Empty != elementClass && "null" != elementClass) {
//                                    actionItem.UserData.Add("code", codeGenClassParameter + elementClass + "'");
//                                    actionItem.UserData.Add("comment1", codeGenTagParameter + elementTagName + "'");
////    Console.WriteLine("\"code\" added 4");
//                                } else if (string.Empty != elementTagName && "null" != elementTagName) {
//                                    actionItem.UserData.Add("code", codeGenTagParameter + elementTagName + "'");
//                                }
//                                break;
//                    case Recorder.constAuxElementSelected:
//                        actionItem.UserData.Add(@"code", @" | Invoke-SeWebElementClick");
//                        break;
#endregion temporaly commented

                    case Recorder.constAuxElementTypedIn:
                        string typedInData = string.Empty;
                        if (null != (typedInData = resultWebElement.GetAttribute("text"))) {
                            
                            // ??
                            
                        } else if (null != (typedInData = resultWebElement.GetAttribute("value"))) {
                            
                            // ??
                        }
                        actionItem.UserData.Add("code", @" | Set-SeWebElementKeys '" + typedInData + "'");
                        break;
                    case Recorder.constAuxElementSelected:
                        // TBD
                        break;
                    case Recorder.constAuxElementData:
                        // nothing to do
                        break;
                }
            }
            catch (Exception eActionItem) {
Console.WriteLine("a fake item exception: " + eActionItem.Message);
            }
            
            // ??
            actionItem.Final = true;
            //
            
            if (codeSequence.ContainsDataItem()) {
                codeSequence.ReadyToProduceCode = true;
            }

            try {
                if (0 == codeSequence.Items.Count) {

                    codeSequence.Items.Add(actionItem);
                } else if (null == (codeSequence.Items[codeSequence.Items.Count - 1] as IRecordedActionItem)) {

                    codeSequence.Items.Add(actionItem);
                } else if (null != ((IRecordedActionItem)codeSequence.Items[codeSequence.Items.Count - 1]).UserData) {
                    if (actionItem.UserData["code"] !=
                        ((IRecordedActionItem)codeSequence.Items[codeSequence.Items.Count - 1]).UserData["code"]) {

                        codeSequence.Items.Add(actionItem);
                    }
                }
            }
            catch (Exception eEliminatingDuplication) {

                codeSequence.Items.Add(actionItem); // ??
            }

            return codeSequence;
        }
 public void CheckCodeSequenceNovelty_CodeSequence_Duplicated()
 {
     bool result = false;
     bool expectedResult = false;
     TranscriptCmdletBase cmdlet = new TranscriptCmdletBase();
     Recorder.RecordingCollection =
         new System.Collections.Generic.List<IRecordedCodeSequence>();
     IRecordedCodeSequence codeSequence = new RecordedCodeSequence();
     RecordedWebElement webElement = new RecordedWebElement();
     webElement.TagName = "button";
     codeSequence.Items.Add(webElement);
     RecordedAction action = new RecordedAction();
     action.UserData.Add("code", Recorder.CodeGenElementClick);
     codeSequence.Items.Add(action);
     
     Recorder.RecordingCollection.Add(codeSequence);
     
     // a new code sequence
     codeSequence = new RecordedCodeSequence();
     webElement = new RecordedWebElement();
     webElement.TagName = "button";
     codeSequence.Items.Add(webElement);
     action = new RecordedAction();
     action.UserData.Add("code", Recorder.CodeGenElementClick);
     codeSequence.Items.Add(action);
     
     result = 
         Recorder.CheckCodeSequenceNovelty(
             cmdlet,
             Recorder.RecordingCollection,
             codeSequence);
     Assert.AreEqual(expectedResult, result);
 }
 public void RecordedAction_Constructor()
 {
     RecordedAction recAction = new RecordedAction();
     //NUnit.Framework.Assert.NotNull(recAction.UserData);
     Assert.IsNotNull(recAction.UserData);
 }
Exemplo n.º 6
0
        internal static IRecordedCodeSequence RecordActionItem(
            TranscriptCmdletBase cmdlet,
            IRecordedCodeSequence codeSequence,
            IWebElement resultWebElement,
            RecordedAction actionItem)
        {
            if (null == codeSequence)
            {
                codeSequence = new RecordedCodeSequence();
            }
            if (null == resultWebElement)
            {
                return(codeSequence);
            }

            actionItem = new RecordedAction();
            var elementId      = string.Empty;
            var elementName    = string.Empty;
            var elementClass   = string.Empty;
            var elementTagName = string.Empty;
            var elementText    = string.Empty;

            try {
                switch (resultWebElement.TagName)
                {
                case ConstAuxElementClicked:
                    actionItem.UserData.Add("code", CodeGenElementClick);
                    break;

                    #region temporaly commented
//                            case Recorder.constAuxElementData:
//                                try { elementId = resultWebElement.GetAttribute("id"); } catch {}
//                                try { elementName = resultWebElement.GetAttribute("name"); } catch {}
//                                try { elementClass = resultWebElement.GetAttribute("class"); } catch {}
//                                try { elementTagName = resultWebElement.TagName; } catch {}
//                                try { elementText = resultWebElement.Text; } catch {}
//                                if (string.Empty != elementId && "null" != elementId) {
//                                    actionItem.UserData.Add("code", codeGenIdParameter + elementId + "'");
//                                    actionItem.UserData.Add("comment1", codeGenNameComment + elementName + "'");
//                                    actionItem.UserData.Add("comment2", codeGenClassComment + elementClass + "'");
//                                    actionItem.UserData.Add("comment3", codeGenTagParameter + elementTagName + "'");
////    Console.WriteLine("\"code\" added 2");
//                                } else if (string.Empty != elementName && "null" != elementName) {
//                                    actionItem.UserData.Add("code", codeGenNameParameter + elementName + "'");
//                                    actionItem.UserData.Add("comment1", codeGenClassComment + elementClass + "'");
//                                    actionItem.UserData.Add("comment2", codeGenTagParameter + elementTagName + "'");
////    Console.WriteLine("\"code\" added 3");
//                                } else if (string.Empty != elementClass && "null" != elementClass) {
//                                    actionItem.UserData.Add("code", codeGenClassParameter + elementClass + "'");
//                                    actionItem.UserData.Add("comment1", codeGenTagParameter + elementTagName + "'");
////    Console.WriteLine("\"code\" added 4");
//                                } else if (string.Empty != elementTagName && "null" != elementTagName) {
//                                    actionItem.UserData.Add("code", codeGenTagParameter + elementTagName + "'");
//                                }
//                                break;
//                    case Recorder.constAuxElementSelected:
//                        actionItem.UserData.Add(@"code", @" | Invoke-SeWebElementClick");
//                        break;
                    #endregion temporaly commented

                case ConstAuxElementTypedIn:
                    var typedInData = string.Empty;
                    if (null != (typedInData = resultWebElement.GetAttribute("text")))
                    {
                        // ??
                    }
                    else if (null != (typedInData = resultWebElement.GetAttribute("value")))
                    {
                        // ??
                    }
                    actionItem.UserData.Add("code", @" | Set-SeWebElementKeys '" + typedInData + "'");
                    break;

                case ConstAuxElementSelected:
                    // TBD
                    break;

                case ConstAuxElementData:
                    // nothing to do
                    break;
                }
            }
            catch (Exception eActionItem) {
                Console.WriteLine("a fake item exception: " + eActionItem.Message);
            }

            // ??
            actionItem.Final = true;
            //

            if (codeSequence.ContainsDataItem())
            {
                codeSequence.ReadyToProduceCode = true;
            }

            try {
                if (0 == codeSequence.Items.Count)
                {
                    codeSequence.Items.Add(actionItem);
                }
                else if (null == (codeSequence.Items[codeSequence.Items.Count - 1] as IRecordedActionItem))
                {
                    codeSequence.Items.Add(actionItem);
                }
                else if (null != ((IRecordedActionItem)codeSequence.Items[codeSequence.Items.Count - 1]).UserData)
                {
                    if (actionItem.UserData["code"] !=
                        ((IRecordedActionItem)codeSequence.Items[codeSequence.Items.Count - 1]).UserData["code"])
                    {
                        codeSequence.Items.Add(actionItem);
                    }
                }
            }
            catch (Exception eEliminatingDuplication) {
                codeSequence.Items.Add(actionItem); // ??
            }

            return(codeSequence);
        }