@@ -111,14 +111,12 @@ function Start-SeChrome {
111
111
112
112
if ($Minimized ){
113
113
$driver.Manage ().Window.Minimize();
114
-
115
114
}
116
115
117
116
if ($Headless -and $DefaultDownloadPath ) {
118
117
$HeadlessDownloadParams = New-Object ' system.collections.generic.dictionary[[System.String],[System.Object]]]'
119
118
$HeadlessDownloadParams.Add (' behavior' , ' allow' )
120
119
$HeadlessDownloadParams.Add (' downloadPath' , $DefaultDownloadPath.FullName )
121
-
122
120
$Driver.ExecuteChromeCommand (' Page.setDownloadBehavior' , $HeadlessDownloadParams )
123
121
}
124
122
@@ -142,32 +140,88 @@ function Start-SeEdge {
142
140
}
143
141
144
142
function Start-SeFirefox {
145
- param ([Switch ]$Profile )
143
+ param (
144
+ [array ]$Arguments ,
145
+ [string ]$StartURL ,
146
+ [System.IO.FileInfo ]$DefaultDownloadPath ,
147
+ [switch ]$Headless ,
148
+ [switch ]$PrivateBrowsing ,
149
+ [switch ]$Maximized ,
150
+ [switch ]$Minimized ,
151
+ [switch ]$Fullscreen
152
+ )
146
153
147
- if ($Profile ) {
148
- # Doesn't work....
149
- $ProfilePath = Join-Path $PSScriptRoot " Assets\ff-profile\rust_mozprofile.YwpEBLY3hCRX"
150
- $firefoxProfile = New-Object OpenQA.Selenium.Firefox.FirefoxProfile - ArgumentList ($ProfilePath )
151
- $firefoxProfile.WriteToDisk ()
152
- if ($IsLinux -or $IsMacOS ){
153
- New-Object - TypeName " OpenQA.Selenium.Firefox.FirefoxDriver" - ArgumentList $AssembliesPath , $firefoxProfile
154
+ BEGIN {
155
+ if ($Maximized -ne $false -and $Minimized -ne $false ) {
156
+ throw ' Maximized and Minimized may not be specified together.'
154
157
}
155
- else {
156
- New-Object - TypeName " OpenQA.Selenium.Firefox.FirefoxDriver" - ArgumentList $firefoxProfile
158
+ elseif ($Maximized -ne $false -and $Fullscreen -ne $false ){
159
+ throw ' Maximized and Fullscreen may not be specified together.'
160
+ }
161
+ elseif ($Minimized -ne $false -and $Fullscreen -ne $false ){
162
+ throw ' Minimized and Fullscreen may not be specified together.'
163
+ }
164
+
165
+ if ($StartURL ){
166
+ if (! [system.uri ]::IsWellFormedUriString($StartURL , [System.UriKind ]::Absolute)){
167
+ throw ' Incorrect StartURL please make sure the URL starts with http:// or https://'
168
+ }
157
169
}
158
170
}
159
- else {
171
+ PROCESS {
172
+ $Firefox_Options = New-Object - TypeName " OpenQA.Selenium.Firefox.FirefoxOptions"
173
+
174
+ if ($Headless ) {
175
+ $Firefox_Options.AddArguments (' -headless' )
176
+ }
177
+
178
+ if ($DefaultDownloadPath ){
179
+ Write-Verbose " Setting Default Download directory: $DefaultDownloadPath "
180
+ $Firefox_Options.setPreference (" browser.download.folderList" , 2 );
181
+ $Firefox_Options.SetPreference (" browser.download.dir" , " $DefaultDownloadPath " );
182
+ }
183
+
184
+ if ($PrivateBrowsing ){
185
+ $Firefox_Options.SetPreference (" browser.privatebrowsing.autostart" , $true )
186
+ }
187
+
188
+ if ($Arguments ) {
189
+ foreach ($Argument in $Arguments ){
190
+ $Firefox_Options.AddArguments ($Argument )
191
+ }
192
+ }
193
+
160
194
if ($IsLinux -or $IsMacOS ){
161
- $Driver = New-Object - TypeName " OpenQA.Selenium.Firefox.FirefoxDriver" - ArgumentList $AssembliesPath
195
+ $Driver = New-Object - TypeName " OpenQA.Selenium.Firefox.FirefoxDriver" - ArgumentList $AssembliesPath , $Firefox_Options
162
196
}
163
197
else {
164
- $Driver = New-Object - TypeName " OpenQA.Selenium.Firefox.FirefoxDriver"
198
+ $Driver = New-Object - TypeName " OpenQA.Selenium.Firefox.FirefoxDriver" - ArgumentList $Firefox_Options
199
+ }
200
+
201
+ $Driver.Manage ().Timeouts().ImplicitWait = [TimeSpan ]::FromSeconds(10 )
202
+
203
+ if ($Minimized ){
204
+ $Driver.Manage ().Window.Minimize()
205
+ }
206
+
207
+ if ($Maximized ){
208
+ $Driver.Manage ().Window.Maximize()
209
+ }
210
+
211
+ if ($Fullscreen ){
212
+ $Driver.Manage ().Window.FullScreen()
213
+ }
214
+
215
+ if ($StartURL ){
216
+ Enter-SeUrl - Driver $Driver - Url $StartURL
165
217
}
166
218
}
167
- $Driver.Manage ().Timeouts().ImplicitWait = [TimeSpan ]::FromSeconds(10 )
168
- $Driver
219
+ END {
220
+ return $Driver
221
+ }
169
222
}
170
223
224
+
171
225
function Stop-SeDriver {
172
226
param ($Driver )
173
227
0 commit comments