Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
113 commits
Select commit Hold shift + click to select a range
9d3499d
add ui tests to pipeline
BenAlvo1 Jan 6, 2025
2c3091a
add debug check
BenAlvo1 Jan 6, 2025
352119c
Update ci.yml
cx-ben-alvo Jan 6, 2025
684630e
change
BenAlvo1 Jan 6, 2025
58f42a0
change
BenAlvo1 Jan 6, 2025
a1c36d2
check
BenAlvo1 Jan 6, 2025
05dadce
change
BenAlvo1 Jan 6, 2025
7d4dae1
check
BenAlvo1 Jan 6, 2025
6c5c9cc
fail by purpose
BenAlvo1 Jan 6, 2025
5c70541
check
BenAlvo1 Jan 6, 2025
7c9a3b5
fix tests
BenAlvo1 Jan 7, 2025
33daff5
Update CheckmarxTests.cs
cx-ben-alvo Jan 7, 2025
e01feb0
Update CheckmarxTests.cs
cx-ben-alvo Jan 7, 2025
7884b80
Update CheckmarxTests.cs
cx-ben-alvo Jan 7, 2025
2ed0acd
revert
BenAlvo1 Jan 7, 2025
0e979a8
Merge branch 'main' into other/benalvo/add-ui-tests-to-pipeline
cx-ben-alvo Jan 7, 2025
9df3ad5
edit ci.yml ui tests job
BenAlvo1 Jan 7, 2025
85be656
add vstest setup
BenAlvo1 Jan 7, 2025
716a6cd
check
BenAlvo1 Jan 7, 2025
afd50dd
try fix running vs
BenAlvo1 Jan 7, 2025
327905d
try fix
BenAlvo1 Jan 7, 2025
b1c7bd8
check
BenAlvo1 Jan 8, 2025
312a343
check
BenAlvo1 Jan 8, 2025
a03f7bb
add comment
BenAlvo1 Jan 8, 2025
59ab6de
fix
BenAlvo1 Jan 8, 2025
733d6ca
add vstest
BenAlvo1 Jan 8, 2025
86b5d55
check
BenAlvo1 Jan 8, 2025
7c8de5b
change vstest
BenAlvo1 Jan 8, 2025
fa7110c
add waiting time
BenAlvo1 Jan 8, 2025
0642bf8
check
BenAlvo1 Jan 8, 2025
3358ab7
check
BenAlvo1 Jan 8, 2025
c300e12
check
BenAlvo1 Jan 8, 2025
894d289
update
BenAlvo1 Jan 8, 2025
a07fe7e
add installation check
BenAlvo1 Jan 9, 2025
a85a81c
fix compilation
BenAlvo1 Jan 9, 2025
4119913
fix
BenAlvo1 Jan 9, 2025
396f76e
add
BenAlvo1 Jan 9, 2025
7e7303a
check
BenAlvo1 Jan 9, 2025
8528dee
try fix
BenAlvo1 Jan 9, 2025
5364159
try fix
BenAlvo1 Jan 9, 2025
ee190f7
fix
BenAlvo1 Jan 9, 2025
bdd3ee0
check
BenAlvo1 Jan 9, 2025
b566b33
change location of close vs command
BenAlvo1 Jan 9, 2025
cc5216a
check
BenAlvo1 Jan 9, 2025
ef58dbc
fix
BenAlvo1 Jan 9, 2025
59928a7
check
BenAlvo1 Jan 9, 2025
3ca3719
check
BenAlvo1 Jan 9, 2025
738fc27
fix
BenAlvo1 Jan 9, 2025
17d3b90
revert
BenAlvo1 Jan 9, 2025
1e55933
wait for initialization
BenAlvo1 Jan 9, 2025
17090ee
add snap shots
BenAlvo1 Jan 9, 2025
56249fc
remofix compilation
BenAlvo1 Jan 9, 2025
a74de32
fix
BenAlvo1 Jan 9, 2025
faf1bc8
change
BenAlvo1 Jan 12, 2025
8b703ab
remove screen shot
BenAlvo1 Jan 12, 2025
68d2e2c
add dep
BenAlvo1 Jan 12, 2025
047bd0f
test
BenAlvo1 Jan 12, 2025
aa6c2e3
check
BenAlvo1 Jan 12, 2025
515f335
chjeck
BenAlvo1 Jan 12, 2025
789ec07
update
BenAlvo1 Jan 12, 2025
82b3573
check
BenAlvo1 Jan 12, 2025
44b9f40
check
BenAlvo1 Jan 12, 2025
f96eb59
check
BenAlvo1 Jan 12, 2025
4d5cd20
addd
BenAlvo1 Jan 12, 2025
9852552
check
BenAlvo1 Jan 12, 2025
3a9b810
add continue-on-error
BenAlvo1 Jan 12, 2025
fae3857
Revert "check"
BenAlvo1 Jan 12, 2025
ac3a0be
check
BenAlvo1 Jan 12, 2025
0655d9b
fix
BenAlvo1 Jan 12, 2025
824fb72
check
BenAlvo1 Jan 12, 2025
f07c839
check
BenAlvo1 Jan 12, 2025
f4d8a72
check
BenAlvo1 Jan 12, 2025
f0a901e
check
BenAlvo1 Jan 12, 2025
549f9e2
push
BenAlvo1 Jan 12, 2025
13672f9
check
BenAlvo1 Jan 12, 2025
945dcd2
revert
BenAlvo1 Jan 13, 2025
da18a9c
check
BenAlvo1 Jan 13, 2025
d40ac97
check
BenAlvo1 Jan 13, 2025
b05e714
check
BenAlvo1 Jan 13, 2025
2a2a566
check
BenAlvo1 Jan 13, 2025
7a8ea76
add params
BenAlvo1 Jan 13, 2025
6329b75
remove screenshot
BenAlvo1 Jan 13, 2025
87676a8
added script to run UI tests locally
BenAlvo1 Jan 13, 2025
37ccae6
add cd to root
BenAlvo1 Jan 13, 2025
043fd1d
ignoring branch checkout if not specify
BenAlvo1 Jan 13, 2025
26340db
check
BenAlvo1 Jan 13, 2025
f4d2262
check
BenAlvo1 Jan 13, 2025
4c0844d
check
BenAlvo1 Jan 13, 2025
6a0d52f
fix
BenAlvo1 Jan 13, 2025
c370c62
revert
BenAlvo1 Jan 13, 2025
e49289d
check
BenAlvo1 Jan 13, 2025
c5279a2
make powershell script
BenAlvo1 Jan 13, 2025
3903fc1
check
BenAlvo1 Jan 13, 2025
424746b
check
BenAlvo1 Jan 13, 2025
ff13f09
check
BenAlvo1 Jan 13, 2025
61b0338
revert
BenAlvo1 Jan 13, 2025
806f100
check
BenAlvo1 Jan 13, 2025
25008aa
try fix
BenAlvo1 Jan 13, 2025
034842a
make it sync
BenAlvo1 Jan 13, 2025
84f73f6
make it powershell script
BenAlvo1 Jan 13, 2025
4437350
change script extension
BenAlvo1 Jan 14, 2025
1ec7cef
revert
BenAlvo1 Jan 14, 2025
6d108cb
edit script
BenAlvo1 Jan 14, 2025
5fa68de
try fix
BenAlvo1 Jan 14, 2025
4e51f27
check
BenAlvo1 Jan 14, 2025
4c0a9f1
try fix
BenAlvo1 Jan 14, 2025
c49ccc2
check
BenAlvo1 Jan 14, 2025
e2bfe99
check
BenAlvo1 Jan 14, 2025
3c05d78
check
BenAlvo1 Jan 14, 2025
23ab518
check
BenAlvo1 Jan 14, 2025
e9a817a
change fetching branch name logic
BenAlvo1 Jan 14, 2025
4d8f982
check
BenAlvo1 Jan 14, 2025
1214ecf
check
BenAlvo1 Jan 14, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 96 additions & 0 deletions .github/scripts/run-ui-tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
param (
[string]$branchName = ""
)

# Exit script on any error
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"

# Helper function for logging
function Log {
$timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
Write-Host "[$timestamp] $args"
}

# Step 1: Get the branch name and checkout
if ($branchName -eq "") {
Log "No branch name provided. Using the current local branch."
} else {
try {
# Check if the branch exists locally
$localBranchExists = git branch --list $branchName | ForEach-Object { $_.Trim() }

if ($localBranchExists) {
Log "Branch $branchName exists locally. Checking out..."
git checkout $branchName
} else {
# Check if the branch exists on the remote
$remoteBranchExists = git ls-remote --heads origin $branchName | ForEach-Object { $_.Trim() }

if ($remoteBranchExists -ne "") {
Log "Branch $branchName does not exist locally. Checking out from remote..."
git checkout -t "origin/$branchName"
} else {
throw "Branch $branchName does not exist locally or on the remote. Please verify the branch name."
}
}

Log "Pulling latest code..."
git pull
} catch {
Log "Error: $_"
throw "Failed to switch to branch $branchName. Ensure the branch exists locally or remotely."
}
}

# Navigate to the root directory
try {
Set-Location (git rev-parse --show-toplevel)
} catch {
Log "Error: $_"
throw "Failed to navigate to the Git repository root directory."
}

# Step 2: Set up paths for Visual Studio executables
$msbuildPath = "C:/Program Files/Microsoft Visual Studio/2022/Community/MSBuild/Current/Bin/MSBuild.exe"
$vsixInstallerPath = "C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/VSIXInstaller.exe"
$vsTestPath = "C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/TestWindow/vstest.console.exe"

# Validate paths
if (-not (Test-Path $msbuildPath)) { throw "MSBuild executable not found at $msbuildPath" }
if (-not (Test-Path $vsixInstallerPath)) { throw "VSIX Installer not found at $vsixInstallerPath" }
if (-not (Test-Path $vsTestPath)) { throw "VSTest executable not found at $vsTestPath" }

# Step 3: Build the solution
try {
Log "Building solution..."
$solutionPath = "$(Get-Location)/ast-visual-studio-extension.sln"
Start-Process -FilePath $msbuildPath -ArgumentList "`"$solutionPath`"", "/p:Configuration=Release" -Wait -NoNewWindow
} catch {
Log "Error: $_"
throw "Failed to build the solution."
}

# Step 4: Install Checkmarx Extension
try {
Log "Installing Checkmarx Extension..."
$vsixPath = "$(Get-Location)/ast-visual-studio-extension/bin/Release/ast-visual-studio-extension.vsix"
Start-Process -FilePath $vsixInstallerPath -ArgumentList "/quiet", "`"$vsixPath`"" -Wait -NoNewWindow
Start-Sleep -Seconds 20
} catch {
Log "Error: $_"
throw "Failed to install the Checkmarx extension."
}

# Step 5: Run UI Tests
try {
Log "Running UI Tests..."
$testDllPath = "$(Get-Location)/UITests/bin/Release/UITests.dll"
Start-Process -FilePath $vsTestPath -ArgumentList "/InIsolation", "`"$testDllPath`"" -Wait -NoNewWindow
} catch {
Log "Error: $_"
throw "Failed to run UI tests."
}

# Final message
Log "Script execution completed successfully."
44 changes: 42 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,45 @@ jobs:
env:
CX_APIKEY: ${{ secrets.CX_APIKEY }}
run: vstest.console.exe /InIsolation .\ast-visual-studio-extension-tests\bin\Release\net60-windows\ast-visual-studio-extension-tests.dll



UI-tests:
runs-on: windows-latest
steps:
# Step 1: Checkout the repository
- name: Checkout code
uses: actions/checkout@v3

# Step 2: Set up Visual Studio
- name: Set up Visual Studio
uses: microsoft/setup-msbuild@v2
with:
msbuild-architecture: x64

# Step 3: Restore dependencies
- name: Restore NuGet packages
run: nuget restore

# Step 4: Build the solution
- name: Build solution
run: msbuild ast-visual-studio-extension.sln /p:Configuration=Release


# Step 7: Install Checkmarx Extension
- name: Install Checkmarx Extension
run: |
& "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\IDE\VSIXInstaller.exe" /quiet "D:\a\ast-visual-studio-extension\ast-visual-studio-extension\ast-visual-studio-extension\bin\Release\ast-visual-studio-extension.vsix"
Start-Sleep -Seconds 20

# Step 8: Run UI Tests
- name: Run UI Tests
run: |
& "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe" /InIsolation .\UITests\bin\Release\UITests.dll
continue-on-error: true

- name: Upload Descendants File
uses: actions/upload-artifact@v4
with:
name: screenshot
path: ${{ github.workspace }}\Screenshots


156 changes: 90 additions & 66 deletions UITests/BaseTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,90 +2,114 @@
using FlaUI.UIA3;
using FlaUI.Core;
using System;
using System.IO;
using System.Threading.Tasks;
using EnvDTE;
using AutomationWindow = FlaUI.Core.AutomationElements.Window;
using FlaUI.Core.Capturing;

namespace UITests
{
[TestClass]
public class BaseTest
{
protected static UIA3Automation _automation;
protected static Application _app;
protected static AutomationWindow _mainWindow;
protected static DTE _dte;
[TestClass]
public class BaseTest
{
protected static UIA3Automation _automation;
protected static Application _app;
protected static AutomationWindow _mainWindow;
protected static DTE _dte;

[ClassInitialize]
public static void ClassInitialize(TestContext context)
{
// Initialize automation and launch VS
_automation = new UIA3Automation();
_app = Application.Launch("devenv.exe");
[ClassInitialize]
public static void ClassInitialize(TestContext context)
{
// Initialize automation and launch VS
_automation = new UIA3Automation();
_app = Application.Launch("devenv.exe","/ResetSettings General");

// Wait for launch VS
Task.Delay(15000).Wait();
_mainWindow = WaitForMainWindow();

// Handle initial setup
SetupVisualStudio().Wait();
}
// Handle initial setup
SetupVisualStudio().Wait();
}

private static async Task SetupVisualStudio()
private static async Task SetupVisualStudio()
{
// Find and click the "Continue without code" button
var continueWithoutCodeButton = _mainWindow.FindFirstDescendant(cf => cf.ByName("Continue without code"));
if (continueWithoutCodeButton != null)
{
var invokePattern = continueWithoutCodeButton.Patterns.Invoke.Pattern;
invokePattern.Invoke();
_mainWindow = WaitForMainWindow();
}
}
if (continueWithoutCodeButton != null)
{
var invokePattern = continueWithoutCodeButton.Patterns.Invoke.Pattern;
invokePattern.Invoke();
_mainWindow = WaitForMainWindow();
}
else
{
Console.WriteLine("Continue without code button not found");
_mainWindow = WaitForMainWindow();
}

var dkipThis = _mainWindow.FindFirstDescendant(cf => cf.ByName("Skip this for now."));
if (dkipThis != null)
{
var invokePattern = dkipThis.Patterns.Invoke.Pattern;
Console.WriteLine("Skip this for now button FOUND");
invokePattern.Invoke();
_mainWindow = WaitForMainWindow();
}
else
{
Console.WriteLine("Skip this for now button not found");
_mainWindow = WaitForMainWindow();
}
}

public static AutomationWindow WaitForMainWindow(int timeoutInSeconds = 30)
{
var startTime = DateTime.Now;
while ((DateTime.Now - startTime).TotalSeconds < timeoutInSeconds)
{
try
{
public static AutomationWindow WaitForMainWindow(int timeoutInSeconds = 30)
{
var startTime = DateTime.Now;
while ((DateTime.Now - startTime).TotalSeconds < timeoutInSeconds)
{
try
{
// Wait until the main window is available
Task.Delay(5000).Wait();
var window = _app.GetMainWindow(_automation);
if (window != null && window.IsAvailable)
{
return window;
}
}
catch (Exception)
{
// Ignore exception, retry until timeout
}
Task.Delay(500).Wait();
}
throw new TimeoutException("Main window did not appear within the timeout period.");
}
var window = _app.GetMainWindow(_automation);
if (window != null && window.IsAvailable)
{
return window;
}
}
catch (Exception)
{
// Ignore exception, retry until timeout
}

Task.Delay(500).Wait();
}

throw new TimeoutException("Main window did not appear within the timeout period.");
}

[ClassCleanup]
public static void ClassCleanup()
{
try
{
if (_app != null)
{
_app.Close();
_app.Dispose();
}
}
finally
{
if (_automation != null)
{
_automation.Dispose();
}

[ClassCleanup]
public static void ClassCleanup()
{
try
{
if (_app != null)
{
_app.Close();
_app.Dispose();
}
}
finally
{
if (_automation != null)
{
_automation.Dispose();
}
_mainWindow = null;
}
}
}
_mainWindow = null;
}
}
}
}
13 changes: 8 additions & 5 deletions UITests/CheckmarxTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using FlaUI.Core.AutomationElements;
using System.Threading.Tasks;
using System.IO;

namespace UITests
{
Expand All @@ -18,17 +20,18 @@ public async Task OpenCheckmarxWindow()
{
// Find the View menu
var viewMenu = _mainWindow.FindFirstDescendant(cf => cf.ByName("View"));

// Assert View menu is not null
Assert.IsNotNull(viewMenu, "View menu not found");

// Open the "View" menu by clicking it
viewMenu.WaitUntilEnabled().Click();
await Task.Delay(500);

var allMenuItems = _mainWindow.FindAllDescendants(cf =>
cf.ByControlType(FlaUI.Core.Definitions.ControlType.MenuItem));
cf.ByControlType(FlaUI.Core.Definitions.ControlType.MenuItem));
bool foundOtherWindows = false;


foreach (var menuItem in allMenuItems)
{
if (menuItem.Name == "Other Windows")
Expand All @@ -37,15 +40,15 @@ public async Task OpenCheckmarxWindow()
menuItem.WaitUntilEnabled().Click();
await Task.Delay(1000);

// Now select a specific window from the list "Checkmarx"
// Select a specific window from the list "Checkmarx"
var checkmarxOption = _mainWindow.FindFirstDescendant(cf => cf.ByName("Checkmarx"));
Assert.IsNotNull(checkmarxOption, "Checkmarx option not found in Other Windows menu");
checkmarxOption.WaitUntilEnabled().Click();
break;
}
}
Assert.IsTrue(foundOtherWindows, "Other Windows menu item not found");

}

}
}
Loading