@@ -263,10 +263,55 @@ function Remove-SeCookie {
263263}
264264
265265function Set-SeCookie {
266- param ($Driver , $name , $value )
266+ param (
267+ $Driver ,
268+ [string ]$Name ,
269+ [string ]$Value ,
270+ [string ]$Path ,
271+ [string ]$Domain ,
272+ [datetime ]$ExpiryDate
273+ )
274+
275+ <# Selenium Cookie Information
276+ Cookie(String, String)
277+ Initializes a new instance of the Cookie class with a specific name and value.
278+ Cookie(String, String, String)
279+ Initializes a new instance of the Cookie class with a specific name, value, and path.
280+ Cookie(String, String, String, Nullable<DateTime>)
281+ Initializes a new instance of the Cookie class with a specific name, value, path and expiration date.
282+ Cookie(String, String, String, String, Nullable<DateTime>)
283+ Initializes a new instance of the Cookie class with a specific name, value, domain, path and expiration date.
284+ #>
285+
286+ if ($Name -and $Value -and (! $Path -and ! $Domain -and ! $ExpiryDate )){
287+ $cookie = New-Object - TypeName OpenQA.Selenium.Cookie - ArgumentList $Name , $Value
288+ }
289+ Elseif ($Name -and $Value -and $Path -and (! $Domain -and ! $ExpiryDate )){
290+ $cookie = New-Object - TypeName OpenQA.Selenium.Cookie - ArgumentList $Name , $Value , $Path
291+ }
292+ Elseif ($Name -and $Value -and $Path -and $ExpiryDate -and ! $Domain ){
293+ $cookie = New-Object - TypeName OpenQA.Selenium.Cookie - ArgumentList $Name , $Value , $Path , $ExpiryDate
294+ }
295+ Elseif ($Name -and $Value -and $Path -and $ExpiryDate -and $Domain ){
296+ if ($Driver.Url -match $Domain ){
297+ $cookie = New-Object - TypeName OpenQA.Selenium.Cookie - ArgumentList $Name , $Value , $Domain , $Path , $ExpiryDate
298+ }
299+ else {
300+ Throw ' In order to set the cookie the browser needs to be on the cookie domain URL'
301+ }
302+ }
303+ else {
304+ Throw " Incorrect Cookie Layout:
305+ Cookie(String, String)
306+ Initializes a new instance of the Cookie class with a specific name and value.
307+ Cookie(String, String, String)
308+ Initializes a new instance of the Cookie class with a specific name, value, and path.
309+ Cookie(String, String, String, Nullable<DateTime>)
310+ Initializes a new instance of the Cookie class with a specific name, value, path and expiration date.
311+ Cookie(String, String, String, String, Nullable<DateTime>)
312+ Initializes a new instance of the Cookie class with a specific name, value, domain, path and expiration date."
313+ }
267314
268- $cookie = New-Object - TypeName OpenQA.Selenium.Cookie - ArgumentList $Name , $value
269-
270315 $Driver.Manage ().Cookies.AddCookie($cookie )
271316}
272317
0 commit comments