PS コードに問題があります。毎週火曜日に teamcity でブラウザーのテストを開始する必要があります。そして、資格情報を使用してサーバー上で機能する関数を作成し、それに対してテストを実行しようとしました
function HTTP-GetRequest($url, $username, $password)
{
$properties = Resolve-Path "C:\Users\Uladzimir_Vaitsiakho\Documents\CI\Build\CI_2.0\vsphere\properties.ps1"
Write-Host $properties
. $properties
$webRequest = [System.Net.WebRequest]::Create($url)
$webRequest.Credentials = New-Object System.Net.NetworkCredential -ArgumentList $username, $password
$webRequest.PreAuthenticate = $true
$webRequest.Headers.Add("AUTHORIZATION", "Basic");
[System.Net.WebResponse] $resp = $webRequest.GetResponse();
$rs = $resp.GetResponseStream();
[System.IO.StreamReader] $sr = New-Object System.IO.StreamReader -argumentList $rs;
[string] $results = $sr.ReadToEnd();
return $results
}
if (($today.DayOfWeek) -eq "Tuesday")
{
if ($env:Browser -eq "Firefox"){
$url = "http://1111111/httpAuth/action.html?add2Queue=bt6&&env.name=Browser&env.value=Chrome"
HTTP-GetRequest $url, $teamcity_username, $teamcity_password
Write-Host $teamcity_password
Write-Host $teamcity_username
}
if ($env:Browser -eq "Chrome"){
$url = "http://11111/httpAuth/action.html?add2Queue=bt6&&env.name=Browser&env.Value=InternetExplorer"
HTTP-GetRequest $url, $teamcity_username, $teamcity_password
}
}
次の出力には問題がありますが、関数に指定したプロパティと資格情報を含むファイルです。何が問題なのですか?!
"Create" を "System.Uri" 型に変換するための値 "System.Object[]" を持つ引数 "0" を変換できません: "型 "System.Object[] の "System.Object[]" 値を変換できません"「System.Uri」と入力します。" C:\Users\Uladzimir_Vaitsiakho\Documents\qw.ps1:6 char:47 + $webRequest = [System.Net.WebRequest]::Create <<<< ($url) + CategoryInfo : NotSpecified: (:) [] 、 MethodException + FullyQualifiedErrorId : MethodArgumentConversionInvalidCastArgument
プロパティ 'Credentials' がこのオブジェクトに見つかりません。存在し、設定可能であることを確認してください。C:\Users\Uladzimir_Vaitsiakho\Documents\qw.ps1:7 char:14 + $webRequest にあります。<<<< Credentials = New-Object System.Net.NetworkCredential -ArgumentList $username, $password + CategoryInfo : InvalidOperation: (Credentials:String) [], RuntimeException + FullyQualifiedErrorId : PropertyNotFound
プロパティ 'PreAuthenticate' がこのオブジェクトに見つかりません。存在し、設定可能であることを確認してください。C:\Users\Uladzimir_Vaitsiakho\Documents\qw.ps1:10 char:14 + $webRequest にあります。<<<< PreAuthenticate = $true + CategoryInfo : InvalidOperation: (PreAuthenticate:String) []、RuntimeException + FullyQualifiedErrorId : PropertyNotFound
null 値の式でメソッドを呼び出すことはできません。C:\Users\Uladzimir_Vaitsiakho\Documents\qw.ps1:11 char:25 + $webRequest.Headers.Add <<<< ("AUTHORIZATION", "Basic"); + CategoryInfo : InvalidOperation: (Add:String) []、RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull
null 値の式でメソッドを呼び出すことはできません。C:\Users\Uladzimir_Vaitsiakho\Documents\qw.ps1:13 で char:58 + [System.Net.WebResponse] $resp = $webRequest.GetResponse <<<< (); + CategoryInfo : InvalidOperation: (GetResponse:String) []、RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull
null 値の式でメソッドを呼び出すことはできません。C:\Users\Uladzimir_Vaitsiakho\Documents\qw.ps1:14 で char:31 + $rs = $resp.GetResponseStream <<<< (); + CategoryInfo : InvalidOperation: (GetResponseStream:String) []、RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull
New-Object : コンストラクターが見つかりません。System.IO.StreamReader 型の適切なコンストラクターが見つかりません。C:\Users\Uladzimir_Vaitsiakho\Documents\qw.ps1:15 で char:43 + [System.IO.StreamReader] $sr = New-Object <<<< System.IO.StreamReader -argumentList $rs; + CategoryInfo : ObjectNotFound: (:) [New-Object]、PSArgumentException + FullyQualifiedErrorId : CannotFindAppropriateCtor、Microsoft.PowerShell.Commands.NewObjectCommand
null 値の式でメソッドを呼び出すことはできません。C:\Users\Uladzimir_Vaitsiakho\Documents\qw.ps1:16 で char:35 + [文字列] $results = $sr.ReadToEnd <<<< (); + CategoryInfo : InvalidOperation: (ReadToEnd:String) []、RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull