From a31ed06b100f23780aba4852bae10932115a6a33 Mon Sep 17 00:00:00 2001 From: Aleksandr Chebotov <47745270+al-cheb@users.noreply.github.com> Date: Thu, 10 Feb 2022 18:10:43 +0300 Subject: [PATCH] [macOS] Add test to check opened windows (#5052) * Add test to check opened windows * Move check before xcode * Move check after homebrew * Exclude NotificationCenter * Update pester test --- .../provision/core/open_windows_check.sh | 21 +++++++++++++++++++ images/macos/templates/macOS-10.15.json | 1 + images/macos/templates/macOS-11.json | 1 + images/macos/templates/macOS-11.pkr.hcl | 1 + images/macos/templates/macOS-12.json | 1 + images/macos/tests/System.Tests.ps1 | 8 +++++++ 6 files changed, 33 insertions(+) create mode 100644 images/macos/provision/core/open_windows_check.sh diff --git a/images/macos/provision/core/open_windows_check.sh b/images/macos/provision/core/open_windows_check.sh new file mode 100644 index 00000000..1392e065 --- /dev/null +++ b/images/macos/provision/core/open_windows_check.sh @@ -0,0 +1,21 @@ +#!/bin/bash -e -o pipefail + +openwindows=$(osascript -e 'tell application "System Events" to get every window of (every process whose class of windows contains window)') +IFS=',' read -r -a windowslist <<< "$openwindows" + +if [ -n "${openwindows}" ]; then + echo "Found opened window:" +fi + +for window in "${windowslist[@]}"; do + if [[ $window =~ "NotificationCenter" ]]; then + echo "[Warning] $window" + else + echo " - ${window}" | xargs + scripterror=true + fi +done + +if [ "${scripterror}" = true ]; then + exit 1 +fi diff --git a/images/macos/templates/macOS-10.15.json b/images/macos/templates/macOS-10.15.json index c55bb3f5..cc67e74c 100644 --- a/images/macos/templates/macOS-10.15.json +++ b/images/macos/templates/macOS-10.15.json @@ -131,6 +131,7 @@ "scripts": [ "./provision/core/xcode-clt.sh", "./provision/core/homebrew.sh", + "./provision/core/open_windows_check.sh", "./provision/core/powershell.sh", "./provision/core/dotnet.sh", "./provision/core/python.sh", diff --git a/images/macos/templates/macOS-11.json b/images/macos/templates/macOS-11.json index 082228f7..ed7b80db 100644 --- a/images/macos/templates/macOS-11.json +++ b/images/macos/templates/macOS-11.json @@ -136,6 +136,7 @@ "pause_before": "30s", "scripts": [ "./provision/core/homebrew.sh", + "./provision/core/open_windows_check.sh", "./provision/core/powershell.sh", "./provision/core/dotnet.sh", "./provision/core/python.sh", diff --git a/images/macos/templates/macOS-11.pkr.hcl b/images/macos/templates/macOS-11.pkr.hcl index 774856ec..72bc9d59 100644 --- a/images/macos/templates/macOS-11.pkr.hcl +++ b/images/macos/templates/macOS-11.pkr.hcl @@ -135,6 +135,7 @@ build { pause_before = "30s" scripts = [ "./provision/core/homebrew.sh", + "./provision/core/open_windows_check.sh", "./provision/core/powershell.sh", "./provision/core/dotnet.sh", "./provision/core/python.sh", diff --git a/images/macos/templates/macOS-12.json b/images/macos/templates/macOS-12.json index b10aa4fa..8c54b7c1 100644 --- a/images/macos/templates/macOS-12.json +++ b/images/macos/templates/macOS-12.json @@ -136,6 +136,7 @@ "pause_before": "30s", "scripts": [ "./provision/core/homebrew.sh", + "./provision/core/open_windows_check.sh", "./provision/core/powershell.sh", "./provision/core/dotnet.sh", "./provision/core/python.sh", diff --git a/images/macos/tests/System.Tests.ps1 b/images/macos/tests/System.Tests.ps1 index f72ba829..ea96602e 100644 --- a/images/macos/tests/System.Tests.ps1 +++ b/images/macos/tests/System.Tests.ps1 @@ -46,3 +46,11 @@ Describe "Screen Resolution" { system_profiler SPDisplaysDataType | Select-String "Resolution" | Should -Match "1176 x 885|1920 x 1080" } } + +Describe "Open windows" { + It "Opened windows not found" { + $cmd = "osascript -e 'tell application \""System Events\"" to get every window of (every process whose class of windows contains window)'" + $openWindows = bash -c $cmd + $openWindows.Split(",").Trim() | Where-Object { $_ -notmatch "NotificationCenter" } | Should -BeNullOrEmpty + } +}