@@ -111,14 +111,12 @@ function Start-SeChrome {
111111
112112 if ($Minimized ){
113113 $driver.Manage ().Window.Minimize();
114-
115114 }
116115
117116 if ($Headless -and $DefaultDownloadPath ) {
118117 $HeadlessDownloadParams = New-Object ' system.collections.generic.dictionary[[System.String],[System.Object]]]'
119118 $HeadlessDownloadParams.Add (' behavior' , ' allow' )
120119 $HeadlessDownloadParams.Add (' downloadPath' , $DefaultDownloadPath.FullName )
121-
122120 $Driver.ExecuteChromeCommand (' Page.setDownloadBehavior' , $HeadlessDownloadParams )
123121 }
124122
@@ -142,32 +140,88 @@ function Start-SeEdge {
142140}
143141
144142function 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+ )
146153
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.'
154157 }
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+ }
157169 }
158170 }
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+
160194 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
162196 }
163197 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
165217 }
166218 }
167- $Driver.Manage ().Timeouts().ImplicitWait = [TimeSpan ]::FromSeconds(10 )
168- $Driver
219+ END {
220+ return $Driver
221+ }
169222}
170223
224+
171225function Stop-SeDriver {
172226 param ($Driver )
173227
0 commit comments