private T To <T>(T pageObject, GoOptions options) where T : PageObject <T> { if (context.PageObject is null) { pageObject = pageObject ?? ActivatorEx.CreateInstance <T>(); context.PageObject = pageObject; if (!string.IsNullOrWhiteSpace(options.Url)) { ToUrl(options.Url); } pageObject.NavigateOnInit = options.Navigate; pageObject.Init(); return(pageObject); } else { IPageObject currentPageObject = (IPageObject)context.PageObject; T newPageObject = currentPageObject.GoTo(pageObject, options); context.PageObject = newPageObject; return(newPageObject); } }
private static T To <T>(T pageObject, GoOptions options) where T : PageObject <T> { if (AtataContext.Current == null) { AtataContext.Build().SetUp(); } if (AtataContext.Current.PageObject == null) { pageObject = pageObject ?? ActivatorEx.CreateInstance <T>(); AtataContext.Current.PageObject = pageObject; if (!string.IsNullOrWhiteSpace(options.Url)) { ToUrl(options.Url); } pageObject.NavigateOnInit = options.Navigate; pageObject.Init(); return(pageObject); } else { IPageObject currentPageObject = (IPageObject)AtataContext.Current.PageObject; T newPageObject = currentPageObject.GoTo(pageObject, options); AtataContext.Current.PageObject = newPageObject; return(newPageObject); } }
public static TComponentPart CreateComponentPart <TComponentPart, TOwner>(UIComponent <TOwner> parentComponent, string name, params Attribute[] attributes) where TComponentPart : UIComponentPart <TOwner> where TOwner : PageObject <TOwner> { parentComponent.CheckNotNull(nameof(parentComponent)); name.CheckNotNull(nameof(name)); TComponentPart componentPart = ActivatorEx.CreateInstance <TComponentPart>(); componentPart.Component = parentComponent; componentPart.ComponentPartName = name; attributes = attributes?.Where(x => x != null).ToArray() ?? new Attribute[0]; if (componentPart is ISupportsMetadata supportsMetadata) { supportsMetadata.Metadata = CreateComponentMetadata( parentComponent, name, supportsMetadata.ComponentType, attributes); string nameFromMetadata = GetControlNameFromNameAttribute(supportsMetadata.Metadata); if (nameFromMetadata != null) { componentPart.ComponentPartName = nameFromMetadata; } } return(componentPart); }
private static void InitComponentPartProperty <TOwner>(UIComponent <TOwner> parentComponent, PropertyInfo property) where TOwner : PageObject <TOwner> { UIComponentPart <TOwner> componentPart = (UIComponentPart <TOwner>)ActivatorEx.CreateInstance(property.PropertyType); componentPart.Component = parentComponent; componentPart.ComponentPartName = property.Name.ToString(TermCase.MidSentence); if (componentPart is ISupportsMetadata supportsMetadata) { supportsMetadata.Metadata = CreateStaticControlMetadata(parentComponent, property, supportsMetadata.ComponentType); string nameFromMetadata = GetControlNameFromNameAttribute(supportsMetadata.Metadata); if (nameFromMetadata != null) { componentPart.ComponentPartName = nameFromMetadata; } } if (componentPart is IClearsCache cacheClearableComponentPart) { parentComponent.CacheClearableComponentParts.Add(cacheClearableComponentPart); } property.SetValue(parentComponent, componentPart, null); }
/// <inheritdoc/> public object Create(Type type, Dictionary <string, object> valuesMap, Dictionary <string, string> alternativeParameterNamesMap) { type.CheckNotNull(nameof(type)); valuesMap.CheckNotNull(nameof(valuesMap)); alternativeParameterNamesMap.CheckNotNull(nameof(alternativeParameterNamesMap)); if (!valuesMap.Any()) { return(ActivatorEx.CreateInstance(type)); } string[] parameterNamesWithAlternatives = valuesMap.Keys .Concat(GetAlternativeParameterNames(valuesMap.Keys, alternativeParameterNamesMap)) .ToArray(); ConstructorInfo constructor = FindMostAppropriateConstructor(type, parameterNamesWithAlternatives); var workingValuesMap = new Dictionary <string, object>(valuesMap); object instance = CreateInstanceViaConstructorAndRemoveUsedValues( constructor, workingValuesMap, alternativeParameterNamesMap); objectMapper.Map(workingValuesMap, instance); return(instance); }
public static ILogConsumer Resolve(string typeNameOrAlias) { typeNameOrAlias.CheckNotNullOrWhitespace(nameof(typeNameOrAlias)); return(AliasFactoryMap.TryGetValue(typeNameOrAlias, out Func <ILogConsumer> factory) ? factory() : ActivatorEx.CreateInstance <ILogConsumer>(typeNameOrAlias)); }
private static void InitComponentPartProperty <TOwner>(UIComponent <TOwner> parentComponent, PropertyInfo property) where TOwner : PageObject <TOwner> { UIComponentPart <TOwner> componentPart = (UIComponentPart <TOwner>)ActivatorEx.CreateInstance(property.PropertyType); componentPart.Component = parentComponent; property.SetValue(parentComponent, componentPart, null); }
private T GoToFollowingPageObject <T>( UIComponent currentPageObject, T nextPageObject, GoOptions options) where T : PageObject <T> { bool isReturnedFromTemporary = TryResolvePreviousPageObjectNavigatedTemporarily(ref nextPageObject); nextPageObject = nextPageObject ?? ActivatorEx.CreateInstance <T>(); if (!isReturnedFromTemporary) { if (!options.Temporarily) { _context.CleanUpTemporarilyPreservedPageObjectList(); } nextPageObject.NavigateOnInit = options.Navigate; if (options.Temporarily) { nextPageObject.IsTemporarilyNavigated = options.Temporarily; _context.TemporarilyPreservedPageObjectList.Add(currentPageObject); } } ((IPageObject)currentPageObject).DeInit(); _context.PageObject = nextPageObject; // TODO: Review this condition. if (!options.Temporarily) { UIComponentResolver.CleanUpPageObject(currentPageObject); } if (!string.IsNullOrWhiteSpace(options.Url)) { Go.ToUrl(options.Url); } if (!string.IsNullOrWhiteSpace(options.WindowName)) { ((IPageObject)currentPageObject).SwitchToWindow(options.WindowName); } if (isReturnedFromTemporary) { _context.Log.Info("Go to {0}", nextPageObject.ComponentFullName); } else { nextPageObject.PreviousPageObject = currentPageObject; nextPageObject.Init(); } return(nextPageObject); }
private static UIComponent <TOwner> CreateComponent <TOwner>(UIComponent <TOwner> parentComponent, UIComponentMetadata metadata) where TOwner : PageObject <TOwner> { UIComponent <TOwner> component = (UIComponent <TOwner>)ActivatorEx.CreateInstance(metadata.ComponentType); InitComponent(component, parentComponent, metadata); Resolve(component); return(component); }
TOther IPageObject.GoTo <TOther>(TOther pageObject, GoOptions options) { bool isReturnedFromTemporary = TryResolvePreviousPageObjectNavigatedTemporarily(ref pageObject); pageObject = pageObject ?? ActivatorEx.CreateInstance <TOther>(); if (!isReturnedFromTemporary) { if (!options.Temporarily) { AtataContext.Current.CleanUpTemporarilyPreservedPageObjectList(); } pageObject.NavigateOnInit = options.Navigate; if (options.Temporarily) { pageObject.IsTemporarilyNavigated = options.Temporarily; AtataContext.Current.TemporarilyPreservedPageObjectList.Add(this); } } ExecuteTriggers(TriggerEvents.DeInit); // TODO: Review that condition. if (!options.Temporarily) { UIComponentResolver.CleanUpPageObject(this); } if (!string.IsNullOrWhiteSpace(options.Url)) { Go.ToUrl(options.Url); } if (!string.IsNullOrWhiteSpace(options.WindowName)) { SwitchTo(options.WindowName); } if (isReturnedFromTemporary) { Log.Info("Go to {0}", pageObject.ComponentFullName); } else { pageObject.PreviousPageObject = this; pageObject.Init(); } return(pageObject); }
public void Log(LogEventInfo eventInfo) { dynamic otherEventInfo = ActivatorEx.CreateInstance(logEventInfoType); otherEventInfo.TimeStamp = eventInfo.Timestamp; otherEventInfo.Level = logLevelsMap[eventInfo.Level]; otherEventInfo.Message = eventInfo.Message; otherEventInfo.Exception = eventInfo.Exception; otherEventInfo.Properties["build-start"] = eventInfo.BuildStart; otherEventInfo.Properties["test-name"] = eventInfo.TestName; otherEventInfo.Properties["test-start"] = eventInfo.TestStart; logger.Log(otherEventInfo); }
private T GoToInitialPageObject <T>(T pageObject, GoOptions options) where T : PageObject <T> { pageObject = pageObject ?? ActivatorEx.CreateInstance <T>(); _context.PageObject = pageObject; if (!string.IsNullOrWhiteSpace(options.Url)) { ToUrl(options.Url); } pageObject.NavigateOnInit = options.Navigate; pageObject.Init(); return(pageObject); }
private static void InitComponentPartProperty <TOwner>(UIComponent <TOwner> parentComponent, PropertyInfo property) where TOwner : PageObject <TOwner> { UIComponentPart <TOwner> componentPart = (UIComponentPart <TOwner>)ActivatorEx.CreateInstance(property.PropertyType); componentPart.Component = parentComponent; componentPart.ComponentPartName = property.Name.ToString(TermCase.MidSentence); if (componentPart is ISupportsMetadata supportsMetadata) { supportsMetadata.Metadata = CreateStaticControlMetadata(parentComponent, property, supportsMetadata.ComponentType); } property.SetValue(parentComponent, componentPart, null); }
/// <summary> /// Adds the created instance of <paramref name="eventHandlerType"/> as a subscription to the event type /// that is read from <see cref="IEventHandler{TEvent}"/> generic argument that <paramref name="eventHandlerType"/> should implement. /// </summary> /// <param name="eventHandlerType">Type of the event handler.</param> /// <returns>The same <see cref="EventSubscriptionsAtataContextBuilder"/> instance.</returns> public EventSubscriptionsAtataContextBuilder Add(Type eventHandlerType) { eventHandlerType.CheckNotNull(nameof(eventHandlerType)); Type expectedInterfaceType = typeof(IEventHandler <>); Type eventHanderType = eventHandlerType.GetGenericInterfaceType(expectedInterfaceType) ?? throw new ArgumentException($"'{nameof(eventHandlerType)}' of {eventHandlerType.FullName} type doesn't implement {expectedInterfaceType.FullName}.", nameof(eventHandlerType)); Type eventType = eventHanderType.GetGenericArguments()[0]; var eventHandler = ActivatorEx.CreateInstance(eventHandlerType); return(Add(eventType, eventHandler)); }
private static void InitComponentPartProperty <TOwner>(UIComponent <TOwner> parentComponent, PropertyInfo property) where TOwner : PageObject <TOwner> { UIComponentPart <TOwner> componentPart = (UIComponentPart <TOwner>)ActivatorEx.CreateInstance(property.PropertyType); componentPart.Component = parentComponent; ISupportsDeclaredAttributes supportsDeclaredAttributes = componentPart as ISupportsDeclaredAttributes; if (supportsDeclaredAttributes != null) { supportsDeclaredAttributes.DeclaredAttributes.AddRange(GetPropertyAttributes(property)); } property.SetValue(parentComponent, componentPart, null); }
/// <summary> /// Adds the created instance of <paramref name="eventHandlerType"/> as a subscription to the <paramref name="eventType"/>. /// </summary> /// <param name="eventType">Type of the event.</param> /// <param name="eventHandlerType">Type of the event handler.</param> /// <returns>The same <see cref="EventSubscriptionsAtataContextBuilder"/> instance.</returns> public EventSubscriptionsAtataContextBuilder Add(Type eventType, Type eventHandlerType) { eventType.CheckNotNull(nameof(eventType)); eventHandlerType.CheckNotNull(nameof(eventHandlerType)); Type expectedType = typeof(IEventHandler <>).MakeGenericType(eventType); if (!expectedType.IsAssignableFrom(eventHandlerType)) { throw new ArgumentException($"'{nameof(eventHandlerType)}' of {eventHandlerType.FullName} type doesn't implement {expectedType.FullName}.", nameof(eventHandlerType)); } var eventHandler = ActivatorEx.CreateInstance(eventHandlerType); return(Add(eventType, eventHandler)); }
public void Log(LogEventInfo eventInfo) { dynamic otherEventInfo = ActivatorEx.CreateInstance(logEventInfoType); otherEventInfo.TimeStamp = eventInfo.Timestamp; otherEventInfo.Level = logLevelsMap[eventInfo.Level]; otherEventInfo.Message = eventInfo.Message; otherEventInfo.Exception = eventInfo.Exception; var properties = (IDictionary <object, object>)otherEventInfo.Properties; properties["build-start"] = eventInfo.BuildStart; properties["test-name"] = eventInfo.TestName; properties["test-start"] = eventInfo.TestStart; properties["driver-alias"] = eventInfo.DriverAlias; logger.Log(otherEventInfo); }
public FindAttribute CreateFindAttribute() { return((FindAttribute)ActivatorEx.CreateInstance(FindAttributeType)); }