IClickable IClickBehaviourFactory.Create(ClickBehaviours clickBehaviour, BasicPageElement pageElement)
		{
			switch (clickBehaviour)
			{
				case ClickBehaviours.Default:
					return new DefaultClickBehaviour(pageElement);
				case ClickBehaviours.ClickWithoutScrolling:
					return new ClickElementWithoutScrollingBehaviour(pageElement);
				default:
					throw new Exception("Unknown clickBehaviour. RegTesting.Logic.ClickBehaviourFactory does not know the ClickBehaviour '" + clickBehaviour + "'.");
			}
		}
Beispiel #2
0
        public static IClickable Create(ClickBehaviours clickBehaviour, BasicPageElement pageElement)
        {
            switch (clickBehaviour)
            {
            case ClickBehaviours.Default:
                return(new DefaultClickBehaviour(pageElement));

            case ClickBehaviours.ClickWithoutScrolling:
                return(new ClickElementWithoutScrollingBehaviour(pageElement));

            default:
                throw new Exception("Unknown clickBehaviour. RegTesting.Logic.ClickBehaviourFactory does not know the ClickBehaviour '" + clickBehaviour + "'.");
            }
        }
Beispiel #3
0
 public DerivedBasicPageElement(By byLocator, IWebDriver webDriver, WaitModel waitModel, BasePageObject parentPageObject, ClickBehaviours clickBehaviour = ClickBehaviours.Default) : base(byLocator, webDriver, waitModel, parentPageObject, clickBehaviour)
 {
 }
		public DerivedImage(By byLocator, IWebDriver webDriver, WaitModel waitModel, BasePageObject parentPageObject, ClickBehaviours clickBehaviour = ClickBehaviours.Default) : base(byLocator, webDriver, waitModel, parentPageObject, clickBehaviour)
		{
		}
Beispiel #5
0
		public Link(By objBy, IWebDriver webDriver, WaitModel waitModel, BasePageObject parentPageObject, ClickBehaviours clickBehaviour = ClickBehaviours.Default)
			: base(objBy, webDriver, waitModel, parentPageObject, clickBehaviour)
		{
		}
 /// <summary>
 /// Construct a new BasicPageElement
 /// </summary>
 /// <param name="objBy">The By Locator.</param>
 /// <param name="webDriver">The WebDriver.</param>
 /// <param name="waitModel">Wait-Options for this element.</param>
 /// <param name="parentPageObject">The <see cref="BasePageObject"/> this <see cref="BasicPageElement"/> belongs to.</param>
 /// <param name="clickBehaviour">The ClickBehaviour.</param>
 public BasicPageElement(By byLocator, IWebDriver webDriver, WaitModel waitModel, BasePageObject parentPageObject, ClickBehaviours clickBehaviour = ClickBehaviours.Default)
 {
     _waitAfterClick      = waitModel.WaitAfterAction == 0 ? TimeSpan.Zero : new TimeSpan(0, 0, 0, 0, waitModel.WaitAfterAction);
     _waitBeforeClick     = waitModel.WaitBeforeAction == 0 ? TimeSpan.Zero : new TimeSpan(0, 0, 0, 0, waitModel.WaitBeforeAction);
     _elementsBeforeClick = waitModel.WaitForElementsBeforeAction;
     _elementsAfterClick  = waitModel.WaitForElementsAfterAction;
     By               = byLocator;
     WebDriver        = webDriver;
     ParentPageObject = parentPageObject;
     ClickBehaviour   = TestContext.ClickBehaviourFactory.Create(clickBehaviour, this);
 }
 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);
 }
        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);
                    }
                }
            }
        }
Beispiel #9
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);
 }
        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);
        }
Beispiel #11
0
 public DerivedLink(By objBy, IWebDriver webDriver, WaitModel waitModel, BasePageObject parentPageObject, ClickBehaviours clickBehaviour = ClickBehaviours.Default) : base(objBy, webDriver, waitModel, parentPageObject, clickBehaviour)
 {
 }
		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)
		{
		}
Beispiel #13
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)
 {
 }
Beispiel #14
0
 public Button(By byLocator, IWebDriver webDriver, WaitModel waitModel, BasePageObject parentBasePageObject, ClickBehaviours clickBehaviour = ClickBehaviours.Default)
     : base(byLocator, webDriver, waitModel, parentBasePageObject, clickBehaviour)
 {
 }
Beispiel #15
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);
		}
Beispiel #16
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));
 }