@@ -44,7 +44,7 @@ function Start-SeChrome {
4444 )
4545
4646 BEGIN {
47- if ($Maximized -ne $false -and $Minimized -ne $false ) {
47+ if ($Maximized -ne $false -and $Minimized -ne $false ){
4848 throw ' Maximized and Minimized may not be specified together.'
4949 }
5050 elseif ($Maximized -ne $false -and $Fullscreen -ne $false ){
@@ -76,29 +76,29 @@ function Start-SeChrome {
7676 $Chrome_Options.AddUserProfilePreference (' plugins' , @ {' always_open_pdf_externally' = $true ;})
7777 }
7878
79- if ($Headless ) {
79+ if ($Headless ){
8080 $Chrome_Options.AddArguments (' headless' )
8181 }
8282
83- if ($Incognito ) {
83+ if ($Incognito ){
8484 $Chrome_Options.AddArguments (' Incognito' )
8585 }
8686
87- if ($Maximized ) {
87+ if ($Maximized ){
8888 $Chrome_Options.AddArguments (' start-maximized' )
8989 }
9090
91- if ($Fullscreen ) {
91+ if ($Fullscreen ){
9292 $Chrome_Options.AddArguments (' start-fullscreen' )
9393 }
9494
95- if ($Arguments ) {
95+ if ($Arguments ){
9696 foreach ($Argument in $Arguments ){
9797 $Chrome_Options.AddArguments ($Argument )
9898 }
9999 }
100100
101- if (! $HideVersionHint ) {
101+ if (! $HideVersionHint ){
102102 Write-Verbose " Download the right chromedriver from 'http://chromedriver.chromium.org/downloads'"
103103 }
104104
@@ -109,18 +109,18 @@ function Start-SeChrome {
109109 $Driver = New-Object - TypeName " OpenQA.Selenium.Chrome.ChromeDriver" - ArgumentList $Chrome_Options
110110 }
111111
112- if ($Minimized ){
112+ if ($Minimized -and $Driver ){
113113 $driver.Manage ().Window.Minimize();
114114 }
115115
116- if ($Headless -and $DefaultDownloadPath ) {
116+ if ($Headless -and $DefaultDownloadPath -and $Driver ) {
117117 $HeadlessDownloadParams = New-Object ' system.collections.generic.dictionary[[System.String],[System.Object]]]'
118118 $HeadlessDownloadParams.Add (' behavior' , ' allow' )
119119 $HeadlessDownloadParams.Add (' downloadPath' , $DefaultDownloadPath.FullName )
120120 $Driver.ExecuteChromeCommand (' Page.setDownloadBehavior' , $HeadlessDownloadParams )
121121 }
122122
123- if ($StartURL ){
123+ if ($StartURL -and $Driver ){
124124 Enter-SeUrl - Driver $Driver - Url $StartURL
125125 }
126126 }
@@ -152,7 +152,7 @@ function Start-SeFirefox {
152152 )
153153
154154 BEGIN {
155- if ($Maximized -ne $false -and $Minimized -ne $false ) {
155+ if ($Maximized -ne $false -and $Minimized -ne $false ){
156156 throw ' Maximized and Minimized may not be specified together.'
157157 }
158158 elseif ($Maximized -ne $false -and $Fullscreen -ne $false ){
@@ -171,7 +171,7 @@ function Start-SeFirefox {
171171 PROCESS {
172172 $Firefox_Options = New-Object - TypeName " OpenQA.Selenium.Firefox.FirefoxOptions"
173173
174- if ($Headless ) {
174+ if ($Headless ){
175175 $Firefox_Options.AddArguments (' -headless' )
176176 }
177177
@@ -185,7 +185,7 @@ function Start-SeFirefox {
185185 $Firefox_Options.SetPreference (" browser.privatebrowsing.autostart" , $true )
186186 }
187187
188- if ($Arguments ) {
188+ if ($Arguments ){
189189 foreach ($Argument in $Arguments ){
190190 $Firefox_Options.AddArguments ($Argument )
191191 }
@@ -198,21 +198,23 @@ function Start-SeFirefox {
198198 $Driver = New-Object - TypeName " OpenQA.Selenium.Firefox.FirefoxDriver" - ArgumentList $Firefox_Options
199199 }
200200
201- $Driver.Manage ().Timeouts().ImplicitWait = [TimeSpan ]::FromSeconds(10 )
202-
203- if ($Minimized ){
201+ if ($Driver ){
202+ $Driver.Manage ().Timeouts().ImplicitWait = [TimeSpan ]::FromSeconds(10 )
203+ }
204+
205+ if ($Minimized -and $Driver ){
204206 $Driver.Manage ().Window.Minimize()
205207 }
206208
207- if ($Maximized ){
209+ if ($Maximized -and $Driver ){
208210 $Driver.Manage ().Window.Maximize()
209211 }
210212
211- if ($Fullscreen ){
213+ if ($Fullscreen -and $Driver ){
212214 $Driver.Manage ().Window.FullScreen()
213215 }
214216
215- if ($StartURL ){
217+ if ($StartURL -and $Driver ){
216218 Enter-SeUrl - Driver $Driver - Url $StartURL
217219 }
218220 }
@@ -221,7 +223,6 @@ function Start-SeFirefox {
221223 }
222224}
223225
224-
225226function Stop-SeDriver {
226227 param ($Driver )
227228
0 commit comments