オブジェクト、メッセージおよび結果に関するグローバルプロパティ

SenseTalkでは、オブジェクト、メッセージ、および、特定のコマンドまたは関数の結果に関して、スクリプティング環境での扱われ方を左右できるグローバルプロパティを多数用意しています。SenseTalkがメッセージをどのように処理するかをよく理解しておくと役立ちます。

ローカルプロパティとグローバルプロパティの扱い方に関する追加情報は、SenseTalkにおけるローカルプロパティとグローバルプロパティをご覧ください。

the throwExceptionResultsグローバルプロパティ

値:TrueFalse

デフォルト:True

挙動:このプロパティでは、コマンド動作がエラーに終わったときに例外を投げるかどうかを決定します。the throwExceptionResultsグローバルプロパティをTrueに設定すると、コマンドまたは関数によってresult()が例外オブジェクト(ほとんどのエラー状態で発生)に設定されたとき、この関数を通じてメッセージとして例外を利用できるようにするのではなく、例外を必ず投げます。

例:

set the throwExceptionResults to false

例:

set the throwExceptionResults to false

put url "http://someinvalidURL.com" into PageContents

log the result // 「Error 404 in HTTPStatus: Server returned status code 404」をログします

log "Performed URL GET."

例:

set the throwExceptionResults to false

set myProcessPath to "bad/process/path"

open process myProcessPath // プロセス起動パスが無効なために失敗しますが、エラーは生成されません

set myResult to result() // 結果を変数に格納します

put myResult

if myResult contains "launch path ("&myProcessPath&") not valid" then

LogWarning myResult // 「STProcessException: NSTask - launch path (bad/process/path) not valid」をログします

end if

the breakpointsEnabledグローバルプロパティ

値:TrueFalse

デフォルト:True

挙動:このプロパティでは、スクリプト内で設定されたブレークポイントを遵守するかどうかを決定します。ブレークポイントは、breakpointコマンドを使って設定でき、スクリプトの制御をデバッガに移します。実行中、ブレークポイントを無効にしたい場合は、このプロパティをFalseに設定します。

例:

set the breakpointsEnabled to false

例:

#Calling Script

LoginWorkflow true // LoginWorkflowスクリプトを呼び出し、パラメータ値「true」を渡します

 

#LoginWorkflow Script

params isTestRun // スクリプトをパラメータ表記にし、パラメータ値を1つ受け取ります

if isTestRun is true // スクリプトに「true」のパラメータ値が渡されているかどうかをチェックします

set the BreakpointsEnabled to false // isTestRunの値がtrueであれば、ブレークポイントを無効化します

end if

Click "Login"

breakpoint // the BreakpointsEnabledグローバルプロパティがtrueに設定されている場合にスクリプトを一時停止します

Click "AccountDetails"

関連:

the exceptionグローバルプロパティ

値:Empty、またはtryブロックでキャッチされた例外を記述するプロパティリスト

デフォルト:Empty

挙動:このプロパティには、直近のtryブロックのコンテキストで投げられた例外に関する情報が格納されます。各try文の開始時には、the exceptionがemptyに設定されます。tryブロック内で例外が投げられると、the exceptionに例外オブジェクトが格納されます。その値は、tryブロックのcatch部の中で利用できるほか、次のtry文までは以後いつでも利用可能です。

例外はオブジェクト(プロパティリスト)です。例外オブジェクトはテキスト値を持ち、例外が単にテキストとして表現される場合には、このテキスト値によって簡単な説明が表示されます。しかし、例外オブジェクトには他にも有用な情報が多数格納されており、次のプロパティのうち、1つまたは複数が含まれています。

名前

例外の名前または識別子

reason

例外に与えられた理由

location

例外が発生したスクリプト内の場所を説明するテキスト

callStack

例外発生地点の呼び出しシーケンス情報を与えるスタックフレームオブジェクトのリスト(callStack()関数の戻り値)

scriptError

エラーに関する固有情報を格納したscriptErrorオブジェクト

the exceptionはグローバルプロパティ(コンテナ)であるため、スクリプトでその内容をいつでも自由に修正することができます。この能力は、例外をキャッチしたときに役立ちます。例えば、キャッチした例外を修正したり、追加のプロパティを付け加えたりしてから、再びその例外を投げることが可能です。

注:standardFormat()関数を使うと、例外オブジェクトの全プロパティを表示することができます。

log the standardFormat of the exception

例:

{asText:@"Runtime Error at line 2: Image Not Found - waitfor Error - Unable To Find Any Image On Screen \"UsernameField\" within 5.00 seconds", CallStack:[{Handler:@"globalpropertiesobjmessages", Line:2, MeObjectID:@"C:/Users/Carrie/Documents/Examples3.suite/Scripts/globalpropertiesObjMessages.script<SELECTION>", MessageName:@"on_globalpropertiesobjmessages", MessageType:@"Command", objectType:@"SenseTalkFrame", RepeatIndex:0, ScriptObjectID:@"C:/Users/Carrie/Documents/Examples3.suite/Scripts/globalpropertiesObjMessages.script<SELECTION>", TryDepth:1}], HelpNote:@"For additional help please review the documentation on 'Image Searching'", ImageName:@"UsernameField", Location:@"line 2 of globalpropertiesobjmessages", LogImage:{CaptureDate:@"2017-09-20 17:58:10 -0600", CaptureHost:@"GalaxyS5", CaptureLocation:[198, 126], CaptureScreenSize:[@"1080", @"1920"], Description:@"", HotSpot:[147, 36], ImageLocation:@"", ImageName:@"UsernameField", ImagePath:@"C:/Users/Carrie/Documents/Examples3.suite/Images/UsernameField.png", ImageRectangle:@"", ImageSize:[295, 72], ImageTolerance:57, Pulsing:False, Scale:1, SearchType:@"Smooth"}, LogMessage:@"Unable To Find Any Image On Screen \"UsernameField\" within 5.00 seconds", Name:@"Image Not Found", objectType:@"exception", OtherButton:@"Help...", OtherHelp:@"ePF/using/epf-finding-images.htm", Reason:@"waitfor Error - Unable To Find Any Image On Screen \"UsernameField\" within 5.00 seconds", ScriptError:{AsText:@"Runtime Error at line 2: Image Not Found - waitfor Error - Unable To Find Any Image On Screen \"UsernameField\" within 5.00 seconds", ErrorType:@"Runtime Error", Line:2, Name:@"Image Not Found", objectType:[@"ScriptError", @"exception"], Reason:@"waitfor Error - Unable To Find Any Image On Screen \"UsernameField\" within 5.00 seconds"}}

例:

put the exception

例:

put the exception's name

例:

try

Connect "Windows VM"

catch

put the exception's ScriptError // connectコマンドで例外が投げられた場合、「Runtime Error at line 2: Connection Failed - Unable to connect to Server:192.168.120.128 on port:5900 Unable to Contact Server: 192.168.120.128:5900 (10060:Operation timed out)」を表示します

end try

例:

try

WaitFor 5, "UsernameField"

catch

log the keys of the exception // WaitForコマンドで例外が投げられた場合、「(asText,CallStack,Location,LogMessage,Name,objectType,Reason,ScriptError)」をログします

end try

例:

try

Click "UsernameField"

catch

set the exception's "ExceptionTime" to the time

log the exception's ExceptionTime // Clickコマンドで例外が投げられた場合、例外がキャッチされた時刻をログします。例:「07:01 PM」

end try

例:

try

throw "Invalid Access", "Name or password is wrong"

catch

put the exception -- "Runtime Error at line 2: Invalid Access - Name or password is wrong"

put the exception's name -- "Invalid Access"

put the exception's reason -- "Name or password is wrong"

end try

the frontScriptsグローバルプロパティ

値:Empty、またはメッセージ処理用のオブジェクトもしくはオブジェクトのリスト(すなわち、ライブラリもしくはスクリプト)。

デフォルト:Empty

挙動:このグローバルプロパティは、ターゲットオブジェクトにメッセージが提示されるよりも前にメッセージを処理する機会を得るオブジェクトのリストを格納することができます。the frontScriptsのオブジェクトは、メッセージをインターセプトする機会を得て、潜在的にどのオブジェクトの振る舞いよりも優先されます。これが必要になる場面は稀ですが、メッセージをメッセージパスに沿って渡す前にログしておくといったタスクに役立つ場合があります。

例:

set the frontscripts to "FileStuff" // the frontScriptsを、同じスイート内の別のスクリプトに設定します

例:

set the frontScripts to ("/Users/bkwins/Documents/ePFSuites/Suite17Helper.suite/Scripts/VerifyWikiSearch.script", "/Users/bkwins/Documents/ePFSuites/TableTesting.suite/Scripts/LiveScript.script") // 2つの異なるスイートからのスクリプトを使用するようthe frontScriptsを設定します

関連:

the backScriptsグローバルプロパティ

値:Empty、またはメッセージ処理用のオブジェクトもしくはオブジェクトのリスト(すなわち、ライブラリもしくはスクリプト)。

デフォルト:Empty

挙動:このグローバルプロパティは、ターゲットオブジェクトがメッセージを処理しなかった場合に、ターゲットオブジェクトの後にメッセージを処理する機会を得るオブジェクトのリストを格納することができます。つまり、the backScriptsにオブジェクト(ライブラリまたはスクリプト)を入れることで、どのスクリプトでもそのオブジェクトのハンドラを利用できるようになります。とはいえ、the backScriptの振る舞いよりも優先されるスクリプト独自のハンドラを、各スクリプトで与えることも依然として可能です。

ヒント:SenseTalkには、the backScriptsの追加および削除を簡単にするための特殊なコマンドが2つ用意されています。start using <オブジェクト>コマンドは、スクリプトまたはその他のオブジェクトをthe backScriptsに挿入するコマンドです。stop using <オブジェクト>構文を使うと、the backScriptsに挿入済みのライブラリまたはスクリプトが削除されます。これらのコマンドは、insert <オブジェクト> into the backScriptsおよびremove <オブジェクト> from the backScriptsコマンドと同じものですが、若干簡潔で読みやすくなります。

例:

set the backScripts to "/Users/bkwins/Documents/ePFSuites/Suite17Helper.suite/Scripts/Units.scripts" // the backScriptsを、別のスイート内のスクリプトに設定します

例:

start using "Folder1/Helper1" // Helper1(Folder1より)をthe backScriptsに格納します

関連:

the watchForScriptChangesグローバルプロパティ

値:TrueFalse

デフォルト:False

挙動:このプロパティでは、スクリプトハンドラが呼び出されるときに、SenseTalkがスクリプトハンドラのキャッシュされたコピーを使用するか、または先にソースの更新をチェックするかを決定します。

ディスク上のスクリプトオブジェクトにメッセージが送られると、SenseTalkはそのスクリプトファイルを読み取って、スクリプトをメモリにキャッシュします。するとSenseTalkは、その後オブジェクトが別のメッセージを受け取った場合に、オブジェクトに当該メッセージ用のハンドラがあるかどうかを素早くチェックすることができます。一部の(かなり稀な)状況では、実行中にスクリプト更新の有無をSenseTalkにチェックさせたい場合があるかもしれません。こうした状況においては、the watchForScriptChangesグローバルプロパティをTrueに設定することで、オブジェクトがメッセージを受け取るたびに、SenseTalkがファイル更新の有無をチェックします。ファイルが更新されていれば、読み取りを再度行い、新しい方のハンドラを使用します。実行中は、ハンドラの実行バージョンは変化しません。

例:

set the watchForScriptChanges to true

例:

set the watchForScriptChanges to true

Login's AddPassword // Loginという名前のスクリプトに格納されたAddPasswordという名前のコマンドハンドラを呼び出します

the resultHistoryグローバルプロパティ

値: Empty、またはthe resultで返された値のリスト。

デフォルト:Empty

挙動:このプロパティは、the resultで返された値を、the resultHistoryLimitプロパティの値に達するまで格納します。空以外の結果が設定された場合は必ず、それがthe resultHistoryに挿入されます。the resultHistoryをスクリプト内で使用すると、それまでの文からの結果の値を取得することができます。ただし、空の値は含まれないため、結果を特定の文と突き合わせる際には注意が必要です。

例:

put the resultHistory

例:

RunWithNewResults "Login"

put the resultHistory // 「((handler:"SmokeTestMasterScript", line:"1", result:(Duration:"0.05", Errors:"0", Exceptions:"0", LogFile:"C:/Users/Carrie/Documents/Examples3.suite/Results/Login/20170920_200213.795/LogFile.txt", ReturnValue:"", RunDate:"2017-09-20 20:02:13.795 -0600", Status:"Success", Successes:"1", Warnings:"0")))」を表示します

例:

RunWithNewResults "Login"

put the resultHistory's handler // コマンドを呼び出したハンドラ名を表示します。例:「SmokeTestMasterScript」

例:

GetValue // 「1234」のような値を返すGetValueという名前のスクリプトを呼び出します

waitFor 8, "UsernameField" // WaitForコマンドが所要時間メッセージ(waitForコマンドの実行にかかった時間数)を返します

log the resultHistory // これまでに実行したコマンドのコマンドメッセージを、the resultHistoryLimitに達するまでログします。例:「((handler:"globalpropertiesobjmessages", line:"1", result:"12213213"),(handler:"globalpropertiesobjmessages", line:"2", result:"1.856 seconds"))」

the resultHistoryLimitグローバルプロパティ

値:数値

デフォルト: 100

挙動:このプロパティでは、the resultHistoryグローバルプロパティに格納できる結果の最大数を設定します。

例:

set the resultHistoryLimit to 25

例:

set the resultHistoryLimit to 5 // 直近の結果5つのみを格納できるようにします。

repeat 10 times

WaitFor 10, "UsernameField"

end repeat

put the resultHistory into myHistory // 実行されたWaitForコマンドの新しい方の結果5つを格納します。例:「((handler:"timings", line:"3", result:"2.141 seconds"),(handler:"timings", line:"3", result:"1.838 seconds"),(handler:"timings", line:"3", result:"1.067 seconds"),(handler:"timings", line:"3", result:"1.031 seconds"),(handler:"timings", line:"3", result:"1.075 seconds"))」

 

// 各結果に繰り返しを行って、その所要時間(waitFor結果のresult)をリストに格納します

repeat with each myResult of myHistory

insert myResult's result after Durations

end repeat

log "The average duration of the last 5 waitFors is "&average(Durations) // 最新5結果の所要時間の平均を求めてログします。例:「The average duration of the last 5 waitFors is 1.5756 seconds」

 

This topic was last updated on 2月 01, 2019, at 11:13:23 午前.

Eggplant icon Eggplant.io | Documentation Home | User Forums | Support | Copyright © 2019 Eggplant