internal static async Task<bool> MatchTreeDumpFromLayoutUpdateAsync(string dumpID, string uiaId, TextBlock textBlock, IList<string> additionalProperties, DumpTreeMode mode, string dumpExpectedText) { // First find root DependencyObject current = textBlock; DependencyObject parent = VisualTreeHelper.GetParent(current); while (parent != null) { current = parent; parent = VisualTreeHelper.GetParent(current); } DependencyObject dumpRoot = current; // if UIAID is passed in from test, find the matching child as the root to dump if (uiaId != null) { var matchingNode = TreeDumpHelper.FindChildWithMatchingUIAID(current, uiaId); if (matchingNode != null) { dumpRoot = matchingNode; } } string dumpText = VisualTreeDumper.DumpTree(dumpRoot, textBlock, additionalProperties, mode); if (dumpText != dumpExpectedText) { return await MatchDump(dumpText, GetMasterFile(dumpID), GetOutputFile(dumpID)); } return true; }
public static async Task<bool> MatchDump(string outputJson, string masterFileRelativePath, string outputFileRelativePath) { Debug.WriteLine($"master file = {Windows.ApplicationModel.Package.Current.InstalledLocation.Path}\\Assets\\{masterFileRelativePath}"); StorageFolder storageFolder = ApplicationData.Current.LocalFolder; Debug.WriteLine($"output file = {storageFolder.Path + "\\" + outputFileRelativePath}"); StorageFile outFile = await storageFolder.CreateFileAsync(outputFileRelativePath, CreationCollisionOption.ReplaceExisting); await FileIO.WriteTextAsync(outFile, outputJson); StorageFile masterFile = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync($@"Assets\{masterFileRelativePath}"); string masterJson = await FileIO.ReadTextAsync(masterFile); if (!TreeDumpHelper.DumpsAreEqual(masterJson, outputJson)) { return false; } else { return true; } }
public static IAsyncOperation <bool> DoesTreeDumpMatchForRNTester(DependencyObject root) { string json = DumpTree(root, null, new string[] { }, DumpTreeMode.Json); try { var obj = JsonValue.Parse(json).GetObject(); var element = FindElementByAutomationId(obj, "PageHeader"); if (element == null) { return(Task.Run(() => false).AsAsyncOperation()); } var value = element.GetNamedString("Text"); var pageName = new Regex(@"[<|>]").Replace(value, ""); var match = TreeDumpHelper.MatchDump(json, pageName); return(match.AsAsyncOperation()); } catch { Debug.WriteLine("JSON ERROR:\n" + json); throw; } }
private async void dispatcherTimer_Tick(object sender, object e) { m_timer.Stop(); if (VisualTreeHelper.GetParent(m_textBlock) != null) { var matchSuccessful = await TreeDumpHelper.MatchTreeDumpFromLayoutUpdateAsync(m_dumpID, m_uiaID, m_textBlock, m_additionalProperties, DumpTreeMode.Json, m_dumpExpectedText); if (!matchSuccessful) { StorageFolder storageFolder = ApplicationData.Current.LocalFolder; StorageFile outFile = await storageFolder.GetFileAsync(TreeDumpHelper.GetOutputFile(m_dumpID)); StorageFile masterFile = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync($@"Assets\{TreeDumpHelper.GetMasterFile(m_dumpID)}"); UpdateResult(false /*matchDump*/, $"Tree dump file does not match master at {masterFile.Path} - See output at {outFile.Path}", GetInlines(masterFile, outFile, m_textBlock)); } else { UpdateResult(true /*matchDump*/, ""); } } }