using System; using System.Collections.Generic; using Xamarin.UITest; using Xamarin.UITest.Android; using Xamarin.UITest.iOS; using System.Linq; namespace Xamarin.Forms.Core.UITests { internal static class ViewInspector { public static void LogPropertiesForView (this IApp app, string query, bool isOnParent = false) { if (app is AndroidApp) { LogPropertiesForAndroidView ((AndroidApp)app, query, isOnParent); } else { LogPropertiesForUIView ((iOSApp)app, query, isOnParent); LogPropertiesForCALayer ((iOSApp)app, query, isOnParent); } } static void LogPropertiesForUIView (this iOSApp app, string query, bool isOnParent = false) { //Logger.LogLine ("--- UIView Properties ---"); var properties = new [] { // just getters with no params, bools "alpha", "autoresizesSubviews", "autoresizingMask", "backgroundColor", "bounds", "center", "clearsContextBeforeDrawing", "clipsToBounds", "contentMode", "contentScaleFactor", "exclusiveTouch", "frame", "gestureRecognizers", "hidden", "layer", "motionEffects", "multipleTouchEnabled", "opaque", "restorationIdentifier", "subviews", "superview", "tag", "tintAdjustmentMode", "tintColor", "transform", "userInteractionEnabled", "window" }; if (isOnParent) query = query + " parent * index:0"; foreach (var property in properties) { object prop; bool found = MaybeGetProperty (app, query, property, out prop) || MaybeGetProperty (app, query, property, out prop) || MaybeGetProperty (app, query, property, out prop) || MaybeGetProperty (app, query, property, out prop); //if (found) // Logger.LogLine (string.Format ("{0,-30}: {1}", property, prop)); } //Logger.LogLine(); } static void LogPropertiesForCALayer(this iOSApp app, string query, bool isOnParent = false) { // Logger.LogLine ("--- UIView.Layer Properties ---"); var properties = new[] { "actions", "anchorPoint", "anchorPointZ", "backgroundColor", "backgroundFilters", "borderColor", "borderWidth", "bounds", "compositingFilter", "contents", "contentsCenter", "contentsGravity", "contentsRect", "contentsScale", "cornerRadius", "delegate", "doubleSided", "drawsAsynchronously", "edgeAntialiasingMask", "filters", "frame", "geometryFlipped", "hidden", "magnificationFilter", "mask", "masksToBounds", "minificationFilter", "minificationFilterBias", "name", "needsDisplayOnBoundsChange", "opacity", "opaque", "position", "rasterizationScale", "shadowColor", "shadowOffset", "shadowOpacity", "shadowPath", "shadowRadius", "shouldRasterize", "style", "sublayers", "sublayerTransform", "superlayer", "transform", "visibleRect", "zPosition" }; if (isOnParent) query = query + " parent * index:0"; foreach (var property in properties) { object prop; bool found = MaybeGetLayerProperty(app, query, property, out prop) || MaybeGetLayerProperty(app, query, property, out prop) || MaybeGetLayerProperty(app, query, property, out prop); //if (found) // Logger.LogLine(string.Format("{0,-30}: {1}", property, prop)); } //Logger.LogLine(); } static void LogPropertiesForAndroidView (this AndroidApp app, string query, bool isOnParent = false) { // Logger.LogLine( "--- Android View Properties ---"); var properties = new [] { // just getters with no params, bools //"getAccessibilityLiveRegion", //"getAccessibilbityNodeProvider", //"getAlpha", //"getAnimation", //"getApplicationWindowToken", //"getBackground", //"getBaseline", //"getBottom", //"getCameraDistance", //"getClipBounds", //"getContentDescription", //"getContext", //"getDefaultSize", //"getDisplay", //"getDrawableState", //"getDrawingCache", //"getDrawingCacheBackgroundColor", //"getDrawingRect", //"getDrawingTime", //"getFilterTouchesWhenObscurred", //"getFitsSystemWindows", //"getFocusables", //"getHandler", //"getHeight", //"getHitRect", //"getHorizontalFadingEdgeLength", //"getId", //"getImportantForAccessibility", //"getKeepScreenOn", //"getKeyDispatcherState", //"getLabelFor", //"getLayerType", //"getLayoutDirection", //"getLayourParams", //"getLeft", "getMatrix", //"getMeasuredHeight", //"getMeasuredHeightAndState", //"getMeasuredState", //"getMeasuredWidth", //"getMeasuredWidthAndState", //"getMinimumHeight", //"getMinimumWidth", //"getNextFocusDownId", //"getNextFocusForwardId", //"getNextFocusLeftId", //"getNextFocusRightId", //"getNextFocusUpId", //"getOnFocusChangedListener", //"getOverScrollMethod", //"getOverlay", //"getPaddingBottom", //"getPaddingEnd", //"getPaddingLeft", //"getPaddingRight", //"getPaddingStart", //"getPaddingTop", //"getParent", //"getParentForAccessibility", //"getPivotX", //"getPivotY", //"getResources", //"getRight", //"getRootView", //"getRotation", //"getRotationX", //"getRotationY", "getScaleX", "getScaleY", //"getScrollBarDefaultDelayBeforeFade", //"getScrollBarFadeDuration", //"getScrollBarSize", //"getScrollBarStyle", //"getScrollX", //"getScrollY", //"getSolidColor", //"getSystemUiVisibility", //"getTag", //"getTextAlignment", //"getTextDirection", //"getTop", //"getTouchDelegate", //"getTouchables", //"getTranslationX", //"getTranslationY", //"getVerticalFadingEdgeLength", //"getVerticalScrollbarPosition", //"getVerticalScrollbarWidth", //"getViewTreeObserver", //"getVisibility", //"getWidth", //"getWindowId", //"getWindowSystemUiVisbility", //"getWindowToken", //"getWindowVisibility", //"getX", //"getY", //"hasFocus", //"hasFocusable", //"hasOnClickListener", //"hasOverlappingRendering", //"hasTransientState", //"hasWindowFocus", //"isActivated", //"isAttachedToWindow", //"isClickable", //"isDirty", //"isDrawingCacheEnabled", //"isDuplicateParentStateEnabled", //"isEnabled", //"isFocusable", //"isFocusableInTouchWindow", //"isFocused", //"isHapticFeedbackEnabled", //"isHardwareAccelerated", //"isHorizontalFadingEdgeEnabled", //"isHovered", //"idInEditMode", //"isInLayout", //"isInTouchMode", //"isLaidOut", //"isLayoutDirectionResolved", //"isLayoutRequested", //"isLongClickable", //"isOpaque", //"isPaddingRelative", //"isPressed", //"isSaveEnabled", //"isSaveFromParentEnabled", //"isScrollContainer", //"isScrollBarFadingEnabled", //"isSelected", //"isShown", //"isSoundEffectsEnabled", //"isTextAlignmentResolved", //"isTextDirectionResolved", //"isVerticalFadingEdgeEnabled", //"isVerticalScrollBarEnabled" }; if (isOnParent) query = query + " parent * index:0"; foreach (var property in properties) { object prop; bool found = MaybeGetProperty (app, query, property, out prop) || //MaybeGetProperty (app, query, property, out prop) || MaybeGetProperty (app, query, property, out prop) || MaybeGetProperty (app, query, property, out prop); //if (found) // Logger.LogLine (string.Format ("{0,-30}: {1}", property, prop)); } //Logger.LogLine(); } static bool MaybeGetLayerProperty (iOSApp app, string query, string property, out object result) { try { result = app.Query (q => q.Raw (query).Invoke ("layer").Invoke (property).Value ()).First (); } catch { result = null; return false; } return true; } static bool MaybeGetProperty (IApp app, string query, string property, out object result) { try { result = app.Query (q => q.Raw (query).Invoke (property).Value ()).First (); } catch { result = null; return false; } return true; } } }