-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAgileInfocheck.psm1
221 lines (155 loc) · 7.14 KB
/
AgileInfocheck.psm1
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
219
220
221
function AgileInfocheck ([string]$para1,[string]$para2){
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Bypass -Force;
$SWB = $para1
$nonlog_flag=$para2
if($PSScriptRoot.length -eq 0){
$scriptRoot="C:\testing_AI\modules\"
}else{
$scriptRoot=$PSScriptRoot
}
$actionss="screenshot"
Get-Module -name $actionss|remove-module
$mdpath=(Get-ChildItem -path $scriptRoot -r -file |Where-object{$_.name -match "^$actionss\b" -and $_.name -match "psm1"}).fullname
Import-Module $mdpath -WarningAction SilentlyContinue -Global
$actionse ="selenium_prepare"
Get-Module -name $actionse|remove-module
$mdpath=(Get-ChildItem -path $scriptRoot -r -file |Where-object{$_.name -match "^$actionse\b" -and $_.name -match "psm1"}).fullname
Import-Module $mdpath -WarningAction SilentlyContinue -Global
$action="Agile Info check"
$tcpath=(Split-Path -Parent $scriptRoot)+"\currentjob\TC.txt"
$tcnumber=((get-content $tcpath).split(","))[0]
$tcstep=((get-content $tcpath).split(","))[1]
$picpath=(Split-Path -Parent $scriptRoot)+"\logs\$($tcnumber)\"
if(-not(test-path $picpath)){new-item -ItemType directory -path $picpath |out-null}
#general SWB number#
if($SWB.length -eq 0){
$inidrv=(Get-ChildItem "C:\testing_AI\logs\ini*\*" -r -Filter "*DriverVersion.csv"|Sort-Object lastwritetime|select -last 1).FullName
$checktype=(import-csv $inidrv|Where-object{$_.DeviceClass -match "DISPLAY"}).devicename
if($inidrv -and $checktype){
if($checktype -match "NVIDIA"){
$drvtype2="NV_general"
if($checktype -match "ada"){
$drvtype2="NV_A6000ada"
}
$drivername=(Get-ChildItem ($scriptRoot+"\driver\GFX\$($drvtype2)\N\driver\") -File |Where-object{$_.name -match "NVIDIA" -and $_.name -match "\.exe"}|sort lastwritetime|select -first 1 ).Name
$SWB=$drivername.split("_") |? {$_.length -eq 5 -and !($_ -match "^WIN\d{2}") }
write-host "The Display Type is $($drvtype2)"
write-host "The Display Driver SWB is $($SWB)"
}
if($checktype -match "AMD"){
$chekdrv=$checktype -match "[a-zA-Z]\d{4}"
if(!$chekdrv){$checktype -match "\d{4}"}
$drvtype2="AMD_"+$matches[0]
$drivername=(Get-ChildItem ($scriptRoot+"\driver\GFX\$($drvtype2)\N\") -File |Where-object{$_.name -match "AMD" -and $_.name -match "\.exe" }|sort lastwritetime|select -first 1 ).Name
$SWB=$drivername.split("_") |? {$_.length -eq 5 -and !($_ -match "^WIN\d{2}")}
write-host "The Display Driver is $($drvtype2)"
write-host "The Display Driver SWB is $($SWB)"
}
}
}
if($SWB -and $SWB.count -eq 1){
#region selenium prepre
&$actionse -para1 "edge" -para2 "nonlog"
Get-ChildItem "C:\testing_AI\modules\selenium\WebDriver.dll" |Unblock-File
Add-Type -Path "C:\testing_AI\modules\selenium\WebDriver.dll"
try{$driver = New-Object OpenQA.Selenium.Edge.EdgeDriver}
catch{
$results="NG"
$index="fail to install web driver"
}
if($results -ne "NG"){
$driver.Manage().Window.Maximize()
$driver.Navigate().GoToUrl("https://agile.us.dell.com/Agile/default/login-cms.jsp")
Start-Sleep -Seconds 10
$agileacc = Get-content -path C:\testing_AI\settings\loginPwd_Agile.txt
$username = $driver.FindElement([OpenQA.Selenium.By]::Id("j_username"))
$username.SendKeys($agileacc[0])
Start-Sleep -Seconds 2
$pass = $driver.FindElement([OpenQA.Selenium.By]::Id("j_password"))
$pass.SendKeys($agileacc[1])
Start-Sleep -Seconds 2
$loginbt = $driver.FindElement([OpenQA.Selenium.By]::Id("login"))
$loginbt.Click()
Start-Sleep -Seconds 30
$driver = $driver.SwitchTo().Window($driver.WindowHandles[-1])
#$driver.Navigate().GoToUrl("https://agile.us.dell.com/Agile/PLMServlet?module=LoginHandler&opcode=forwardToMainMenu")
Start-Sleep -Seconds 5
$QSS = $driver.FindElement([OpenQA.Selenium.By]::Id("QUICKSEARCH_STRING"))
$QSS.SendKeys($SWB)
Start-Sleep -Seconds 2
$sech = $driver.FindElement([OpenQA.Selenium.By]::Id("top_simpleSearchspan"))
$sech.Click()
Start-Sleep -Seconds 30
$QST = $driver.FindElement([OpenQA.Selenium.By]::ClassName("GMBodyMid"))
$searchjs = "var search = document.getElementById('QUICKSEARCH_TABLE');"
$searchjs += "var itemcount = 0;"
$searchjs += "for(var i = 0; i<= search.querySelectorAll('td').length-1; i++){"
$searchjs += "if(search.querySelectorAll('td').item(i).textContent.includes('$SWB') && search.querySelectorAll('td').item(i).textContent.length <= 6){ itemcount = i;}}"
$searchjs += "search.querySelectorAll('td').item(itemcount).querySelector('a').click();"
$driver.ExecuteScript($searchjs)
Start-Sleep -Seconds 30
&$actionss -para3 nonlog -para5 "page1"
$page3 = $driver.FindElement([OpenQA.Selenium.By]::Id("id_heading_Page Three"))
$page3.Click()
&$actionss -para3 nonlog -para5 "page3"
$searchtextjs = "var table = document.getElementById('content');"
$searchtextjs += "var dl = table.querySelectorAll('dl');"
$searchtextjs += "var array = [];"
$searchtextjs += "for(var i = 0 ; i<= dl.length-1 ; i++){"
$searchtextjs += " array += dl.item(i).textContent;};"
$searchtextjs += "return array;"
$content = $driver.ExecuteScript($searchtextjs)
$content = $content.split("`n")
$findings=@("Fixes and Enhancements","Operating System","Description External")
$checkinfos=@()
foreach($finding in $findings){
$findingmat="\s{2,}"+$finding
$checkinfo= ($content -match $findingmat).trim()
$checkinfos+=@($checkinfo)
$splittitle=$finding+":"
$findingindex=$finding
if($finding -match "Fixes and Enhancements"){
$checkinfo2= ($checkinfo -split "External\:")[1]
}
if($finding -match "Operating System"){
$checkinfo2= ($checkinfo -split "\(OS\)\:")[1]
}
if($finding -match "Description External"){
$splittitle2=$splittitle.substring($splittitle.length -10,10)
$checkinfo2= ($checkinfo -split "$splittitle2")[1]
$findingindex=($finding.replace("*","")).replace(" External","")
}
$datenow = get-date -format "yyMMdd_HHmmss"
$infopath =$picpath+"\$($datenow)_step$($tcstep)_agileinfo_$($findingindex).txt"
#$findingindex
#$checkinfo2
#start-sleep -s 5
set-content -path $infopath -Value $checkinfo2 -Force
}
$results="NG"
$index="Fail to check agile info"
$checkinfos=($checkinfos|Out-String)
if( $checkinfos.Length -gt 0){
$results="OK"
$index= $checkinfos
}
### close web ###
$driver.Close()
$driver.Quit()
if((get-process -Name msedgedriver -ErrorAction SilentlyContinue)){Stop-Process -Name msedgedriver}
}
}
else{
$results="NG"
$index="SWB number read fail"
}
######### write log #######
if($nonlog_flag.Length -eq 0){
Get-Module -name "outlog"|remove-module
$mdpath=(Get-ChildItem -path "C:\testing_AI\modules\" -r -file |Where-Object{$_.name -match "outlog" -and $_.name -match "psm1"}).fullname
Import-Module $mdpath -WarningAction SilentlyContinue -Global
#write-host "Do $action!"
outlog $action $results $tcnumber $tcstep $index
}
}
Export-ModuleMember -Function AgileInfocheck