Beispiel #1
0
 /// <summary>
 /// 检查是否有不存在的元素,如果有则修改状态为Faulted
 /// </summary>
 /// <param name="browser"></param>
 public void ValidateAction(csExWB.cEXWB browser)
 {
     foreach (ActionBase action in this)
     {
         string typeName = action.GetType().Name;
         if (typeName == "ActionClick" || typeName == "ActionSleep")
         {
             action.Status = StatusIndicators.StepContinue;
             continue;
         }
         ActionElementBase actionE = action as ActionElementBase;
         if (actionE != null)
         {
             action.Status = StatusIndicators.StepContinue;
             string id = actionE.ElementId;
             if (!string.IsNullOrEmpty(id))
             {
                 var e = browser.GetElementByID(false, id);
                 if (e == null)
                 {
                     action.Status = StatusIndicators.StepFailure;
                 }
             }
         }
     }
 }
Beispiel #2
0
        /// <summary>
        /// 对活动自动排序, 对输入框,下拉列表排序
        /// </summary>
        public void OrderById()
        {
            Hashtable hash = new Hashtable();

            for (int i = 0; i < this.Count; i++)
            {
                ActionElementBase ab = this[i] as ActionElementBase;
                if (ab == null)
                {
                    continue;
                }
                if (ab is ActionClick)
                {
                    continue;
                }
                if (hash.Contains(ab))
                {
                    continue;
                }
                int clickIndex = FindClickAction(ab);
                int target     = i;
                if (clickIndex < i)
                {
                    target -= 1;
                }
                if (clickIndex != -1)
                {
                    hash.Add(ab, ab);
                    MoveTo(clickIndex, target);
                }
            }
        }
Beispiel #3
0
        static public ElementCollection GetElementsByXPath(this IElementContainer container, string xpath)
        {
            DateTime now = DateTime.Now;

            xpath = xpath.Trim();
            if (xpath[xpath.Length - 1] == '/')
            {
                xpath = xpath.Substring(0, xpath.Length - 1);
            }
            var constraint = ActionElementBase.GetConstraint(new FindAttribute()
            {
                FindMethod = FindMethods.XPath,
                FindValue  = xpath,
                Regex      = true,
            });
            string tagName = GetLastTag(xpath);

            int index = xpath.IndexOf("*");
            ElementCollection elements = null;

            if (index > 0)
            {
                elements = GetElementsByXPath(container, xpath.Substring(0, xpath.Substring(0, index).LastIndexOf("/")));

                if (elements.Count > 0)
                {
                    return(GetElementsByTag((IElementContainer)elements[0], tagName, constraint));
                }
                return(null);
            }

            elements = GetElementsByTag(container, tagName, constraint);
            logger.Info("GetElementsByXPath:" + DateTime.Now.Subtract(now).TotalMilliseconds);
            return(elements);
        }
Beispiel #4
0
        public bool Contain(ActionBase action)
        {
            //if (action is ActionNavigate) return false;
            //if (action is ActionDirectionKey) return false;
            //if (action is ActionVariable) return false;
            //非页面元素活动不检查
            ActionElementBase el = action as ActionElementBase;

            if (el == null)
            {
                return(false);
            }
            bool   ret = false;
            object obj = new object();

            lock (obj)
            {
                foreach (var o in this)
                {
                    if (o.ID == action.ID)
                    {
                        ret = true;
                        break;
                    }
                }
            }
            return(ret);
        }
Beispiel #5
0
 public Constraint FindByAttr(string attr, string value)
 {
     return(ActionElementBase.GetConstraint(new FindAttribute()
     {
         FindMethod = (FindMethods)Enum.Parse(typeof(FindMethods), attr, true),
         FindValue = value,
         Regex = true,
     }));
 }
Beispiel #6
0
        public void ChangeActionFinder(ActionElementBase action, NameValueCollection nvcFinder)
        {
            if (action == null)
            {
                return;
            }
            action.ActionFinder.SetAttributes(nvcFinder);

            OnActionModified(action);
        }
Beispiel #7
0
 public void SetCheckList(ActionElementBase element)
 {
     _finder = element.AllAttributes;
     clbAttributes.Items.Clear();
     foreach (string attributekey in _finder.AllKeys)
     {
         clbAttributes.Items.Add(attributekey + " = " + _finder[attributekey],
                                 element.ActionFinder.KeyExists(attributekey)?CheckState.Checked : CheckState.Unchecked);
     }
 }
Beispiel #8
0
        private void Write(List <IHTMLElement> activeElements)
        {
            if (activeElements.Count == 0)
            {
                return;
            }
            IAppContext context = AppContext.Current;
            ModelSet    model   = new ModelSet(new CustomScriptWriteRepository(Identity.UserId, scriptId));

            foreach (var o in activeElements)
            {
                var type = ActionElementBase.TagStringToElementType(o);
                switch (type)
                {
                case ElementTypes.TextField:
                    model.AddAction(context, ActionEnum.ActionTypeText.ToString(),
                                    new ActionTypingParameter()
                    {
                        Element     = o,
                        XPathFinder = false
                    });
                    break;

                case ElementTypes.RadioButton:
                    model.AddAction(context, ActionEnum.ActionRadio.ToString(), new ActionClickParameter()
                    {
                        Element = o,
                    });
                    break;

                case ElementTypes.CheckBox:
                    model.AddAction(context, ActionEnum.ActionCheckbox.ToString(), new ActionClickParameter()
                    {
                        Element = o,
                    });
                    break;

                case ElementTypes.SelectList:
                    model.AddAction(context, ActionEnum.ActionSelectList.ToString(),
                                    new Core.ActionBuilder.SelectParameter()
                    {
                        ByValue = true, Element = o
                    });
                    break;

                default:
                    break;
                }
            }
            activeElements.Clear();
            model.Save();
        }
Beispiel #9
0
        public int GetElementIndex(ActionElementBase element)
        {
            int index = 0;

            foreach (var o in this)
            {
                ActionElementBase a = o as ActionElementBase;
                if (a != null)
                {
                    if (a.ID == element.ID)
                    {
                        break;
                    }
                }
                index++;
            }
            return(index == this.Count ? -1 : index);
        }
Beispiel #10
0
        /// <summary>
        /// 获取同一个元素的活动项
        /// </summary>
        /// <param name="constraint"></param>
        /// <returns></returns>
        public List <ActionElementBase> GetTheElementActions(WatiN.Core.Constraints.Constraint constraint)
        {
            string cs = constraint.ToString();
            List <ActionElementBase> aes = new List <ActionElementBase>();

            foreach (var o in this)
            {
                ActionElementBase ae = o as ActionElementBase;
                if (ae == null)
                {
                    continue;
                }
                if (ae.GetConstraint().ToString() == cs)
                {
                    aes.Add(ae);
                }
            }
            return(aes);
        }
Beispiel #11
0
        private int FindClickAction(ActionElementBase ab)
        {
            int index = -1;

            for (int i = 0; i < this.Count; i++)
            {
                ActionElementBase action = this[i] as ActionElementBase;
                if (action == null)
                {
                    continue;
                }
                if ((action is ActionClick) && action.GetConstraint().ToString() == ab.GetConstraint().ToString())
                {
                    index = i;
                    break;
                }
            }
            return(index);
        }
Beispiel #12
0
        /// <summary>
        /// 为活动选择元素增加标签说明
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void view_TagLabelEvent(object sender, EventArgs e)
        {
            ICoreBrowser browser       = Context.Browser;
            IHTMLElement activeElement = null;

            if (browser.Selector != null && browser.Selector.SelectorElement != null)
            {
                activeElement = browser.Selector.SelectorElement;
            }
            if (activeElement == null)
            {
                return;
            }

            if (string.IsNullOrEmpty(activeElement.innerText))
            {
                return;
            }

            //int selectIndex = Context.State.SelectItemIndex;
            //if (selectIndex == -1) return;
            ActionBase actionBase = Context.State.ActiveAction;//wsv.DataSource[wsv.SelectItemIndex - 1] as ActionBase;

            if (actionBase == null)
            {
                return;
            }
            ActionElementBase ae = actionBase as ActionElementBase;

            if (ae == null)
            {
                return;
            }

            List <ActionElementBase> aes = Model.ActiveActionModel.GetTheElementActions(ae.GetConstraint());
            string labelText             = activeElement.innerText.Replace(":", "").Replace(":", "").Trim();

            foreach (var o in aes)
            {
                o.Title = labelText;
            }
            // wsv.DataBind();
        }
Beispiel #13
0
 void attrCombox_SelectedIndexChanged(object sender, EventArgs e)
 {
     propertyTextbox.Enabled = attrCombox.SelectedIndex == 2;
     if (propertyTextbox.Enabled)
     {
         ActionElementBase action = base.Action as ActionElementBase;
         if (action != null)
         {
             if (action.ElementType == ElementTypes.Link)
             {
                 propertyTextbox.Text = "href";
             }
             else if (action.ElementType == ElementTypes.Image)
             {
                 propertyTextbox.Text = "src";
             }
         }
     }
 }
Beispiel #14
0
 public void ObjectToGui(ActionElementBase act)
 {
     this.action = act;
     methodComboBox.DataSource            = Enum.GetValues(typeof(FindMethods));
     methodComboBox.SelectedIndexChanged += new EventHandler(methodComboBox_SelectedIndexChanged);
     if (act.FindMechanism.Count > 0)
     {
         FindAttribute attribute = act.FindMechanism[0];
         methodComboBox.SelectedItem = attribute.FindMethod;
         regxCheckBox.Checked        = attribute.Regex;
         valueTextBox.Text           = attribute.FindValue;
         var currentElement = action.GetElement();
         if (currentElement != null && currentElement.Exists)
         {
             contentTextBox.Text = currentElement.OuterHtml;
         }
         else
         {
             contentTextBox.Text = "";
         }
     }
 }
        /// <summary>
        /// given an element, it creates a property string for writing
        /// </summary>
        /// <param name="friendlyName">friendly name of the element</param>
        /// <param name="action">action object used to get the element's finder and window name</param>
        internal void ElementToProperty(string friendlyName, ActionElementBase action)
        {
            string elementConstraintString = GetPropertyAttributeString(action.ActionFinder);

            // check for duplicate properties
            if (Properties.Exists(p => p.Finder.TagName == action.ActionFinder.TagName &&
                                  p.Finder.ActionUrl == action.ActionFinder.ActionUrl &&
                                  GetPropertyAttributeString(p.Finder) == elementConstraintString))
            {
                return;
            }

            string propertyType = GetPropertyType(action.ActionFinder.TagName);
            string frames       = GetFrames(action.ActionFrames);

            string property = Template.PropertyTemplate;

            property = Regex.Replace(property, "FRAMES\\.", frames); // replacing the dot too
            property = Regex.Replace(property, "ELEMENTTYPE", propertyType);
            property = Regex.Replace(property, "ELEMENTNAME", friendlyName);
            property = Regex.Replace(property, "ELEMENTDESCRIPTION", action.ActionFinder.GetDescription());
            property = Regex.Replace(property, "ELEMENTFINDCOLLECTION", GetPropertyAttributeString(action.ActionFinder));
            Properties.Add(new ScriptProperty(action.ActionWindow.InternalName, property, action.ActionFinder));
        }