Repository navigation
[Power BI] Validate PBIT templates automatically - #2396
Open
Michael Flanakin (flanakin) wants to merge 2 commits into
Open
Michael Flanakin (flanakin) wants to merge 2 commits into
Michael Flanakin (flanakin) wants to merge 2 commits into
Conversation
…sktop Add PowerBITemplates unit tests that read each built PBIT and check the parameters, empty data sources, demo strings, tables, and gzip support, and skip when the templates are not built. Add Test-PowerBITemplates, which opens each PBIT in Power BI Desktop on Windows and checks the parameter prompt, and a -ValidateTemplates switch on Package-PowerBI to run it. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Michael Flanakin (flanakin)
force-pushed
the
flanakin/pbit-validation
branch
from
October 29, 2026 02:08
dddae20 to
06e72fa
Compare
Roland Krummenacher (RolandKrummenacher)
left a comment
Collaborator
There was a problem hiding this comment.
The static checks look sound, and CI is green. CI only tests the "nothing built" skip path, though; the built path has only run on the author's Windows machine.
…ic eventhouse URIs Co-Authored-By: RolandKrummenacher <RolandKrummenacher@users.noreply.github.com> Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replaces the manual "open each of the 12 Power BI templates in Power BI Desktop, check for errors, and read the parameter prompt" release check with two repeatable layers.
1. Static layer (any platform):
src/powershell/Tests/Unit/PowerBITemplates.Tests.ps1Opens each built PBIT, detects the encoding of
DataModelSchema(UTF-16LE with or without BOM, or UTF-8), and checks:.kqland 6.storagetemplates exist, one per report inreports.json. The two release ZIP files hold the same six each.reports.jsonfor the report (limited to tables that exist in that model type, likePricesonly existing for storage).expressions.tmdl), except the data source URLs, which must benull. This covers the storage defaults (Number of Months 3, Default Granularity Daily, both FALSE flags), the KQL defaults (Number of Months 13), andRemove Duplicate Resource IDsonly wherereports.jsonkeeps it. Values are read from the source rather than hard-coded.ftk_DemoFilteris the empty version, and no storage account or cluster name is hard-coded.ftkdemo/ftk-demostring appears in any text part of the PBIT..gzfilter ([Extension] = ".gz"plusBinary.Decompress(..., Compression.GZip)) lives in the sharedftk_Storagefunction, not in theCostsquery itself, so the test checks thatCostsreads throughftk_Storage("focuscost")and thatftk_Storagehas the filter.When no templates are built (
release/pbitand the ZIP files are missing) every test is skipped with the command that builds them, so unit CI is unaffected. When some are built, missing or unreadable ones fail. I did not add a build step to CI, becauseBuild-PowerBIinstalls the Analysis Services NuGet package; that is a possible follow-up.2. Windows UI layer:
src/scripts/Test-PowerBITemplates.ps1For each template it launches Power BI Desktop, answers the "Potential security risk" dialog with OK when it shows (KQL), waits for the parameter prompt, fails on any other dialog (for example "Unable to open template"), reads the prompt, and ends only the Power BI Desktop process it started. It checks that the prompt is titled after the template, lists the expected parameters in order with the expected values (derived from the parameters in the PBIT itself), has empty Storage URL, Cluster URL, RangeStart, and RangeEnd fields, and doesn't mention a demo hub. It saves a screenshot per template to
release/pbit-test.Package-PowerBI -ValidateTemplates(off by default, one parameter and one block) runs it before packaging.Save-PowerBIProject.ps1is unchanged.Why UI Automation was not enough, and what is used instead. I investigated before falling back to screenshots. Power BI Desktop shows the security dialog and the parameter prompt in an embedded browser control (
Internet Explorer_Server). UI Automation lists only the main window for the process;AutomationElement.FromHandleon the dialog gives four unnamed panes and nothing inside the browser control. The dialogs are found from Windows' own window list (the window title is the dialog title), and the page is read throughWM_HTML_GETOBJECTand the browser control's HTML document, which is what screen readers use. That gives the real parameter names and values, and buttons are pressed through the page, so no mouse or keyboard input is needed (verified: the DOMclick()answers the security dialog). Pass/fail therefore rests on the actual prompt contents, not on screenshots. The screenshots are evidence only. I reused the approach ofSave-PowerBIProject.ps1(Win32 window listing, process-scoped cleanup, screenshot on failure) but did not move its helpers into a shared file: I couldn't safely regression-test that 1200-line script, and the issue asked for its behavior to stay unchanged. Sharing the helpers is a reasonable follow-up.Why not Playwright. Power BI Desktop is a native WinForms/WPF app with embedded browser controls, not a web page or an Electron/WebView2 app Playwright can attach to.
What it cannot check.
o-group-fieldTemplate). A Power BI Desktop update that changes the prompt's markup would make it fail with "prompt did not appear", and the selectors would need updating.Default Granularityparameter's current value is"Monthly"withDefaultValue="Daily". The prompt shows the default (Daily), which is what is checked. I didn't change that.What was run
Test-PowerShell -Lint: 3970 of 3970 passed.PowerBITemplates.Tests.ps1andBuild-PowerBI.Tests.ps1with Pester 6.2.0, after building withBuild-PowerBI -NoPbip: 169 passed, 0 failed, 6 skipped (the gzip test is skipped for the 6 KQL templates by design).releasemoved away: all skipped with the build message (1 passed, 124 skipped). With only the two ZIP files present: pass.Test-PowerBITemplates.ps1on all 12 built templates, once at the end, on Windows with Power BI Desktop 2.159 from the Microsoft Store: 12 of 12 passed (about 30 seconds each, 5.7 minutes total, security dialog answered for all 6 KQL templates). No Power BI Desktop processes were left running.PSScriptAnalyzer: only the warnings the existing scripts also have (Write-Host,ShouldProcessonStop-Desktop, BOM).Not run:
Package-PowerBI -ValidateTemplatesend to end (it needs saved demo PBIX files; the code path is a single call to the script above), the static tests on Linux CI, and a second Power BI Desktop version.Changelog
No changelog entry. This is a maintainer-facing validation script and tests, not a user-facing change under the changelog standard.
🤖 Generated with Claude Code