-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExecuteTestFromRemoteMachine.ps1
More file actions
220 lines (158 loc) · 7.46 KB
/
ExecuteTestFromRemoteMachine.ps1
File metadata and controls
220 lines (158 loc) · 7.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
#----------varaible declarations --------------------------------------------
#path variables
$OdessaTestServerNetworkPath = "\\lwdelapp-003\Sites\DFS\BUILD\OT\OdessaTestExecutionWorkspace"
$OdessaTestServerLocalPath = "E:\Sites\DFS\BUILD\OT\OdessaTestExecutionWorkspace"
#creds
$remoteSessionUser = "db_job"
$remoteSessionPwd = "password-1"
$TestServer = "lwdelapp-003"
#configs
$OTBinaryPath = "$OdessaTestServerLocalPath\OdessaTestClient\Binaries\OdessaTest.exe"
$OTlogPath = $OdessaTestServerNetworkPath #provide network path
$OTWorkSpace = "$OdessaTestServerLocalPath\TestSuites\Projects\SmokeSuite"
$OTScenarioCollection = "NightlyBuild"
$LPurl= "http://dfsqa.del3.odessadev.local/"
$APIGetURL= "http://dfsqa.api.del3.odessadev.local/api/Entity/User/Id=1?select=FirstName,LastName"
$APIPostURL = "http://dfsqa.api.del3.odessadev.local//api/Entity/BankBranch/Create"
$global:RunName = $null
#-------------------------------------------------------------------------
$startTime = get-date -Format dd_MM_hhmmss
$projectName = "SmokeSuite" + $startTime
$global:MailBody = "Team,<br>"
Write-Host "$projectName"
function global:GetCredForPSS {
$pw = convertto-securestring -AsPlainText -Force -String $remoteSessionPwd
$global:cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $remoteSessionUser,$pw
}
function global:ExecuteOTtest{
$s = New-PSSession -ComputerName $TestServer -credential $global:cred
Invoke-Command -Session $s -Script {
Write-Host "Executing Odessa Test Scenarios"
$userName = "system.user"
$workingDirectory = $Using:OTWorkSpace
&$Using:OTBinaryPath -Operation Execute -DeploymentPath $Using:LPurl -WorkingDirectory $workingDirectory -Scenarios $Using:OTScenarioCollection -Collection true -RunName $Using:projectName -LogsFolder $Using:OTlogPath
Start-Sleep -Seconds 30
Write-Host "Test Execution Completed"
}
}
function global:ExecutedScenarioDetails{
$SqlQuery = "SELECT sh.ScenarioName,sh.ScenarioRunStatus,sh.ModuleName FROM dbo.ScenarioHeader sh JOIN dbo.RunHeader rh ON sh.RunHeaderID = rh.RunHeaderID WHERE rh.RunName ='"+ $projectName +"'"
$SQLConnection = New-Object System.Data.SqlClient.SqlConnection
$SqlConnection.ConnectionString = "Server = 'lwdeldb-003'; Database = 'TestAutomation'; uid = 'development'; pwd = 'jk'"
$SqlCmd = New-Object System.Data.SqlClient.SqlCommand
$SqlCmd.CommandText = $SqlQuery
$SqlCmd.Connection = $SqlConnection
$SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter
$SqlAdapter.SelectCommand = $SqlCmd
$DataSet = New-Object System.Data.DataSet
$SqlAdapter.Fill($DataSet)
$SqlConnection.Close()
# This code outputs the retrieved data
$table = $DataSet.Tables[0]
$global:MailBody += "<style> table, th, td { border: 1px solid black;}.Error { border: 1.5px solid red; color: red; }.Success { border: 1.5px solid green; color: green; }</style> "
$global:MailBody += "<br><table><tr><th>ScenarioName</th><th>Status</th><th>Module</th></tr>"
foreach ($row in $table.Rows)
{
if($row[1] -ne "Completed With Errors"){
$global:MailBody += "<tr><td class='Success'>" + $row[0] + "</td><td>" + $row[1] + "</td><td>" + $row[2] + "</td></tr>"
}
else{
$global:MailBody += "<tr><td class='Error'>" + $row[0] + "</td><td class='Error'>" + $row[1] + "</td><td class='Error'>" + $row[2] + "</td></tr>"
}
}
$global:MailBody += "</table><br>"
}
function global:CheckRunStatus {
$logfile = $OTlogPath+"\"+$projectName+"_Execute.txt"
$val = 0
$global:success = 0
$retryGetResult = 1
Write-Host "Validating Test Execution"
while($val -ne 1)
{
Start-Sleep -Seconds 300
if([System.IO.File]::Exists($logfile))
{
$SEL = Get-Content $logfile | Select -Index 2
if ($SEL -eq 'Status: Passed')
{
$global:success = 0
$val = 1
$global:MailBody += "<br> <font color=black>Please find the execution results below.</font><br>"
global:ExecutedScenarioDetails
}
else
{
$val = 1
$global:MailBody += " <b><font color=red>OT Validation Failed please check the logs</b></font><br>"
}
}
else
{
$retryGetResult++
Write-Host "Retrying Validating Execution"
}
if ($retryGetResult -eq 20)
{
$global:MailBody += " <b><font color=red>OT Validation Failed please check the logs</b></font><br>"
$val = 1
Exit 1
}
}
}
function global:TestAPI{
$Headers = @{
Authorization = "Basic dXNlci4xOlBhc3N3b3JkLTE="
}
$getresponse = Invoke-WebRequest -Uri $APIGetURL -Headers $Headers -UseBasicParsing
$getcond = $getresponse | Select-String -Pattern '"FirstName": "System",'
$success = 0
if ($getcond -ne $null) {$success = 1} else {$success = 0}
$data = @{
"Name" = "AutoAPITest_$startTime";
"BankName"= "BB_AutoAPITest";
"ACHRoutingNumber"= "768345234";
"ABARoutingNumber"= "123234345";
}
$body = $data | ConvertTo-Json
$postresponse = Invoke-WebRequest -Uri $APIPostURL -Headers $Headers -Method POST -Body $body -ContentType "application/json" -UseBasicParsing
$postcond = $postresponse | Select-String -Pattern '"Success": true,'
if ($getcond -ne $null) {$success = 1} else {$success = 0}
if ($success -eq 1){$global:MailBody += " <b><font color=green>API validation successfull</b></font><br> <b><font color=black>Successfully executed 2 scenarios.</b></font><br>" }
else {$global:MailBody += " <b><font color=red>API Validation Failed please check the logs</b></font><br>" }
}
function Send-Email(){
param(
[Parameter(Mandatory=$true)][string]$smtpServer = "YOUREMAILSERVER.COM",
[string]$ComputerName = $env:ComputerName,
[string]$from = "from@yourdomain.com",
[string]$to = "you@yourdomain.com",
[string]$subject = "Default Send-Email Subject.",
[string]$body = "Default Send-Email Body"
)
try {
#Creating a Mail object
$msg = new-object Net.Mail.MailMessage
#Creating SMTP server object
$smtp = new-object Net.Mail.SmtpClient($smtpServer,25)
#$smtp.EnableSsl = $true
$smtp.Credentials = New-Object System.Net.NetworkCredential("no-reply@odessatech.in", "password-1");
#Email structure
$msg.From = $from
$msg.ReplyTo = "noreply@yourdomain.com"
$msg.To.Add($to)
$msg.subject = "Nightly Build : Test Results"
write-host $global:MailBody
$msg.body = $global:MailBody
$msg.IsBodyHtml = 1
#Sending email
$smtp.Send($msg)
} catch {
Write-Warning $_
}
}
GetCredForPSS
ExecuteOTtest
CheckRunStatus
TestAPI
Send-Email -smtpServer mail.odessatech.in -from 'LWOctopusDeployment@odessainc.com' -to 'Dell-Blr@odessainc.com';