Esempio n. 1
0
        private void OnCanceledClick(IntPtr ieWnd, Point screenPos)
        {
            // Reset any mouseup package.
            this.recLastMouseUpPackage = null;

            if (!Win32Api.IsWindow(ieWnd))
            {
                return;
            }

            IHTMLElement htmlElem = GetHtmlElementFromScreenPoint(ieWnd, screenPos);

            if (htmlElem == null)
            {
                return;
            }

            if (!IsValidForClickRec(htmlElem))
            {
                return;
            }

            RecEventArgs recPackage = RecEventArgs.CreateRecEvent(htmlElem, twebstBrowser);

            // Notify listeners about a recorded click action.
            this.ClickAction(this, recPackage);
        }
Esempio n. 2
0
        // If onmouseup is canceled and onclick is not we'll fall back on OnCanceledClick case.
        private void OnHtmlMouseUp(object sender, EventArgs e)
        {
            // Reset any previous mouse up package.
            this.recLastMouseUpPackage = null;

            // On www.xero.com the source element we get on click event is messed up I don't know why.
            // Just keep the source recorder package we correctly get on mouseup event and use it with onclick event.
            if (this.IsRecording && (this.ClickAction != null))
            {
                HtmlHandler  htmlHandler = (HtmlHandler)sender;
                IHTMLElement htmlSource  = [email protected];

                if (!IsValidForClickRec(htmlSource))
                {
                    return;
                }

                // For non <img> elements take a parent anchor. Example: a <b> inside an <a>. Skip anchor with names (page bookmarks).
                IHTMLImgElement imgElem = htmlSource as IHTMLImgElement;
                if (imgElem == null)
                {
                    IElement sourceElement = this.twebstCore.AttachToNativeElement(htmlSource);
                    IElement parentAnchor  = sourceElement.FindParentElement("a", "name="); // A parent anchor without a name.

                    if (parentAnchor != null)
                    {
                        htmlSource = parentAnchor.nativeElement;
                    }
                }

                this.recLastMouseUpPackage = RecEventArgs.CreateRecEvent(htmlSource, twebstBrowser);
            }
        }
Esempio n. 3
0
        private void OnHtmlClick(object sender, EventArgs e)
        {
            if (this.IsRecording && (this.ClickAction != null) && (this.recLastMouseUpPackage != null))
            {
                this.pendingWin32Click = false;

                // On google.com for instance, clicking on a label attached to a radio will trigger another onclick for radio.
                // Duplicate statements must e filtered out.
                if (this.pendingWin32Action &&
                    ((DateTime.Now - this.lastWin32Time).TotalMilliseconds <= MAXIMUM_TIME_FOR_PENDING_CLICKS))
                {
                    this.pendingWin32Action = false;
                    this.lastWin32Time      = DateTime.Now;

                    RecEventArgs recPackage = this.recLastMouseUpPackage;
                    this.recLastMouseUpPackage = null;

                    // Notify listeners about a recorded click action.
                    this.ClickAction(this, recPackage);
                    return;
                }
            }

            this.recLastMouseUpPackage = null;
        }
Esempio n. 4
0
        private bool FindNonEmptyAttribute(RecEventArgs evt, out String attr, out String attrVal, params Object[] attrNames)
        {
            ICustomRecording customRec = this.languageGenerator as ICustomRecording;

            for (int i = 0; i < attrNames.Length; ++i)
            {
                String crntAttr = (String)attrNames[i];
                String val      = evt.GetAttribute(crntAttr);

                if (val != "")
                {
                    attr = crntAttr;

                    if ((attr == "src") && ((customRec == null) || customRec.ShortSrc))
                    {
                        // For src attribute of the image element keep only the file name if any.
                        int lastSlashIndex = val.LastIndexOf('/');

                        attrVal = val.Substring(lastSlashIndex + 1);
                    }
                    else
                    {
                        attrVal = val;
                    }

                    return(true);
                }
            }

            return(evt.GetFirstAttribute(out attr, out attrVal));
        }
Esempio n. 5
0
 private String ComputeTwebstTagName(RecEventArgs evt)
 {
     if (evt.InputType != null)
     {
         return(evt.TagName + " " + evt.InputType);
     }
     else
     {
         return(evt.TagName);
     }
 }
Esempio n. 6
0
        private void OnHtmlChange(object sender, EventArgs e)
        {
            if (this.IsRecording && (this.ChangeAction != null))
            {
                HtmlHandler  htmlHandler = (HtmlHandler)sender;
                IHTMLElement htmlSource  = [email protected];
                RecEventArgs recPackage  = RecEventArgs.CreateRecEvent(htmlSource, twebstBrowser);

                // Notify listeners about a recorded value change action.
                this.ChangeAction(this, recPackage);
            }
        }
Esempio n. 7
0
        private bool GetAttrToRecord(RecEventArgs evt, out String attr, out String attrVal)
        {
            ICustomRecording customRec = this.languageGenerator as ICustomRecording;

            if (customRec != null)
            {
                return(this.FindNonEmptyAttribute(evt, out attr, out attrVal, customRec.GetRecordedAttributes(evt.TagName, evt.InputType)));
            }

            // href is for area, src is for img.
            return(this.FindNonEmptyAttribute(evt, out attr, out attrVal, "id", "name", "uiname", "src", "href", "class"));
        }
Esempio n. 8
0
        private void OnRightClick(IntPtr ieWnd, Point screenPos)
        {
            if (this.IsRecording && (this.RightClickAction != null))
            {
                IHTMLElement htmlElem = GetHtmlElementFromScreenPoint(ieWnd, screenPos);
                if (htmlElem == null)
                {
                    return;
                }

                RecEventArgs recPackage = RecEventArgs.CreateRecEvent(htmlElem, twebstBrowser);

                // Notify listeners about a recorded click action.
                this.RightClickAction(this, recPackage);
            }
        }
Esempio n. 9
0
        private void OnClick(Object sender, RecEventArgs evt, bool isRightClick)
        {
            int brwsNameIndex = GenBrowserCode(evt.BrowserURL, evt.BrowserTitle, evt.BrowserAppName, evt.BrowserHWND);

            String attr;
            String attrVal;

            String twebstTagName = ComputeTwebstTagName(evt);
            bool   success       = GetAttrToRecord(evt, out attr, out attrVal);

            // What to do if no attribute (success is false). Use only index or don't record anything?
            int          index = ComputeIndex(evt, twebstTagName, attr, attrVal);
            RawStatement rs    = RawStatement.CreateClickStatement(twebstTagName, attr, attrVal, index, evt.IsChecked, isRightClick, brwsNameIndex);

            this.AddStatement(rs);
        }
Esempio n. 10
0
        private void OnChangeAction(Object sender, RecEventArgs evt)
        {
            int brwsNameIndex = GenBrowserCode(evt.BrowserURL, evt.BrowserTitle, evt.BrowserAppName, evt.BrowserHWND);

            String attr;
            String attrVal;

            bool   success       = GetAttrToRecord(evt, out attr, out attrVal);
            String twebstTagName = ComputeTwebstTagName(evt);
            int    index         = ComputeIndex(evt, twebstTagName, attr, attrVal);

            if (evt.TagName == "select")
            {
                RawStatement rs = RawStatement.CreateSelectionChangeStatement(twebstTagName, attr, attrVal, evt.Values, evt.IsMultipleSelection, !this.IsSelectVarDeclared, index, brwsNameIndex);

                if (evt.IsMultipleSelection)
                {
                    RawStatement lastStatement = this.LastStatement;
                    if (lastStatement != null)
                    {
                        if (lastStatement.Equals(rs))
                        {
                            this.rawStatements[this.rawStatements.Count - 1] = rs;
                            this.FireCodeChanged();
                        }
                        else
                        {
                            this.AddStatement(rs);
                        }
                    }
                    else
                    {
                        this.AddStatement(rs);
                    }
                }
                else
                {
                    this.AddStatement(rs);
                }
            }
            else
            {
                RawStatement rs = RawStatement.CreateTextChangeStatement(twebstTagName, attr, attrVal, evt.Values, index, brwsNameIndex);
                this.AddStatement(rs);
            }
        }
Esempio n. 11
0
        private void OnScreenSelected(int x, int y)
        {
            Debug.Assert(this.IsSelecting);

            if (this.ElementSelected != null)
            {
                try
                {
                    IElement elem = this.lastSelectingElem; //this.twebstCore.FindElementFromPoint(x, y);
                    if (elem != null)
                    {
                        IHTMLElement htmlElem   = elem.nativeElement;
                        RecEventArgs recPackage = RecEventArgs.CreateRecEvent(htmlElem, elem.parentBrowser);
                        this.ElementSelected(this, recPackage);
                    }
                }
                catch (COMException ex)
                {
                    Debug.WriteLine(ex.Message);
                }
            }
        }
Esempio n. 12
0
        public static RecEventArgs CreateRecEvent(IHTMLElement htmlElem, IBrowser twbstBrowser)
        {
            htmlElem = FilterHtmlElement(htmlElem);

            RecEventArgs result = new RecEventArgs();
            String       topURL = twbstBrowser.url;

            result.htmlTargetElem = htmlElem;
            result.browser        = twbstBrowser;
            result.tagName        = htmlElem.tagName.ToLower();
            result.browserURL     = topURL;
            result.browserTitle   = twbstBrowser.title;
            result.browserAppName = twbstBrowser.app;
            result.browserHwnd    = 0; /*twbstBrowser.nativeBrowser.HWND;*/ // TODO: gotta solve exception? Maybe we don't need the handle after all...
            result.BuildAttributeDictionary(htmlElem);
            result.BuildValuesList(htmlElem);

            IHTMLInputElement inputElem = htmlElem as IHTMLInputElement;

            if (inputElem != null)
            {
                result.inputType = inputElem.type.ToLower();

                if ((result.inputType == "checkbox") || (result.inputType == "radio"))
                {
                    result.isChecked = inputElem.@checked;
                }
            }

            IHTMLSelectElement selectElem = htmlElem as IHTMLSelectElement;

            if (selectElem != null)
            {
                result.isMultipleSelection = selectElem.multiple;
            }

            return(result);
        }
Esempio n. 13
0
 private void OnElementSelected(Object sender, RecEventArgs evt)
 {
     if ((evt.TagName == "select") || (evt.TagName == "textarea"))
     {
         this.OnChangeAction(sender, evt);
     }
     else if (evt.TagName == "input")
     {
         if ((evt.InputType == "text") || (evt.InputType == "password") ||
             (evt.InputType == "file") || (evt.InputType == "email"))
         {
             this.OnChangeAction(sender, evt);
         }
         else
         {
             OnClick(sender, evt, false);
         }
     }
     else
     {
         OnClick(sender, evt, false);
     }
 }
Esempio n. 14
0
 private void OnClickAction(Object sender, RecEventArgs evt)
 {
     OnClick(sender, evt, false);
 }
Esempio n. 15
0
 private void OnRightClickAction(Object sender, RecEventArgs evt)
 {
     OnClick(sender, evt, true);
 }
Esempio n. 16
0
        private int ComputeIndex(RecEventArgs evt, String twebstTagName, String attr, String attrVal)
        {
            try
            {
                String           uniqueValue     = DateTime.Now.ToString();
                IHTMLElement     htmlTarget      = evt.TargetElement;
                String           searchCondition = null;
                IElementList     elements        = null;
                bool             isInnerText     = (attr == "innertext");
                ICustomRecording customRec       = this.languageGenerator as ICustomRecording;

                htmlTarget.setAttribute(CatStudioConstants.FIND_INDEX_HELPER_ATTR, uniqueValue, 0);

                if ((attr != null) && (attrVal != null) && !isInnerText)
                {
                    searchCondition = String.Format("{0}={1}", attr, attrVal);

                    if ((customRec == null) || !customRec.LocalIndex)
                    {
                        elements = evt.Browser.FindAllElements(twebstTagName, searchCondition);
                    }
                    else
                    {
                        ICore    core       = CoreWrapper.Instance;
                        IElement targetElem = core.AttachToNativeElement(evt.TargetElement);

                        // Search only elements in current frame.
                        elements = targetElem.parentFrame.FindChildrenElements(twebstTagName, searchCondition);
                    }
                }
                else
                {
                    if ((customRec == null) || !customRec.LocalIndex)
                    {
                        elements = evt.Browser.FindAllElements(twebstTagName, "");
                    }
                    else
                    {
                        ICore    core       = CoreWrapper.Instance;
                        IElement targetElem = core.AttachToNativeElement(evt.TargetElement);

                        // Search only elements in current frame.
                        elements = targetElem.parentFrame.FindChildrenElements(twebstTagName, "");
                    }
                }

                int index  = 0;
                int length = elements.length;

                if (length <= 1)
                {
                    return(0);
                }

                if (!isInnerText)
                {
                    for (int i = 0; i < length; ++i)
                    {
                        String findIndexAttrValue = (String)elements[i].GetAttribute(CatStudioConstants.FIND_INDEX_HELPER_ATTR);

                        if (uniqueValue == findIndexAttrValue)
                        {
                            index = i;
                            break;
                        }
                    }
                }
                else
                {
                    // Watir uses innerText but Twebst does not search for innerText.
                    for (int i = 0; i < length; ++i)
                    {
                        String findIndexAttrValue = (String)elements[i].GetAttribute(CatStudioConstants.FIND_INDEX_HELPER_ATTR);
                        if (uniqueValue == findIndexAttrValue)
                        {
                            break;
                        }

                        if (attrVal == elements[i].nativeElement.innerText)
                        {
                            index++;
                        }
                    }
                }

                return(index);
            }
            catch
            {
                // Something went wrong, give up using index.
                return(0);
            }
        }