Skip to content

Commit

Permalink
Merge pull request #40 from nowsprinting/feature/pluggable_monkey_ope…
Browse files Browse the repository at this point in the history
…rators

Upgrade test-helper.monkey package to v0.11.0 (pluggable operators)
  • Loading branch information
Kuniwak authored Apr 9, 2024
2 parents bcf177f + 53fd480 commit 8d886c8
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 83 deletions.
8 changes: 8 additions & 0 deletions Editor/Localization/ja.po
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,10 @@ msgstr "コンポーネント探索時間[秒]"
msgid "Seconds to determine that an error has occurred when an object that can be interacted with does not exist"
msgstr "インタラクティブな要素を探索する秒数を指定します。探索時間がこれを超えるとエラーを発生させます"

# uGUI click and hold operator options
msgid "Touch and Hold Operator Options"
msgstr "タッチ&ホールド・オペレーター設定"

# touchAndHoldDelayMillis
msgid "Touch and Hold Millis"
msgstr "タッチ&ホールド時間[ミリ秒]"
Expand All @@ -322,6 +326,10 @@ msgstr "Gizmos を有効"
msgid "Show Gizmos on GameView during running monkey test if true"
msgstr "もし有効ならモンキー操作中の GameView に Gizmo を表示します。もし無効なら GameView に Gizmo を表示しません"

# uGUI text input operator options
msgid "Text Input Operator Options"
msgstr "テキスト入力オペレーター設定"

# random string parameters table
msgid "Random String Parameters Table"
msgstr "ランダム文字列パラメータ表"
Expand Down
182 changes: 105 additions & 77 deletions Editor/UI/Agents/UGUIMonkeyAgentEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,6 @@ public class UGUIMonkeyAgentEditor : UnityEditor.Editor
private SerializedProperty _timeoutProp;
private GUIContent _timeoutGUIContent;

private static readonly string s_touchAndHoldDelayMillis = L10n.Tr("Touch and Hold Millis");
private static readonly string s_touchAndHoldDelayMillisTooltip = L10n.Tr("Delay time for touch-and-hold [ms]");
private SerializedProperty _touchAndHoldDelayMillisProp;
private GUIContent _touchAndHoldDelayMillisGUIContent;

private static readonly string s_gizmos = L10n.Tr("Enable Gizmos");

private static readonly string s_gizmosTooltip =
Expand All @@ -57,24 +52,7 @@ public class UGUIMonkeyAgentEditor : UnityEditor.Editor
private SerializedProperty _gizmosProp;
private GUIContent _gizmosGUIContent;

private static readonly string s_randomStringParams = L10n.Tr("Random String Parameters Table");
private static readonly string s_randomStringParamsEntryKey = L10n.Tr("Game Object Name");
private static readonly string s_randomStringParamsEntryKind = L10n.Tr("Characters Kind");
private static readonly string s_randomStringParamsEntryMinLength = L10n.Tr("Minimum Length");
private static readonly string s_randomStringParamsEntryMaxLength = L10n.Tr("Maximum Length");
private SerializedProperty _randomStringParametersMapProp;
private ReorderableList _randomStringParamsMapList;
private const float Padding = 2f;
private const int NumberOfLines = 4;

private static readonly float s_elementHeight =
EditorGUIUtility.singleLineHeight * NumberOfLines + Padding * (NumberOfLines + 1);

private GUIContent _randomStringParamsEntryKeyGUIContent;
private GUIContent _randomStringParamsEntryKindGUIContent;
private GUIContent _randomStringParamsEntryMinLengthGUIContent;
private GUIContent _randomStringParamsEntryMaxLengthGUIContent;

// Screenshot options
private static readonly string s_screenshotOptions = L10n.Tr("Screenshot Options");
private static readonly string s_screenshotEnabled = L10n.Tr("Enabled");
private static readonly string s_screenshotEnabledTooltip = L10n.Tr("Whether screenshot is enabled or not");
Expand Down Expand Up @@ -135,6 +113,35 @@ public class UGUIMonkeyAgentEditor : UnityEditor.Editor
private const ScreenCapture.StereoScreenCaptureMode DefaultStereoScreenCaptureMode =
ScreenCapture.StereoScreenCaptureMode.LeftEye;

// uGUI click and hold operator options
private static readonly string s_uGUIClickAndHoldOperatorOptions = L10n.Tr("Touch and Hold Operator Options");
private static readonly string s_touchAndHoldDelayMillis = L10n.Tr("Touch and Hold Millis");
private static readonly string s_touchAndHoldDelayMillisTooltip = L10n.Tr("Delay time for touch-and-hold [ms]");
private SerializedProperty _touchAndHoldDelayMillisProp;
private GUIContent _touchAndHoldDelayMillisGUIContent;

// uGUI text input operator options
private static readonly string s_uGUITextInputOperatorOptions = L10n.Tr("Text Input Operator Options");
private static readonly string s_randomStringParams = L10n.Tr("Random String Parameters Table");
private static readonly string s_randomStringParamsEntryKey = L10n.Tr("Game Object Name");
private static readonly string s_randomStringParamsEntryKind = L10n.Tr("Characters Kind");
private static readonly string s_randomStringParamsEntryMinLength = L10n.Tr("Minimum Length");
private static readonly string s_randomStringParamsEntryMaxLength = L10n.Tr("Maximum Length");
private SerializedProperty _randomStringParametersMapProp;
private ReorderableList _randomStringParamsMapList;
private const float Padding = 2f;
private const int NumberOfLines = 4;

private static readonly float s_elementHeight =
EditorGUIUtility.singleLineHeight * NumberOfLines + Padding * (NumberOfLines + 1);

private GUIContent _randomStringParamsEntryKeyGUIContent;
private GUIContent _randomStringParamsEntryKindGUIContent;
private GUIContent _randomStringParamsEntryMinLengthGUIContent;
private GUIContent _randomStringParamsEntryMaxLengthGUIContent;

private const float SpacerPixels = 10f;
private const float SpacerPixelsUnderHeader = 4f;

private void OnEnable()
{
Expand All @@ -157,16 +164,62 @@ private void Initialize()
serializedObject.FindProperty(nameof(UGUIMonkeyAgent.secondsToErrorForNoInteractiveComponent));
_timeoutGUIContent = new GUIContent(s_timeout, s_timeoutToolTip);

_gizmosProp = serializedObject.FindProperty(nameof(UGUIMonkeyAgent.gizmos));
_gizmosGUIContent = new GUIContent(s_gizmos, s_gizmosTooltip);

// Screenshot options
_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(
s_screenshotDefaultFilenamePrefix,
s_screenshotDefaultFilenamePrefixTooltip
);
_screenshotFilenamePrefixProp =
serializedObject.FindProperty(nameof(UGUIMonkeyAgent.screenshotFilenamePrefix));
_screenshotFilenamePrefixGUIContent = new GUIContent(
s_screenshotFilenamePrefix,
s_screenshotFilenamePrefixTooltip
);

_screenshotSuperSizeProp = serializedObject.FindProperty(nameof(UGUIMonkeyAgent.screenshotSuperSize));
_screenshotSuperSizeGUIContent = new GUIContent(s_screenshotSuperSize, s_screenshotSuperSizeTooltip);
_screenshotSuperSizeGUIContentDisabled = new GUIContent(DefaultSuperSize.ToString());

_screenshotStereoCaptureModeProp =
serializedObject.FindProperty(nameof(UGUIMonkeyAgent.screenshotStereoCaptureMode));
_screenshotStereoCaptureModeGUIContent = new GUIContent(
s_screenshotStereoCaptureMode,
s_screenshotStereoCaptureModeTooltip
);
_screenshotStereoCaptureModeGUIContentDisabled = new GUIContent(
DefaultStereoScreenCaptureMode.ToString(),
s_screenshotStereoCaptureModeTooltip
);

// uGUI click and hold operator options
_touchAndHoldDelayMillisProp =
serializedObject.FindProperty(nameof(UGUIMonkeyAgent.touchAndHoldDelayMillis));
_touchAndHoldDelayMillisGUIContent = new GUIContent(
s_touchAndHoldDelayMillis,
s_touchAndHoldDelayMillisTooltip
);

_gizmosProp = serializedObject.FindProperty(nameof(UGUIMonkeyAgent.gizmos));
_gizmosGUIContent = new GUIContent(s_gizmos, s_gizmosTooltip);

// uGUI text input operator options
_randomStringParamsEntryKeyGUIContent = new GUIContent(s_randomStringParamsEntryKey);
_randomStringParamsEntryKindGUIContent = new GUIContent(s_randomStringParamsEntryKind);
_randomStringParamsEntryMinLengthGUIContent = new GUIContent(s_randomStringParamsEntryMinLength);
Expand All @@ -180,13 +233,14 @@ private void Initialize()
// XXX: Discarding parameters cannot be used on Unity 2019.x .
// ReSharper disable UnusedParameter.Local
drawElementCallback = (rect, index, isActive, isFocused) =>
// ReSharper enable UnusedParameter.Local
// ReSharper enable UnusedParameter.Local
{
var elemProp = _randomStringParametersMapProp.GetArrayElementAtIndex(index);
var rect1 = new Rect(rect) { y = rect.y + Padding, height = EditorGUIUtility.singleLineHeight };
EditorGUI.PropertyField(
rect1,
elemProp.FindPropertyRelative(nameof(UGUIMonkeyAgent.RandomStringParametersEntry.GameObjectName)),
elemProp.FindPropertyRelative(
nameof(UGUIMonkeyAgent.RandomStringParametersEntry.GameObjectName)),
_randomStringParamsEntryKeyGUIContent
);

Expand All @@ -197,7 +251,8 @@ private void Initialize()
};
EditorGUI.PropertyField(
rect2,
elemProp.FindPropertyRelative(nameof(UGUIMonkeyAgent.RandomStringParametersEntry.CharactersKind)),
elemProp.FindPropertyRelative(
nameof(UGUIMonkeyAgent.RandomStringParametersEntry.CharactersKind)),
_randomStringParamsEntryKindGUIContent
);
var rect3 = new Rect(rect)
Expand All @@ -207,7 +262,8 @@ private void Initialize()
};
EditorGUI.PropertyField(
rect3,
elemProp.FindPropertyRelative(nameof(UGUIMonkeyAgent.RandomStringParametersEntry.MinimumLength)),
elemProp.FindPropertyRelative(nameof(UGUIMonkeyAgent.RandomStringParametersEntry
.MinimumLength)),
_randomStringParamsEntryMinLengthGUIContent
);
var rect4 = new Rect(rect)
Expand All @@ -217,54 +273,12 @@ private void Initialize()
};
EditorGUI.PropertyField(
rect4,
elemProp.FindPropertyRelative(nameof(UGUIMonkeyAgent.RandomStringParametersEntry.MaximumLength)),
elemProp.FindPropertyRelative(nameof(UGUIMonkeyAgent.RandomStringParametersEntry
.MaximumLength)),
_randomStringParamsEntryMaxLengthGUIContent
);
}
};

_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(
s_screenshotDefaultFilenamePrefix,
s_screenshotDefaultFilenamePrefixTooltip
);
_screenshotFilenamePrefixProp =
serializedObject.FindProperty(nameof(UGUIMonkeyAgent.screenshotFilenamePrefix));
_screenshotFilenamePrefixGUIContent = new GUIContent(
s_screenshotFilenamePrefix,
s_screenshotFilenamePrefixTooltip
);

_screenshotSuperSizeProp = serializedObject.FindProperty(nameof(UGUIMonkeyAgent.screenshotSuperSize));
_screenshotSuperSizeGUIContent = new GUIContent(s_screenshotSuperSize, s_screenshotSuperSizeTooltip);
_screenshotSuperSizeGUIContentDisabled = new GUIContent(DefaultSuperSize.ToString());

_screenshotStereoCaptureModeProp =
serializedObject.FindProperty(nameof(UGUIMonkeyAgent.screenshotStereoCaptureMode));
_screenshotStereoCaptureModeGUIContent = new GUIContent(
s_screenshotStereoCaptureMode,
s_screenshotStereoCaptureModeTooltip
);
_screenshotStereoCaptureModeGUIContentDisabled = new GUIContent(
DefaultStereoScreenCaptureMode.ToString(),
s_screenshotStereoCaptureModeTooltip
);
}


Expand All @@ -277,10 +291,10 @@ public override void OnInspectorGUI()
EditorGUILayout.PropertyField(_lifespanProp, _lifespanGUIContent);
EditorGUILayout.PropertyField(_delayMillisProp, _delayMillisGUIContent);
EditorGUILayout.PropertyField(_timeoutProp, _timeoutGUIContent);
EditorGUILayout.PropertyField(_touchAndHoldDelayMillisProp, _touchAndHoldDelayMillisGUIContent);
EditorGUILayout.PropertyField(_gizmosProp, _gizmosGUIContent);
_randomStringParamsMapList.DoLayoutList();
EditorGUILayout.LabelField(s_screenshotOptions, EditorStyles.boldLabel);

// Screenshot options
DrawHeader(s_screenshotOptions);
using (new EditorGUI.IndentLevelScope())
{
EditorGUILayout.PropertyField(_screenshotEnabledProp, _screenshotEnabledGUIContent);
Expand Down Expand Up @@ -358,9 +372,23 @@ public override void OnInspectorGUI()
}
}

// uGUI click and hold operator options
DrawHeader(s_uGUIClickAndHoldOperatorOptions);
EditorGUILayout.PropertyField(_touchAndHoldDelayMillisProp, _touchAndHoldDelayMillisGUIContent);

// uGUI text input operator options
DrawHeader(s_uGUITextInputOperatorOptions);
_randomStringParamsMapList.DoLayoutList();

serializedObject.ApplyModifiedProperties();
}

private static void DrawHeader(string label)
{
GUILayout.Space(SpacerPixels);
GUILayout.Label(label, EditorStyles.boldLabel);
GUILayout.Space(SpacerPixelsUnderHeader);
}

// XXX: Fallback for Unity 2019.x
private static int Clamp(int value, int min, int max) => value < min ? min : max < value ? max : value;
Expand Down
16 changes: 11 additions & 5 deletions Runtime/Agents/UGUIMonkeyAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Cysharp.Threading.Tasks;
using TestHelper.Monkey;
using TestHelper.Monkey.Annotations.Enums;
using TestHelper.Monkey.Operators;
using TestHelper.Monkey.Random;
using TestHelper.Monkey.ScreenshotFilenameStrategies;
using TestHelper.Random;
Expand Down Expand Up @@ -98,16 +99,13 @@ public override async UniTask Run(CancellationToken token)
{
Logger.Log($"Enter {this.name}.Run()");

var random = new RandomImpl(this.Random.Next());
var random = new RandomWrapper(this.Random.Next());
var config = new MonkeyConfig
{
Lifetime = lifespanSec > 0 ? TimeSpan.FromSeconds(lifespanSec) : TimeSpan.MaxValue,
DelayMillis = delayMillis,
Random = random,
RandomString = new RandomStringImpl(random),
RandomStringParametersStrategy = GetRandomStringParameters,
SecondsToErrorForNoInteractiveComponent = secondsToErrorForNoInteractiveComponent,
TouchAndHoldDelayMillis = touchAndHoldDelayMillis,
Gizmos = gizmos,
Screenshots = screenshotEnabled
? new ScreenshotOptions
Expand All @@ -119,7 +117,15 @@ public override async UniTask Run(CancellationToken token)
SuperSize = screenshotSuperSize,
StereoCaptureMode = screenshotStereoCaptureMode
}
: null
: null,
Operators = new IOperator[]
{
new UGUIClickOperator(), //
new UGUIClickAndHoldOperator(holdMillis: touchAndHoldDelayMillis), //
new UGUITextInputOperator(
randomStringParams: GetRandomStringParameters,
randomString: new RandomStringImpl(random)),
},
};
await Monkey.Run(config, token);

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"changelogUrl": "https://github.com/DeNA/Anjin/releases",
"dependencies": {
"com.cysharp.unitask": "2.3.3",
"com.nowsprinting.test-helper.monkey": "0.8.0",
"com.nowsprinting.test-helper.monkey": "0.11.0",
"com.nowsprinting.test-helper.random": "0.3.0",
"com.unity.automated-testing": "0.8.1-preview.2"
},
Expand Down

0 comments on commit 8d886c8

Please sign in to comment.