Beispiel #1
0
        public static void RecordActions(TranscriptCmdletBase cmdlet, IJsRecorder jsRecorder, RecorderLanguages languageCode) //, bool waitForElement)
        {
            var startTime = DateTime.Now;

            RecordingCollection = 
                new List<IRecordedCodeSequence>();
            IRecordedCodeSequence codeSequence =
                new RecordedCodeSequence();
            var codeString = string.Empty;

            var currentWindowHandles =
                //CurrentData.CurrentWebDriver.WindowHandles;
                new ReadOnlyCollection<string>((new List<string>()));

            if (null != CurrentData.CurrentWebDriver &&
                null != CurrentData.CurrentWebDriver.WindowHandles) {

                currentWindowHandles = CurrentData.CurrentWebDriver.WindowHandles;
            }

            do {

                jsRecorder.MakeJsInjection(cmdlet);

                try {

                    var scriptResults = jsRecorder.GetRecordedResults();
                        
                    if (null != scriptResults) { // && scriptResults is object[] && 0 < ((object[])scriptResults).Length) {
                        foreach (var singleResult in scriptResults) {

                            codeSequence =
                                RecordCodeSequence(
                                    cmdlet,
                                    RecordingCollection,
                                    singleResult,
                                    codeSequence);

                            if (CodeSequenceCompleted) {

                                NotifyCodeGathered();
                                
                                codeString =
                                    ConvertCodeSequenceToCode(
                                        codeSequence,
                                        SelectLanguage(languageCode),
                                        codeString);
Console.WriteLine("codeString:");
Console.WriteLine(codeString);
                                CodeSequenceCompleted = false;
                            }
                            
                            if (null != (singleResult as IWebElement)) {

                                var resultElement = 
                                    singleResult as IWebElement;

                                if (IsNotFakeWebElement(resultElement)) {
                                    cmdlet.WriteVerbose(cmdlet, "element is not a fake");

                                    if (cmdlet.PassThru) {

                                        cmdlet.WriteVerbose(cmdlet, "outputting the object");
                                        cmdlet.WriteObject(cmdlet, resultElement);
                                        
                                    } else if (Preferences.Highlight) {

                                        cmdlet.WriteVerbose(cmdlet, "highlighting the object");
                                        SeHelper.Highlight(resultElement);
                                        
                                    }
                                } 
                            } 
#region commented 20101031
//                            else if (null != (singleResult as ReadOnlyCollection<object>)){
////Console.WriteLine("0010: singleResult type is " + singleResult.GetType().Name);
//                                RecordedData recData = new RecordedData();
//                                ReadOnlyCollection<object> elementData = singleResult as ReadOnlyCollection<object>;
////Console.WriteLine("0012: Count = " + elementData.Count.ToString());
//
////try { Console.WriteLine("000001: " + elementData); } catch {}
////try { cmdlet.WriteObject(cmdlet, "000002: " + elementData); } catch {}
////try { Console.WriteLine("000003: " + elementData[0]); } catch {}
////try { cmdlet.WriteObject("000004: " + elementData[0]); } catch {}
////if (0 < elementData.Count) {
////    foreach (var item1 in elementData) {
////        cmdlet.WriteObject(cmdlet, item1.GetType().Name);
////        cmdlet.WriteObject(cmdlet, item1);
////    }
////}
//
////                                Dictionary<string, object> elementData2 = singleResult as Dictionary<string, object>;
////if (null != elementData2) {
////    Console.WriteLine("0012-2: Count = " + elementData2.Keys.Count.ToString());
////                                foreach (KeyValuePair<string, object> elementDataItem in elementData) {
////    Console.WriteLine("elementDataItem[elementDataItem.Keys[]] = " + elementDataItem.Key + "\t" + elementDataItem.Value.ToString());
////                                }
////}
////                                foreach (var elementDataItem in elementData) {
////Console.WriteLine("0015");
////                                        //recData.UserData.Add(elementData.
////                                    Console.WriteLine(elementDataItem);
////                                }
//                                //}
//                            } 
#endregion commented 20101031
                            else {

                                cmdlet.WriteObject(cmdlet, "singleResult is not IWebElement");
                                cmdlet.WriteObject(cmdlet, "else: " + singleResult);
                                //cmdlet.WriteObject(cmdlet, singleResult);
                                
                                
                            }
                        } // foreach (var singleResult in scriptResults) {
                    } // if (null != scriptResults) {
                }
                catch (Exception eRec) {
                    Console.WriteLine(eRec.Message);
                }
                
#region commented - the previous version
//                ReadOnlyCollection<IWebElement> scriptResult = null;
//                //System.Collections.ArrayList scriptResultOther = null;
//                object[] scriptResultOther = null;
//                
//                try {
//                    var scriptResultUndefined = 
//                        ((IJavaScriptExecutor)CurrentData.CurrentWebDriver).ExecuteScript(
//                            JSRecorder.constRecorderGetElement,
//                            (new string[] { string.Empty } ));
////                        (ReadOnlyCollection<IWebElement>)((IJavaScriptExecutor)CurrentData.CurrentWebDriver).ExecuteScript(
////                            JSRecorder.constRecorderGetElement,
////                            (new string[] { string.Empty } ));
//                    
//                    scriptResult = scriptResultUndefined as ReadOnlyCollection<IWebElement>;
//                    scriptResultOther = scriptResultUndefined as object[];
//                    
//                    if (null == scriptResult && null == scriptResultOther ) {
//                        cmdlet.WriteVerbose(cmdlet, "scriptResult == null");
//                    } else {
//                        cmdlet.WriteVerbose(cmdlet, "scriptResult != null");
//                        if (null != scriptResult && 0 == scriptResult.Count) {
//                            cmdlet.WriteVerbose(cmdlet, "scriptResult.Count == 0");
//                        } else if (null != scriptResultOther && 0 == scriptResultOther.Length) {
//                            cmdlet.WriteVerbose(cmdlet, "scriptResultOther.Count == 0");
//                        } else {
//                            cmdlet.WriteVerbose(cmdlet, "scriptResult.Count == " + scriptResult.Count.ToString());
//                            
//                            foreach (IWebElement resultElement in scriptResult) {
//                                codeSequence =
//                                    Recorder.RecordCodeSequence(
//                                        cmdlet,
//                                        recordingCollection,
//                                        resultElement,
//                                        codeSequence);
//
//                                if (Recorder.isNotFakeWebElement(resultElement)) {
//                                    cmdlet.WriteVerbose(cmdlet, "element is not a fake");
//
//                                    if (cmdlet.PassThru) {
//                                        
//                                        cmdlet.WriteVerbose(cmdlet, "outputting the object");
//                                        cmdlet.WriteObject(cmdlet, resultElement);
//                                        
//                                    } else if (Preferences.Highlight) {
//                                        
//                                        cmdlet.WriteVerbose(cmdlet, "highlighting the object");
//                                        SeHelper.Highlight(resultElement);
//                                        
//                                    }
//                                } 
//                            }
//                            
//                            // 20121012
//                            scriptResult = null; // ??
//                        }
//                    }
//                }
//                catch (Exception eRecording) {
//Console.WriteLine("eRecording: " + eRecording.Message);
//                    if (eRecording.Message.Contains("Element does not exist in cache")) {
//                        CurrentData.CurrentWebDriver.Navigate().Refresh();
//                    }
//                }
//                //
//                //
//                //
//                //
#endregion commented - the previous version
                
                cmdlet.WriteVerbose(cmdlet, "startTime = " + startTime.ToString());
                
                if ((DateTime.Now - startTime).TotalSeconds > 
                    (cmdlet.Timeout / 1000) &&
                    cmdlet.Wait) {
                    cmdlet.WriteVerbose(cmdlet, "Time spent: " + (DateTime.Now - startTime).TotalSeconds + " seconds");
                    
                    cmdlet.Wait = false;
                }
                
                SleepAndRunScriptBlocks(cmdlet);
                
                /*
                if (Preferences.TranscriptCleanRecordedDuringSleep) {
                    SeHelper.CleanRecordedDuringSleep(cmdlet);
                }
                */
               
               GoToNewlyOpenedWindowhandle(currentWindowHandles);
               

            } while (cmdlet.Wait);
            
            //SeHelper.ExitRecording(cmdlet);
            
            // store the last code sequence
            StoreCodeSequenceInCollection(
                cmdlet,
                RecordingCollection,
                codeSequence);
            
        }
Beispiel #2
0
        public static void RecordActions(TranscriptCmdletBase cmdlet, IJsRecorder jsRecorder, RecorderLanguages languageCode) //, bool waitForElement)
        {
            var startTime = DateTime.Now;

            RecordingCollection =
                new List <IRecordedCodeSequence>();
            IRecordedCodeSequence codeSequence =
                new RecordedCodeSequence();
            var codeString = string.Empty;

            var currentWindowHandles =
                //CurrentData.CurrentWebDriver.WindowHandles;
                new ReadOnlyCollection <string>((new List <string>()));

            if (null != CurrentData.CurrentWebDriver &&
                null != CurrentData.CurrentWebDriver.WindowHandles)
            {
                currentWindowHandles = CurrentData.CurrentWebDriver.WindowHandles;
            }

            do
            {
                jsRecorder.MakeJsInjection(cmdlet);

                try {
                    var scriptResults = jsRecorder.GetRecordedResults();

                    if (null != scriptResults)   // && scriptResults is object[] && 0 < ((object[])scriptResults).Length) {
                    {
                        foreach (var singleResult in scriptResults)
                        {
                            codeSequence =
                                RecordCodeSequence(
                                    cmdlet,
                                    RecordingCollection,
                                    singleResult,
                                    codeSequence);

                            if (CodeSequenceCompleted)
                            {
                                NotifyCodeGathered();

                                codeString =
                                    ConvertCodeSequenceToCode(
                                        codeSequence,
                                        SelectLanguage(languageCode),
                                        codeString);
                                Console.WriteLine("codeString:");
                                Console.WriteLine(codeString);
                                CodeSequenceCompleted = false;
                            }

                            if (null != (singleResult as IWebElement))
                            {
                                var resultElement =
                                    singleResult as IWebElement;

                                if (IsNotFakeWebElement(resultElement))
                                {
                                    cmdlet.WriteVerbose(cmdlet, "element is not a fake");

                                    if (cmdlet.PassThru)
                                    {
                                        cmdlet.WriteVerbose(cmdlet, "outputting the object");
                                        cmdlet.WriteObject(cmdlet, resultElement);
                                    }
                                    else if (Preferences.Highlight)
                                    {
                                        cmdlet.WriteVerbose(cmdlet, "highlighting the object");
                                        SeHelper.Highlight(resultElement);
                                    }
                                }
                            }
                            #region commented 20101031
//                            else if (null != (singleResult as ReadOnlyCollection<object>)){
////Console.WriteLine("0010: singleResult type is " + singleResult.GetType().Name);
//                                RecordedData recData = new RecordedData();
//                                ReadOnlyCollection<object> elementData = singleResult as ReadOnlyCollection<object>;
////Console.WriteLine("0012: Count = " + elementData.Count.ToString());
//
////try { Console.WriteLine("000001: " + elementData); } catch {}
////try { cmdlet.WriteObject(cmdlet, "000002: " + elementData); } catch {}
////try { Console.WriteLine("000003: " + elementData[0]); } catch {}
////try { cmdlet.WriteObject("000004: " + elementData[0]); } catch {}
////if (0 < elementData.Count) {
////    foreach (var item1 in elementData) {
////        cmdlet.WriteObject(cmdlet, item1.GetType().Name);
////        cmdlet.WriteObject(cmdlet, item1);
////    }
////}
//
////                                Dictionary<string, object> elementData2 = singleResult as Dictionary<string, object>;
////if (null != elementData2) {
////    Console.WriteLine("0012-2: Count = " + elementData2.Keys.Count.ToString());
////                                foreach (KeyValuePair<string, object> elementDataItem in elementData) {
////    Console.WriteLine("elementDataItem[elementDataItem.Keys[]] = " + elementDataItem.Key + "\t" + elementDataItem.Value.ToString());
////                                }
////}
////                                foreach (var elementDataItem in elementData) {
////Console.WriteLine("0015");
////                                        //recData.UserData.Add(elementData.
////                                    Console.WriteLine(elementDataItem);
////                                }
//                                //}
//                            }
                            #endregion commented 20101031
                            else
                            {
                                cmdlet.WriteObject(cmdlet, "singleResult is not IWebElement");
                                cmdlet.WriteObject(cmdlet, "else: " + singleResult);
                                //cmdlet.WriteObject(cmdlet, singleResult);
                            }
                        } // foreach (var singleResult in scriptResults) {
                    }     // if (null != scriptResults) {
                }
                catch (Exception eRec) {
                    Console.WriteLine(eRec.Message);
                }

                #region commented - the previous version
//                ReadOnlyCollection<IWebElement> scriptResult = null;
//                //System.Collections.ArrayList scriptResultOther = null;
//                object[] scriptResultOther = null;
//
//                try {
//                    var scriptResultUndefined =
//                        ((IJavaScriptExecutor)CurrentData.CurrentWebDriver).ExecuteScript(
//                            JSRecorder.constRecorderGetElement,
//                            (new string[] { string.Empty } ));
////                        (ReadOnlyCollection<IWebElement>)((IJavaScriptExecutor)CurrentData.CurrentWebDriver).ExecuteScript(
////                            JSRecorder.constRecorderGetElement,
////                            (new string[] { string.Empty } ));
//
//                    scriptResult = scriptResultUndefined as ReadOnlyCollection<IWebElement>;
//                    scriptResultOther = scriptResultUndefined as object[];
//
//                    if (null == scriptResult && null == scriptResultOther ) {
//                        cmdlet.WriteVerbose(cmdlet, "scriptResult == null");
//                    } else {
//                        cmdlet.WriteVerbose(cmdlet, "scriptResult != null");
//                        if (null != scriptResult && 0 == scriptResult.Count) {
//                            cmdlet.WriteVerbose(cmdlet, "scriptResult.Count == 0");
//                        } else if (null != scriptResultOther && 0 == scriptResultOther.Length) {
//                            cmdlet.WriteVerbose(cmdlet, "scriptResultOther.Count == 0");
//                        } else {
//                            cmdlet.WriteVerbose(cmdlet, "scriptResult.Count == " + scriptResult.Count.ToString());
//
//                            foreach (IWebElement resultElement in scriptResult) {
//                                codeSequence =
//                                    Recorder.RecordCodeSequence(
//                                        cmdlet,
//                                        recordingCollection,
//                                        resultElement,
//                                        codeSequence);
//
//                                if (Recorder.isNotFakeWebElement(resultElement)) {
//                                    cmdlet.WriteVerbose(cmdlet, "element is not a fake");
//
//                                    if (cmdlet.PassThru) {
//
//                                        cmdlet.WriteVerbose(cmdlet, "outputting the object");
//                                        cmdlet.WriteObject(cmdlet, resultElement);
//
//                                    } else if (Preferences.Highlight) {
//
//                                        cmdlet.WriteVerbose(cmdlet, "highlighting the object");
//                                        SeHelper.Highlight(resultElement);
//
//                                    }
//                                }
//                            }
//
//                            // 20121012
//                            scriptResult = null; // ??
//                        }
//                    }
//                }
//                catch (Exception eRecording) {
//Console.WriteLine("eRecording: " + eRecording.Message);
//                    if (eRecording.Message.Contains("Element does not exist in cache")) {
//                        CurrentData.CurrentWebDriver.Navigate().Refresh();
//                    }
//                }
//                //
//                //
//                //
//                //
                #endregion commented - the previous version

                cmdlet.WriteVerbose(cmdlet, "startTime = " + startTime.ToString());

                if ((DateTime.Now - startTime).TotalSeconds >
                    (cmdlet.Timeout / 1000) &&
                    cmdlet.Wait)
                {
                    cmdlet.WriteVerbose(cmdlet, "Time spent: " + (DateTime.Now - startTime).TotalSeconds + " seconds");

                    cmdlet.Wait = false;
                }

                SleepAndRunScriptBlocks(cmdlet);

                /*
                 * if (Preferences.TranscriptCleanRecordedDuringSleep) {
                 *  SeHelper.CleanRecordedDuringSleep(cmdlet);
                 * }
                 */

                GoToNewlyOpenedWindowhandle(currentWindowHandles);
            } while (cmdlet.Wait);

            //SeHelper.ExitRecording(cmdlet);

            // store the last code sequence
            StoreCodeSequenceInCollection(
                cmdlet,
                RecordingCollection,
                codeSequence);
        }