Пример #1
0
		public DerivedImage(By byLocator, IWebDriver webDriver, WaitModel waitModel, BasePageObject parentPageObject, ClickBehaviours clickBehaviour = ClickBehaviours.Default) : base(byLocator, webDriver, waitModel, parentPageObject, clickBehaviour)
		{
		}
Пример #2
0
 internal static BasicPageElement CreateElementObject(Type fieldType, IWebDriver webDriver, By @by, WaitModel waitModel, BasePageObject parentPageObject, ClickBehaviours clickBehaviours = ClickBehaviours.Default, FillBehaviour fillBehaviour = FillBehaviour.Default)
 {
     if (fieldType == typeof(Button))
     {
         return(new Button(@by, webDriver, waitModel, parentPageObject, clickBehaviours));
     }
     if (fieldType == typeof(Link))
     {
         return(new Link(@by, webDriver, waitModel, parentPageObject, clickBehaviours));
     }
     if (fieldType == typeof(Image))
     {
         return(new Image(@by, webDriver, waitModel, parentPageObject, clickBehaviours));
     }
     if (fieldType == typeof(BasicPageElement))
     {
         return(new BasicPageElement(@by, webDriver, waitModel, parentPageObject));
     }
     if (fieldType == typeof(SelectBox))
     {
         return(new SelectBox(@by, webDriver, waitModel, parentPageObject));
     }
     if (fieldType == typeof(CheckBox))
     {
         return(new CheckBox(@by, webDriver, waitModel, parentPageObject, clickBehaviours));
     }
     if (fieldType == typeof(Input))
     {
         return(new Input(@by, webDriver, waitModel, parentPageObject, clickBehaviours, fillBehaviour));
     }
     if (fieldType == typeof(HiddenElement))
     {
         return(new HiddenElement(@by, webDriver, waitModel, parentPageObject, clickBehaviours));
     }
     return(null);
 }
Пример #3
0
		public Link(By objBy, IWebDriver webDriver, WaitModel waitModel, BasePageObject parentPageObject, ClickBehaviours clickBehaviour = ClickBehaviours.Default)
			: base(objBy, webDriver, waitModel, parentPageObject, clickBehaviour)
		{
		}
Пример #4
0
        internal static BasicPageElement CreateElementObject(Type fieldType, IWebDriver webDriver, By @by, WaitModel waitModel, BasePageObject parentPageObject, ClickBehaviours clickBehaviours = ClickBehaviours.Default, FillBehaviour fillBehaviour = FillBehaviour.Default)
        {
            if ((typeof(Button).IsAssignableFrom(fieldType)) ||
                (typeof(Link).IsAssignableFrom(fieldType)) ||
                (typeof(Image).IsAssignableFrom(fieldType)) ||
                (typeof(CheckBox).IsAssignableFrom(fieldType)) ||
                (typeof(HiddenElement).IsAssignableFrom(fieldType)))
            {
                return((BasicPageElement)Activator.CreateInstance(fieldType,
                                                                  BindingFlags.CreateInstance |
                                                                  BindingFlags.Public |
                                                                  BindingFlags.Instance |
                                                                  BindingFlags.OptionalParamBinding, null, new object[] { @by, webDriver, waitModel, parentPageObject, clickBehaviours }, CultureInfo.CurrentCulture));
            }

            if ((typeof(Input).IsAssignableFrom(fieldType)))
            {
                return((BasicPageElement)Activator.CreateInstance(fieldType,
                                                                  BindingFlags.CreateInstance |
                                                                  BindingFlags.Public |
                                                                  BindingFlags.Instance |
                                                                  BindingFlags.OptionalParamBinding, null, new object[] { @by, webDriver, waitModel, parentPageObject, clickBehaviours, fillBehaviour }, CultureInfo.CurrentCulture));
            }


            if ((typeof(BasicPageElement).IsAssignableFrom(fieldType)) ||
                (typeof(SelectBox).IsAssignableFrom(fieldType)))
            {
                return((BasicPageElement)Activator.CreateInstance(fieldType,
                                                                  BindingFlags.CreateInstance |
                                                                  BindingFlags.Public |
                                                                  BindingFlags.Instance |
                                                                  BindingFlags.OptionalParamBinding, null, new object[] { @by, webDriver, waitModel, parentPageObject }, CultureInfo.CurrentCulture));
            }


            return(null);
        }
Пример #5
0
        private static void InitElements(IWebDriver driver, BasePageObject pageObject)
        {
            if (pageObject == null)
            {
                throw new ArgumentNullException("pageObject");
            }

            Type type = pageObject.GetType();
            List <MemberInfo>  memberInfos          = new List <MemberInfo>();
            const BindingFlags publicBindingOptions = BindingFlags.Instance | BindingFlags.Public;

            memberInfos.AddRange(type.GetFields(publicBindingOptions));
            memberInfos.AddRange(type.GetProperties(publicBindingOptions));

            while (type != null)
            {
                const BindingFlags nonPublicBindingOptions = BindingFlags.Instance | BindingFlags.NonPublic;
                memberInfos.AddRange(type.GetFields(nonPublicBindingOptions));
                memberInfos.AddRange(type.GetProperties(nonPublicBindingOptions));
                type = type.BaseType;
            }

            Type pageObjectType = pageObject.GetType();

            foreach (MemberInfo member in memberInfos)
            {
                LocateAttribute         locateAttribute         = GetAttribute <LocateAttribute>(member);
                ClickBehaviourAttribute clickBehaviourAttribute = GetAttribute <ClickBehaviourAttribute>(member);
                ClickBehaviours         clickBehaviour          = clickBehaviourAttribute != null
                                                                            ? clickBehaviourAttribute.Using
                                                                            : ClickBehaviours.Default;

                FillBehaviourAttribute fillBehaviourAttribute = GetAttribute <FillBehaviourAttribute>(member);
                FillBehaviour          fillBehaviour          = fillBehaviourAttribute != null
                                                                                                ? fillBehaviourAttribute.Using
                                                                                                : FillBehaviour.Default;

                WaitAttribute waitAttribute = GetAttribute <WaitAttribute>(member);
                WaitForElementsOnActionAttribute waitForElementsOnActionAttribute = GetAttribute <WaitForElementsOnActionAttribute>(member);

                WaitModel waitModel = new WaitModel
                {
                    WaitBeforeAction = waitAttribute != null
                                                ? waitAttribute.BeforePerformAction
                                                : Settings.Default.WaitBeforePerformAction,
                    WaitAfterAction = waitAttribute != null
                                                ? waitAttribute.AfterPerformAction
                                                : Settings.Default.WaitAfterPerformAction,
                    WaitForElementsBeforeAction = CreateLocateOptionsFromAttribute(waitForElementsOnActionAttribute, pageObjectType, When.Before),
                    WaitForElementsAfterAction  = CreateLocateOptionsFromAttribute(waitForElementsOnActionAttribute, pageObjectType, When.After),
                };

                if (locateAttribute != null)
                {
                    By           by = CreateLocator(member);
                    object       createdElementObject;
                    FieldInfo    field    = member as FieldInfo;
                    PropertyInfo property = member as PropertyInfo;
                    if (field != null)
                    {
                        createdElementObject = CreateElementObject(field.FieldType, driver, by, waitModel, pageObject, clickBehaviour, fillBehaviour);
                        if (createdElementObject == null)
                        {
                            throw new ArgumentException("Type of field '" + field.Name + "' is not IWebElement or IList<IWebElement>");
                        }

                        field.SetValue(pageObject, createdElementObject);
                    }
                    else if (property != null)
                    {
                        createdElementObject = CreateElementObject(property.PropertyType, driver, by, waitModel, pageObject, clickBehaviour, fillBehaviour);
                        if (createdElementObject == null)
                        {
                            throw new ArgumentException("Type of property '" + property.Name + "' is not IWebElement or IList<IWebElement>");
                        }

                        property.SetValue(pageObject, createdElementObject, null);
                    }
                }

                PartialPageObjectAttribute partialPageObjectAttribute = GetAttribute <PartialPageObjectAttribute>(member);
                if (partialPageObjectAttribute != null)
                {
                    PropertyInfo property = member as PropertyInfo;
                    if (property != null)
                    {
                        MethodInfo castMethod           = typeof(PageObjectFactory).GetMethod("CreatePageObject", BindingFlags.Static | BindingFlags.NonPublic).MakeGenericMethod(property.PropertyType);
                        object     createdElementObject = castMethod.Invoke(null, new object[] { driver });
                        if (createdElementObject == null)
                        {
                            throw new ArgumentException("Type of property '" + property.Name + "' is not IWebElement or IList<IWebElement>");
                        }

                        property.SetValue(pageObject, createdElementObject, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, null, null);
                    }
                }
            }
        }
Пример #6
0
		public DerivedInput(By objBy, IWebDriver webDriver, WaitModel waitModel, BasePageObject parentPageObject, ClickBehaviours clickBehaviour = ClickBehaviours.Default, FillBehaviour fillBehaviour = FillBehaviour.Default) : base(objBy, webDriver, waitModel, parentPageObject, clickBehaviour, fillBehaviour)
		{
		}
Пример #7
0
		public Input(By objBy, IWebDriver webDriver, WaitModel waitModel, BasePageObject parentPageObject, ClickBehaviours clickBehaviour = ClickBehaviours.Default, FillBehaviour fillBehaviour = FillBehaviour.Default)
			: base(objBy, webDriver, waitModel, parentPageObject, clickBehaviour)
		{
			_fillBehaviour = TestContext.FillBehaviourFactory.Create(fillBehaviour, this);
		}
		public DerivedSelectBox(By objBy, IWebDriver webDriver, WaitModel waitModel, BasePageObject parentPageObject, ISelectable selectBehaviour = null) : base(objBy, webDriver, waitModel, parentPageObject, selectBehaviour)
		{
		}
Пример #9
0
		public SelectBox(By objBy, IWebDriver webDriver, WaitModel waitModel, BasePageObject parentPageObject, ISelectable selectBehaviour = null)
			: base(objBy, webDriver, waitModel, parentPageObject, ClickBehaviours.Default)
		{
			_selectBehaviour = selectBehaviour ?? new DefaultSelectBehaviour(this);
		}
Пример #10
0
 /// <summary>
 /// Get a element which is not defined in the pageobject, because it is dynamically generated some time later after the page has loaded.
 /// DO NOT USE FOR REGULAR OBJECTS THAT COULD BE DEFINED IN THE PAGEOBJECT!
 /// </summary>
 /// <typeparam name="T">The type of the requested pageobject. E.g. <see cref="Link"/>.</typeparam>
 /// <param name="findBy">The locator object.</param>
 /// <param name="waitModel">The wait-model for the requested dynamic element.</param>
 /// <param name="clickBehaviour">The ClickBehaviour.</param>
 /// <returns>T</returns>
 public T GetDynamicElement <T>(By findBy, WaitModel waitModel = null, ClickBehaviours clickBehaviour = ClickBehaviours.Default) where T : BasicPageElement
 {
     return((T)PageObjectFactory.CreateElementObject(typeof(T), _driver, findBy, waitModel ?? new WaitModel(), this, clickBehaviour));
 }