-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdelldownload.psm1
314 lines (216 loc) · 8.26 KB
/
delldownload.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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
function delldownload([string]$para1,[int]$para2,[string]$para3){
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Bypass -Force;
$wshell=New-Object -ComObject wscript.shell
Add-Type -AssemblyName Microsoft.VisualBasic
Add-Type -AssemblyName System.Windows.Forms
$paracheck=$PSBoundParameters.ContainsKey('para1')
$paracheck2=$PSBoundParameters.ContainsKey('para2')
$paracheck3=$PSBoundParameters.ContainsKey('para3')
if( $paracheck -eq $false -or $para1.length -eq 0 ){
#write-host "no defined, setting 1 min after login"
$para1="R167233.exe"
}
if($paracheck2 -eq $false -or $para2 -eq 0){
$para2=2250584
}
if($paracheck3 -eq $false -or $para3.length -eq 0){
$para3=""
}
$dlfilename=$para1
$dlfilesize=$para2
$nonlog_flag=$para3
if($PSScriptRoot.length -eq 0){
$scriptRoot="C:\testing_AI\modules"
}
else{
$scriptRoot=$PSScriptRoot
}
$action="delldownload"
$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}
$actionmd="screenshot"
Get-Module -name $actionmd|remove-module
$mdpath=(Get-ChildItem -path $scriptRoot -r -file |Where-object{$_.name -match "^$actionmd\b" -and $_.name -match "psm1"}).fullname
Import-Module $mdpath -WarningAction SilentlyContinue -Global
$screen = [System.Windows.Forms.Screen]::PrimaryScreen
$bounds = $screen.Bounds
$width = $bounds.Width
$height = $bounds.Height
#$width = (([string]::Join("`n", (wmic path Win32_VideoController get CurrentHorizontalResolution))).split("`n") -match "\d{1,}")[0]
#$height = (([string]::Join("`n", (wmic path Win32_VideoController get CurrentVerticalResolution))).split("`n") -match "\d{1,}")[0]
Get-ChildItem "C:\testing_AI\modules\selenium\WebDriver.dll" |Unblock-File
Add-Type -Path "C:\testing_AI\modules\selenium\WebDriver.dll"
$dlcount=(Get-ChildItem $env:USERPROFILE\downloads\*.exe).count
$dlnames=(Get-ChildItem $env:USERPROFILE\downloads\*.exe).name
### web ##
$actionsln ="selenium_prepare"
Get-Module -name $actionsln|remove-module
$mdpath=(Get-ChildItem -path $scriptRoot -r -file |Where-object{$_.name -match "^$actionsln\b" -and $_.name -match "psm1"}).fullname
Import-Module $mdpath -WarningAction SilentlyContinue -Global
&$actionsln -para1 edge -para2 nonlog
$website="https://www.dell.com/support/home/en-us?lwp=rt"
#$website="https://www.dell.com/support/home/en-sg?app=drivers&lwp=rt"
$searchw= "Precision R5400"
$searchw2= "Intel Chipset Software Installation Utility, v.8.5"
try{$driver = New-Object OpenQA.Selenium.Edge.EdgeDriver}
catch{
$results="NG"
$index="fail to install web driver"
}
if($results -ne "NG"){
[OpenQA.Selenium.Interactions.Actions]$actions = New-Object OpenQA.Selenium.Interactions.Actions ($driver)
$driver.Manage().Window.Maximize()
$driver.Navigate().GoToUrl($website)
Start-Sleep -s 10
## if popup message ##
[System.Windows.Forms.SendKeys]::SendWait("{esc}")
Start-Sleep -s 2
[System.Windows.Forms.SendKeys]::SendWait("{esc}")
##>
Start-Sleep -s 5
$newbt=$driver.FindElement([OpenQA.Selenium.By]::ClassName("mh-mobile-nav-toggle"))
$newbt.Click()
Start-Sleep -s 5
$supelement = $driver.FindElement([OpenQA.Selenium.By]::XPath("//button[contains(@class, 'mh-top-nav-button') and span[text()='Support']]"))
$supelement.Click()
#$driver.ExecuteScript('arguments[0].scrollIntoView(true);', @($supelement))
Start-Sleep -s 5
$supl2=$element = $driver.FindElement([OpenQA.Selenium.By]::CssSelector("a.mh-menuItem[href*='self-support-knowledgebase']"))
$supl2.click()
#$supl=$driver.FindElement([OpenQA.Selenium.By]::XPath("//*[@id=""divResourceLinks""]/div/div/div[5]/a"))
# $supl=$driver.FindElement([OpenQA.Selenium.By]::CssSelector("a[data-linkmetrics='support-library']"))
# $supl.click()
# Start-Sleep -s 5
## if popup message ##
[System.Windows.Forms.SendKeys]::SendWait("{esc}")
##>
Start-Sleep -s 5
&$actionmd -para3 nonlog -para5 web1
$downl1=$driver.FindElement([OpenQA.Selenium.By]::CssSelector("a[href*='software-and-downloads'] div.dds__card"))
[System.Windows.Forms.SendKeys]::SendWait("{esc}")
Start-Sleep -s 1
$downl1.click()
Start-Sleep -s 5
## if popup message ##
[System.Windows.Forms.SendKeys]::SendWait("{esc}")
##>
&$actionmd -para3 nonlog -para5 web2
Start-Sleep -s 5
$downl2=$driver.FindElement([OpenQA.Selenium.By]::ID("tabi-2"))
[System.Windows.Forms.SendKeys]::SendWait("{esc}")
Start-Sleep -s 1
$downl2.click()
Start-Sleep -s 5
## if popup message ##
[System.Windows.Forms.SendKeys]::SendWait("{esc}")
##>
&$actionmd -para3 nonlog -para5 web3
$downl3=$driver.FindElement([OpenQA.Selenium.By]:: ID("PromotedContent-download-center-0"))
[System.Windows.Forms.SendKeys]::SendWait("{esc}")
Start-Sleep -s 1
$downl3.click()
Start-Sleep -s 5
## if popup message ##
[System.Windows.Forms.SendKeys]::SendWait("{esc}")
##>
Start-Sleep -s 5
&$actionmd -para3 nonlog -para5 web4
$downl4= $driver.FindElement([OpenQA.Selenium.By]::LinkText("Drivers & Downloads website"))
[System.Windows.Forms.SendKeys]::SendWait("{esc}")
Start-Sleep -s 1
$downl4.Click()
Start-Sleep -s 5
## if popup message ##
[System.Windows.Forms.SendKeys]::SendWait("{esc}")
##>
&$actionmd -para3 nonlog -para5 web5
Start-Sleep -s 5
$popupWindow = $driver.SwitchTo().Window($driver.WindowHandles[1])
$input=$popupWindow.FindElement([OpenQA.Selenium.By]::Id("inpEntrySelection"))
$input.SendKeys($searchw)
Start-Sleep -s 5
## if popup message ##
[System.Windows.Forms.SendKeys]::SendWait("{esc}")
##>
&$actionmd -para3 nonlog -para5 web6
Start-Sleep -s 5
$searchb=$popupWindow.FindElement([OpenQA.Selenium.By]::Id("txtSearchEs"))
[System.Windows.Forms.SendKeys]::SendWait("{esc}")
Start-Sleep -s 1
$searchb.Click()
Start-Sleep -s 5
## if popup message ##
[System.Windows.Forms.SendKeys]::SendWait("{esc}")
##>
&$actionmd -para3 nonlog -para5 web7
Start-Sleep -s 5
$input2=$popupWindow.FindElement([OpenQA.Selenium.By]::Id("keyword"))
$input2.SendKeys($searchw2)
Start-Sleep -s 5
## if popup message ##
[System.Windows.Forms.SendKeys]::SendWait("{esc}")
##>
&$actionmd -para3 nonlog -para5 web8
Start-Sleep -s 5
$searchb2=$popupWindow.FindElement([OpenQA.Selenium.By]::Id("dnd_btnKeywordSearch"))
[System.Windows.Forms.SendKeys]::SendWait("{esc}")
Start-Sleep -s 1
$searchb2.Click()
Start-Sleep -s 5
## if popup message ##
[System.Windows.Forms.SendKeys]::SendWait("{esc}")
##>
Start-Sleep -s 5
$downloadbt=$popupWindow.FindElement([OpenQA.Selenium.By]::Id("btnDwn-P50X1"))
[System.Windows.Forms.SendKeys]::SendWait("{esc}")
Start-Sleep -s 1
$downloadbt.Click()
$i=0
do{
$i++
Start-Sleep -s 5
$dlcount2=(Get-ChildItem $env:USERPROFILE\downloads\*.exe).count
} until ($dlcount2 -gt $dlcount -or $i -gt 60)
$dlnames2=(Get-ChildItem $env:USERPROFILE\downloads\*.exe|Where-object{$_.name -notin $dlnames}).name
$dlnamesfull=(Get-ChildItem $env:USERPROFILE\downloads\*.exe|Where-object{$_.name -notin $dlnames}).fullname
$dlsize=(Get-ChildItem $env:USERPROFILE\downloads\*.exe|Where-object{$_.name -notin $dlnames}).length
if($dlcount2 -gt $dlcount){
Move-Item $dlnamesfull $picpath -Force
}
if($dlnames2 -eq $dlfilename -and $dlsize -eq $dlfilesize){
$results="OK"
$index="same file name and size"
}
else{
$nonlog_flag="nolog"
}
### close web ###
$driver.Close()
$driver.Quit()
######### check timespan #######
$logs=(Split-Path -Parent $scriptRoot)+"\logs\logs_timemap.csv"
$lastactiontime=(Get-ChildItem $logs).LastWriteTime
$timespanmin=(New-TimeSpan -start $lastactiontime -end (get-date)).TotalMinutes
if($timespanmin -gt 30){
$nonlog_flag=""
$results="NG"
$index="download failed (over 30 minutes), check screen shots"
}
$results
$index
$nonlog_flag
}
######### write log #######
if($nonlog_flag.Length -eq 0 -or $timespanmin -gt 30){
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 delldownload