Browse Source

Added Test Center Scripts

main
kusum 1 year ago
parent
commit
d5680e7dfb
2 changed files with 326 additions and 0 deletions
  1. 260
    0
      test-center/TestCenter_1.ps1
  2. 66
    0
      test-center/TestCenter_2.ps1

+ 260
- 0
test-center/TestCenter_1.ps1 View File

@@ -0,0 +1,260 @@
<#
.SYNOPSIS
Create and run test suite
.DESCRIPTION
Submit a multi-case test suite to v3 of the test-center API and execute it
.PARAMETER UserID
ID of the user executing the test. Must be the same as that used in your hostname creation previously
.EXAMPLE
> .\New-AkaUTests.ps1 -UserID example
#>

Param(
[Parameter(Mandatory)]
[string]
$UserID,

[Parameter()]
[string]
$EdgeRCFile,

[Parameter()]
[string]
$Section,

[Parameter()]
[string]
$AccountSwitchKey
)

$CommonParams = @{
EdgeRCFile = $EdgeRCFile
Section = $Section
AccountSwitchKey = $AccountSwitchKey
}

# 1. Create test suite with child objects

$TestSuiteJSON = @"
{
"testSuiteName": "AkaULab-$UserID-TestSuite",
"isLocked": false,
"isStateful": false,
"testCases": [
{
"clientProfile": {
"client": "CURL",
"ipVersion": "IPV4"
},
"condition": {
"conditionExpression": "Response code is one of \"302\""
},
"testRequest": {
"requestMethod": "GET",
"testRequestUrl": "https://{{userId}}tflab.akaudevops.com"
}
},
{
"clientProfile": {
"client": "CURL",
"ipVersion": "IPV4"
},
"condition": {
"conditionExpression": "Response header \"X-Akamai-Staging\" has a value that equals \"ESSL\""
},
"testRequest": {
"requestMethod": "GET",
"testRequestUrl": "https://{{userId}}tflab.akaudevops.com"
}
},
{
"clientProfile": {
"client": "CURL",
"ipVersion": "IPV4"
},
"condition": {
"conditionExpression": "Caching option is cache with max-age of \"30\" days"
},
"testRequest": {
"requestMethod": "GET",
"testRequestUrl": "https://{{userId}}tflab.akaudevops.com/assets/public/images/JuiceShop_Logo.png"
}
},
{
"clientProfile": {
"client": "CURL",
"ipVersion": "IPV4"
},
"condition": {
"conditionExpression": "Response code is one of \"302\""
},
"testRequest": {
"requestMethod": "GET",
"testRequestUrl": "https://{{userId}}tflab-test.akaudevops.com"
}
},
{
"clientProfile": {
"client": "CURL",
"ipVersion": "IPV4"
},
"condition": {
"conditionExpression": "Response header \"X-Test-Environment\" has a value that equals \"true\""
},
"testRequest": {
"requestMethod": "GET",
"testRequestUrl": "https://{{userId}}tflab-test.akaudevops.com"
}
},
{
"clientProfile": {
"client": "CURL",
"ipVersion": "IPV4"
},
"condition": {
"conditionExpression": "Response header \"cache-control\" has a value that contains \"no-store\""
},
"testRequest": {
"requestMethod": "GET",
"testRequestUrl": "https://{{userId}}tflab-test.akaudevops.com/style.css"
}
},
{
"clientProfile": {
"client": "CURL",
"ipVersion": "IPV4"
},
"condition": {
"conditionExpression": "Response code is one of \"403\""
},
"testRequest": {
"testRequestUrl": "https://{{userId}}tflab.akaudevops.com/?pasword='OR%201=1",
"requestMethod": "GET"
}
},
{
"clientProfile": {
"client": "CURL",
"ipVersion": "IPV4"
},
"condition": {
"conditionExpression": "Response code is one of \"403\""
},
"testRequest": {
"testRequestUrl": "https://{{userId}}tflab.akaudevops.com/",
"requestMethod": "GET",
"requestHeaders": [
{
"headerName": "blockme",
"headerValue": "true",
"headerAction": "ADD"
}
]
}
},

{
"clientProfile": {
"client": "CHROME",
"ipVersion": "IPV4"
},
"condition": {
"conditionExpression": "Response code is one of \"403\""
},
"testRequest": {
"testRequestUrl": "https://{{userId}}tflab.akaudevops.com/rest/user/login",
"requestMethod": "POST"
}
},

{
"clientProfile": {
"client": "CURL",
"ipVersion": "IPV4"
},
"condition": {
"conditionExpression": "Response code is one of \"403\""
},
"testRequest": {
"testRequestUrl": "https://{{userId}}tflab.akaudevops.com/",
"requestMethod": "GET",
"requestHeaders": [
{
"headerName": "X-Forwarded-For",
"headerValue": "101.110.112.0",
"headerAction": "ADD"
}
]
}
},
{
"clientProfile": {
"client": "CURL",
"ipVersion": "IPV4"
},
"condition": {
"conditionExpression": "Response header \"set-cookie\" has a value that contains \"language=ko_KR\""
},
"testRequest": {
"testRequestUrl": "https://{{userId}}tflab.akaudevops.com/",
"requestMethod": "GET",
"requestHeaders": [
{
"headerName": "X-Forwarded-For",
"headerValue": "168.126.63.1",
"headerAction": "ADD"
}
]
}
}
],
"variables": [
{
"variableName": "userId",
"variableValue": "$UserID"
}
]
}
"@

try {
$TestSuite = Invoke-AkamaiRestMethod -Method POST -Path '/test-management/v3/functional/test-suites/with-child-objects' -Body $TestSuiteJSON @CommonParams
}
catch {
Write-Error "Error creating test suite. Cannot continue"
Write-Error $_
return
}

# 2. Execute Test Suite

$TestExecutionJSON = @"
{
"functional": {
"testSuiteExecutions": [
{
"testSuiteId": $($TestSuite.success.testSuiteId)
}
]
},
"targetEnvironment": "STAGING",
"note": "Executing test suite for user $UserID",
"sendEmailOnCompletion": false
}
"@

try {
$Run = Invoke-AkamaiRestMethod -Method POST -Path '/test-management/v3/test-runs' -Body $TestExecutionJSON @CommonParams
}
catch {
Write-Error "Error executing test suite $($TestSuite.success.testSuiteId). Cannot continue"
Write-Error $_
return
}

Write-Host -ForegroundColor Green "Test suite $($TestSuite.success.testSuiteId) created. Wait a few minutes before retrieving test run results with ID: $($Run.testRunId)"

+ 66
- 0
test-center/TestCenter_2.ps1 View File

@@ -0,0 +1,66 @@
<#
.SYNOPSIS
Get test suite results
.DESCRIPTION
Retrieve test suite results and format for output
.PARAMETER TestRunID
ID of the test suite execution to poll
.EXAMPLE
> .\New-AkaUTests.ps1 -TestID 12345
#>
Param(
[Parameter(Mandatory)]
[string]
$TestRunID,
[Parameter()]
[string]
$EdgeRCFile,
[Parameter()]
[string]
$Section,
[Parameter()]
[string]
$AccountSwitchKey
)
$CommonParams = @{
EdgeRCFile = $EdgeRCFile
Section = $Section
AccountSwitchKey = $AccountSwitchKey
}
$Results = Invoke-AkamaiRestMethod -Path "/test-management/v3/test-runs/$TestRunID" @CommonParams
if ($Results.functional.testSuiteExecutions[0].status -eq 'IN_PROGRESS') {
Write-Host -ForegroundColor Yellow "Tests are not yet complete. Please wait and try again"
return
}
$TestResults = $Results.functional.testSuiteExecutions.testCaseExecutions
$Spaces = ' '
foreach ($TestResult in $TestResults) {
$Method = $TestResult.testCaseContext.testRequest.requestMethod
$URL = $TestResult.testCaseContext.testRequest.testRequestUrlResolved
$Condition = $TestResult.testCaseContext.condition.conditionExpression
$Result = $TestResult.conditionEvaluationResult.result
$SpaceLength = 80 - $Condition.length
$ScopedSpaces = $Spaces.SubString(0, $SpaceLength)
Write-Host -ForegroundColor Blue $Method -NoNewline
Write-Host "`t" -NoNewline
Write-Host $URL
Write-Host "`t$Condition" -NoNewline
if ($Result -eq 'PASSED') {
Write-Host -ForegroundColor Green "$ScopedSpaces$Result"
}
else {
Write-Host -ForegroundColor Red "$ScopedSpaces$Result"
}
}

Loading…
Cancel
Save