Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add output files root path field into AutopilotSetings #115

Merged
merged 11 commits into from
Nov 25, 2024
52 changes: 28 additions & 24 deletions Editor/Localization/ja.po
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,30 @@ msgstr "タイムスケール"
msgid "Time.timeScale on running Autopilot"
msgstr "Time.timeScaleを指定します"

# outputRootPath
msgid "Output Root Path"
msgstr "出力ルートパス"

# outputRootPath tooltip
msgid "Output files root directory path used by Agents, Loggers, and Reporters. When a relative path is specified, the origin is the project root in the Editor, and Application.persistentDataPath on the Player."
msgstr "Agent、Logger、および Reporter が出力するファイルのルートディレクトリパスを指定します。相対パスが指定されたときの起点は、エディターではプロジェクトルート、プレーヤーでは Application.persistentDataPath になります。"

# screenshotsPath
msgid "Screenshots Path"
msgstr "スクリーンショット出力パス"

# screenshotsPath tooltip
msgid "Screenshots output directory path used by Agents. When a relative path is specified, relative to the outputRootPath."
msgstr "Agent が撮影するスクリーンショットの出力ディレクトリパスを指定します。相対パスが指定されたとき、outputRootPath が起点となります。"

# cleanScreenshots
msgid "Clean Screenshots"
msgstr "スクリーンショットを消去"

# cleanScreenshots tooltip
msgid "Clean screenshots under screenshotsPath when launching Autopilot."
msgstr "オートパイロットを起動するとき、screenshotsPath 下のスクリーンショットを消去します"

# logger
msgid "Loggers"
msgstr "Loggers"
Expand Down Expand Up @@ -333,26 +357,6 @@ msgstr "有効"
msgid "Whether screenshot is enabled or not"
msgstr "スクリーンショット撮影を有効にします"

# screenshot directory
msgid "Directory"
msgstr "ディレクトリ"

# screenshot directory path
msgid "Path"
msgstr "パス"

# screenshot directory path tooltip
msgid "Directory path to save screenshots"
msgstr "スクリーンショットの保存先ディレクトリのパス"

# screenshot directory use default
msgid "Use Default"
msgstr "デフォルト値を使用"

# screenshot directory use default tooltip
msgid "Whether using a default directory path to save screenshots or specifying it manually. Default value is specified by command line argument \"-testHelperScreenshotDirectory\". If the command line argument is also omitted, Application.persistentDataPath + \"/TestHelper/Screenshots/\" is used."
msgstr "スクリーンショットの保存先のディレクトリ名にデフォルト値を使用します。デフォルト値はコマンドライン引数 \"-testHelperScreenshotDirectory\" で指定します。コマンドライン引数も省略した場合は、Application.persistentDataPath + \"/TestHelper/Screenshots/\" が使用されます。"

# screenshot filename
msgid "Filename"
msgstr "ファイル名"
Expand Down Expand Up @@ -509,8 +513,8 @@ msgid "Output File Path"
msgstr "出力ファイルパス"

# Output Path tooltip
msgid "Log output file path. Specify relative path from project root or absolute path."
msgstr "ログ出力ファイルのパス。プロジェクトルートからの相対パスまたは絶対パスを指定します"
msgid "Output path for log file path. When a relative path is specified, relative to the AutopilotSettings.outputRootPath."
msgstr "ログファイルの出力先パスを指定します。相対パスが指定されたとき、AutopilotSettings.outputRootPath が起点となります"

# Timestamp
msgid "Timestamp"
Expand Down Expand Up @@ -544,8 +548,8 @@ msgid "Output File Path"
msgstr "出力ファイルパス"

# outputPath tooltip
msgid "Relative path from the project root directory. When run on player, it will be the Application.persistentDataPath."
msgstr "プロジェクトルートからの相対パスを指定します。プレイヤー実行の際は Application.persistentDataPath が起点となります"
msgid "Output path for JUnit XML format file. When a relative path is specified, relative to the AutopilotSettings.outputRootPath."
msgstr "JUnit XML形式ファイルの出力先パスを指定します。相対パスが指定されたとき、AutopilotSettings.outputRootPath が起点となります"


#: Editor/UI/Reporters/SlackReporterEditor.cs
Expand Down
39 changes: 0 additions & 39 deletions Editor/UI/Agents/UGUIMonkeyAgentEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,6 @@ public class UGUIMonkeyAgentEditor : UnityEditor.Editor
private SerializedProperty _screenshotEnabledProp;
private GUIContent _screenshotEnabledGUIContent;

private static readonly string s_screenshotDirectory = L10n.Tr("Directory");
private static readonly string s_screenshotDefaultDirectory = L10n.Tr("Use Default");

private static readonly string s_screenshotDefaultDirectoryTooltip = L10n.Tr(
@"Whether using a default directory path to save screenshots or specifying it manually. Default value is specified by command line argument ""-testHelperScreenshotDirectory"". If the command line argument is also omitted, Application.persistentDataPath + ""/TestHelper/Screenshots/"" is used."
);

private static readonly string s_screenshotDirectoryPath = L10n.Tr("Path");
private static readonly string s_screenshotDirectoryPathTooltip = L10n.Tr("Directory path to save screenshots");
private SerializedProperty _screenshotDefaultDirectoryProp;
private GUIContent _screenshotDefaultDirectoryGUIContent;
private SerializedProperty _screenshotDirectoryProp;
private GUIContent _screenshotDirectoryGUIContent;

private static readonly string s_screenshotFilename = L10n.Tr("Filename");
private static readonly string s_screenshotDefaultFilenamePrefix = L10n.Tr("Use Default");

Expand Down Expand Up @@ -171,18 +157,6 @@ private void Initialize()
_screenshotEnabledProp = serializedObject.FindProperty(nameof(UGUIMonkeyAgent.screenshotEnabled));
_screenshotEnabledGUIContent = new GUIContent(s_screenshotEnabled, s_screenshotEnabledTooltip);

_screenshotDefaultDirectoryProp =
serializedObject.FindProperty(nameof(UGUIMonkeyAgent.defaultScreenshotDirectory));
_screenshotDefaultDirectoryGUIContent = new GUIContent(
s_screenshotDefaultDirectory,
s_screenshotDefaultDirectoryTooltip
);
_screenshotDirectoryProp = serializedObject.FindProperty(nameof(UGUIMonkeyAgent.screenshotDirectory));
_screenshotDirectoryGUIContent = new GUIContent(
s_screenshotDirectoryPath,
s_screenshotDirectoryPathTooltip
);

_screenshotDefaultFilenamePrefixProp =
serializedObject.FindProperty(nameof(UGUIMonkeyAgent.defaultScreenshotFilenamePrefix));
_screenshotDefaultFilenamePrefixGUIContent = new GUIContent(
Expand Down Expand Up @@ -300,19 +274,6 @@ public override void OnInspectorGUI()
EditorGUILayout.PropertyField(_screenshotEnabledProp, _screenshotEnabledGUIContent);
if (_screenshotEnabledProp.boolValue)
{
EditorGUILayout.LabelField(s_screenshotDirectory, EditorStyles.boldLabel);
using (new EditorGUI.IndentLevelScope())
{
EditorGUILayout.PropertyField(
_screenshotDefaultDirectoryProp,
_screenshotDefaultDirectoryGUIContent
);
if (!_screenshotDefaultDirectoryProp.boolValue)
{
EditorGUILayout.PropertyField(_screenshotDirectoryProp, _screenshotDirectoryGUIContent);
}
}

EditorGUILayout.LabelField(s_screenshotFilename, EditorStyles.boldLabel);
using (new EditorGUI.IndentLevelScope())
{
Expand Down
4 changes: 3 additions & 1 deletion Editor/UI/Loggers/FileLoggerEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,19 @@ namespace DeNA.Anjin.Editor.UI.Loggers
[CustomEditor(typeof(FileLoggerAsset))]
public class FileLoggerEditor : UnityEditor.Editor
{
// @formatter:off
private static readonly string s_description = L10n.Tr("Description");
private static readonly string s_descriptionTooltip = L10n.Tr("Description about this Logger instance");

private static readonly string s_outputPath = L10n.Tr("Output File Path");
private static readonly string s_outputPathTooltip = L10n.Tr("Log output file path. Specify relative path from project root or absolute path.");
private static readonly string s_outputPathTooltip = L10n.Tr("Output path for log file path. When a relative path is specified, relative to the AutopilotSettings.outputRootPath.");

private static readonly string s_filterLogType = L10n.Tr("Filter LogType");
private static readonly string s_filterLogTypeTooltip = L10n.Tr("To selective enable debug log message");

private static readonly string s_timestamp = L10n.Tr("Timestamp");
private static readonly string s_timestampTooltip = L10n.Tr("Output timestamp to log entities");
// @formatter:on

/// <inheritdoc/>
public override void OnInspectorGUI()
Expand Down
2 changes: 1 addition & 1 deletion Editor/UI/Reporters/JUnitXmlReporterEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class JUnitXmlReporterEditor : UnityEditor.Editor
private SerializedProperty _descriptionProp;

private static readonly string s_outputPath = L10n.Tr("Output File Path");
private static readonly string s_outputPathTooltip = L10n.Tr("Relative path from the project root directory. When run on player, it will be the Application.persistentDataPath.");
private static readonly string s_outputPathTooltip = L10n.Tr("Output path for JUnit XML format file. When a relative path is specified, relative to the AutopilotSettings.outputRootPath.");
private GUIContent _outputPathLabel;
private SerializedProperty _outputPathProp;
// @formatter:on
Expand Down
15 changes: 15 additions & 0 deletions Editor/UI/Settings/AutopilotSettingsEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ public class AutopilotSettingsEditor : UnityEditor.Editor
private static readonly string s_randomSeedTooltip = L10n.Tr("Random using the specified seed value");
private static readonly string s_timeScale = L10n.Tr("Time Scale");
private static readonly string s_timeScaleTooltip = L10n.Tr("Time.timeScale on running Autopilot");
private static readonly string s_outputRootPath = L10n.Tr("Output Root Path");
private static readonly string s_outputRootPathTooltip = L10n.Tr("Output files root directory path used by Agents, Loggers, and Reporters. When a relative path is specified, the origin is the project root in the Editor, and Application.persistentDataPath on the Player.");
private static readonly string s_screenshotsPath = L10n.Tr("Screenshots Path");
private static readonly string s_screenshotsPathTooltip = L10n.Tr("Screenshots output directory path used by Agents. When a relative path is specified, relative to the outputRootPath.");
private static readonly string s_cleanScreenshots = L10n.Tr("Clean Screenshots");
private static readonly string s_cleanScreenshotsTooltip = L10n.Tr("Clean screenshots under screenshotsPath when launching Autopilot.");

private static readonly string s_loggers = L10n.Tr("Loggers");
private static readonly string s_loggersTooltip = L10n.Tr("List of Loggers used for this autopilot settings. If omitted, Debug.unityLogger will be used as default.");
Expand Down Expand Up @@ -93,6 +99,15 @@ public override void OnInspectorGUI()
new GUIContent(s_randomSeed, s_randomSeedTooltip));
EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(AutopilotSettings.timeScale)),
new GUIContent(s_timeScale, s_timeScaleTooltip));
EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(AutopilotSettings.outputRootPath)),
new GUIContent(s_outputRootPath, s_outputRootPathTooltip));
EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(AutopilotSettings.screenshotsPath)),
new GUIContent(s_screenshotsPath, s_screenshotsPathTooltip));
EditorGUI.BeginDisabledGroup(string.IsNullOrEmpty(((AutopilotSettings)target).screenshotsPath));
EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(AutopilotSettings.cleanScreenshots)),
new GUIContent(s_cleanScreenshots, s_cleanScreenshotsTooltip));
EditorGUI.EndDisabledGroup();

EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(AutopilotSettings.loggerAssets)),
new GUIContent(s_loggers, s_loggersTooltip));
EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(AutopilotSettings.reporters)),
Expand Down
26 changes: 16 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ for specifying, e.g., `ErrorHandlerAgent` and `UGUIEmergencyExitAgent`.
This item can also be overridden from the commandline (see below).</dd>
<dt>Time Scale</dt><dd>Time.timeScale. Default is 1.0.
This item can also be overridden from the commandline (see below).</dd>
<dt>Output Root Path</dt><dd>Output files root directory path used by Agents, Loggers, and Reporters. When a relative path is specified, the origin is the project root in the Editor, and Application.persistentDataPath on the Player.
This item can also be overridden from the commandline (see below).</dd>
<dt>Screenshots Path</dt><dd>Screenshots output directory path used by Agents. When a relative path is specified, relative to the outputRootPath.
This item can also be overridden from the commandline (see below).</dd>
<dt>Clean Screenshots</dt><dd>Clean screenshots under screenshotsPath when launching Autopilot.</dd>
<dt>Loggers</dt><dd>Logger used for this autopilot settings. If omitted, <code>Debug.unityLogger</code> will be used as default.</dd>
<dt>Reporters</dt><dd>Reporter to be called on Autopilot terminate.</dd>
</dl>
Expand Down Expand Up @@ -200,22 +205,24 @@ For details on each argument, see the entry of the same name in the "Generate an
<dt>LIFESPAN_SEC</dt><dd>Specifies the execution time limit in seconds</dd>
<dt>RANDOM_SEED</dt><dd>Specifies when you want to fix the seed given to the pseudo-random number generator</dd>
<dt>TIME_SCALE</dt><dd>Specifies the Time.timeScale. Default is 1.0</dd>
<dt>OUTPUT_ROOT_DIRECTORY_PATH</dt><dd>Output files root directory path used by Agents, Loggers, and Reporters.</dd>
<dt>SCREENSHOTS_DIRECTORY_PATH</dt><dd>Screenshots output directory path used by Agents.</dd>
</dl>

In both cases, the key should be prefixed with `-` and specified as `-LIFESPAN_SEC 60`.


### 3. Run in Play Mode test

Autopilot works within your test code using the async method `Launcher.LaunchAutopilotAsync(string)`.
Autopilot works within your test code using the static method `Launcher.LaunchAutopilotAsync(string)`.
Specify the `AutopilotSettings` file path via the argument.

```
[Test]
public async Task LaunchAutopilotInTest()
{
// Load the first scene
await SceneManager.LoadSceneAsync(0);
// Load the first scene (required scene in "Scenes in Build")
await SceneManager.LoadSceneAsync("Title");

// Launch autopilot
await Launcher.LaunchAutopilotAsync("Assets/Path/To/AutopilotSettings.asset");
Expand All @@ -227,10 +234,14 @@ public async Task LaunchAutopilotInTest()

> [!WARNING]
> When running tests on a player, any necessary configuration files must be placed in the `Resources` folder to be included in the player build. It can use `IPrebuildSetup` and `IPostBuildCleanup` to insert processing into the test player build.
> The file path is specified relative to the `Resources` folder without the extension (".asset").

> [!NOTE]
> The test will fail if the test-runner detects a `LogException` or `LogError` output. You can suppress this by using `LogAssert.ignoreFailingMessages` assuming that you will use Anjin for error handling.

> [!NOTE]
> If running multiple scenarios in succession, you can preserve the output files by specifying different paths in `AutopilotSettings.outputRootPath`.



## Built-in Agents
Expand All @@ -257,7 +268,6 @@ An instance of this Agent (.asset file) can contain the following.

<dl>
<dt>Enabled</dt><dd>Whether screenshot is enabled or not</dd>
<dt>Directory</dt><dd><b>Use Default: </b>Whether using a default directory path to save screenshots or specifying it manually. Default value is specified by command line argument "-testHelperScreenshotDirectory". If the command line argument is also omitted, `Application.persistentDataPath` + "/TestHelper/Screenshots/" is used.<br><b>Path: </b>Directory path to save screenshots</dd>
<dt>Filename</dt><dd><b>Use Default: </b>Whether using a default prefix of screenshots filename or specifying it manually. Default value is Agent name<br><b>Prefix: </b>Prefix of screenshots filename</dd>
<dt>Super Size</dt><dd>The factor to increase resolution with. Neither this nor Stereo Capture Mode can be specified</dd>
<dt>Stereo Capture Mode</dt><dd>The eye texture to capture when stereo rendering is enabled. Neither this nor Resolution Factor can be specified</dd>
Expand Down Expand Up @@ -285,10 +295,6 @@ The recording file (.json) is saved under the Assets/Recordings/ folder and can
Note that the Recorded Playback function in Automated QA can record operations across Scene transitions, but in Anjin, when the Scene is switched, the Agent is also forcibly switched, so playback is also interrupted.
Therefore, please be careful to record in units of Scenes.

A screenshot of the operation by Automated QA is stored under `Application.persistentDataPath/Anjin`.
The `Application.persistentDataPath` for each platform can be found in the Unity manual at
[Scripting API: Application.persistentDataPath](https://docs.unity3d.com/ScriptReference/Application-persistentDataPath.html).

> [!WARNING]
> The Automated QA package outputs `LogType.Error` to the console when playback fails (e.g., the target Button cannot be found). The following setting is required to detect this and terminate the autopilot.
> 1. Add [ErrorHandlerAgent](#ErrorHandlerAgent) and set `Handle Error` to `Terminate Autopilot`.
Expand Down Expand Up @@ -456,7 +462,7 @@ A Logger that outputs to a specified file.
The instance of this Logger (.asset file) can have the following settings.

<dl>
<dt>Output File Path</dt><dd>Log output file path. Specify relative path from project root or absolute path. When run on player, it will be the <code>Application.persistentDataPath</code>.
<dt>Output File Path</dt><dd>Output path for log file path. When a relative path is specified, relative to the <code>AutopilotSettings.outputRootPath</code>.
It can be overwritten with the command line argument <code>-FILE_LOGGER_OUTPUT_PATH</code>, but be careful if multiple FileLoggers are defined, they will all be overwritten with the same value.</dd>
<dt>Filter LogType</dt><dd>To selective enable debug log message</dd>
<dt>Timestamp</dt><dd>Output timestamp to log entities</dd>
Expand All @@ -477,7 +483,7 @@ If there are zero errors and zero failures, the autopilot run is considered to h
The instance of this Reporter (.asset file) can have the following settings.

<dl>
<dt>Output File Path</dt><dd>JUnit XML report file output path. Specify relative path from project root or absolute path. When run on player, it will be the <code>Application.persistentDataPath</code>.
<dt>Output File Path</dt><dd>Output path for JUnit XML format file. When a relative path is specified, relative to the <code>AutopilotSettings.outputRootPath</code>.
It can be overwritten with the command line argument <code>-JUNIT_REPORT_PATH</code>, but be careful if multiple JUnitXmlReporters are defined, they will all be overwritten with the same value.</dd>
</dl>

Expand Down
Loading