alttester / AltTester-Unity-SDK

AltTester Unity SDK is an open-source UI driven test automation tool that helps you find objects in your game and interacts with them using tests written in C#, Python, Robot or Java.
https://alttester.com/docs/sdk/latest/home.html
GNU General Public License v3.0
57 stars 5 forks source link

[C#] Special characters and syntax errors in code generated in Recorder in `WaitForComponentProperty` #1635

Open iulianatodoran opened 1 month ago

iulianatodoran commented 1 month ago

!!! This is fixed in https://github.com/alttester/AltTester-Desktop/pull/1679

Steps to reproduce

## Actual result ### AR There are some cases in the code generated in Recorder for C# in `WaitForComponentProperty` methods that throw errors: 1. special characters error when running tests generated in the Recorder - code examples that generate the error: `Capsule.WaitForComponentProperty("UnityEngine.Rigidbody", "gameObject.scene.name", JToken.Parse("Scene 1 AltDriverTestScene"), "UnityEngine.PhysicsModule", 1, getPropertyAsString: true);` `Text.WaitForComponentProperty("UnityEngine.UI.Text", "font.material.shader.name", JToken.Parse("GUI/Text Shader"), "UnityEngine.UI", 1, getPropertyAsString: true);` `PlasteredWall.WaitForComponentProperty("UnityEngine.MeshFilter", "gameObject.name", JToken.Parse("PlasteredWall02 (1)"), "UnityEngine.CoreModule", 1, getPropertyAsString: true);` - error thrown: ``` 2024-06-04 10:15:45.4832|Editor|ERROR|Newtonsoft.Json.JsonReaderException : Unexpected character encountered while parsing value: G. Path '', line 0, position 0. at Newtonsoft.Json.JsonTextReader.ParseValue () [0x002ac] in /root/repo/Src/Newtonsoft.Json/JsonTextReader.cs:1817 at Newtonsoft.Json.JsonTextReader.Read () [0x0004c] in /root/repo/Src/Newtonsoft.Json/JsonTextReader.cs:429 at Newtonsoft.Json.Linq.JToken.ReadFrom (Newtonsoft.Json.JsonReader reader, Newtonsoft.Json.Linq.JsonLoadSettings settings) [0x00013] in /root/repo/Src/Newtonsoft.Json/Linq/JToken.cs:2126 at Newtonsoft.Json.Linq.JToken.Load (Newtonsoft.Json.JsonReader reader, Newtonsoft.Json.Linq.JsonLoadSettings settings) [0x00000] in /root/repo/Src/Newtonsoft.Json/Linq/JToken.cs:2227 at Newtonsoft.Json.Linq.JToken.Parse (System.String json, Newtonsoft.Json.Linq.JsonLoadSettings settings) [0x0000c] in /root/repo/Src/Newtonsoft.Json/Linq/JToken.cs:2203 at Newtonsoft.Json.Linq.JToken.Parse (System.String json) [0x00000] in /root/repo/Src/Newtonsoft.Json/Linq/JToken.cs:2189 at TestGiuli3.Test () [0x00055] in D:\AltTester\AltTester-Unity-SDK\AltTester-Unity-SDK\Assets\Examples\Test\Editor\Driver\TestGiuli3.cs:39 at (wrapper managed-to-native) System.Reflection.RuntimeMethodInfo.InternalInvoke(System.Reflection.RuntimeMethodInfo,object,object[],System.Exception&) at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x0006a] in <75633565436c42f0a6426b33f0132ade>:0 UnityEngine.Debug:LogError (object) AltTester.AltTesterUnitySDK.Driver.Logging.UnityTarget:Write (NLog.LogEventInfo) (at Assets/AltTester/Runtime/AltDriver/Logging/UnityTarget.cs:40) NLog.Targets.Target:Write (NLog.Common.AsyncLogEventInfo) NLog.Targets.Target:WriteAsyncThreadSafe (NLog.Common.AsyncLogEventInfo) NLog.Targets.Target:WriteAsyncLogEvent (NLog.Common.AsyncLogEventInfo) NLog.LoggerImpl:WriteToTargetWithFilterChain (NLog.Targets.Target,NLog.Filters.FilterResult,NLog.LogEventInfo,NLog.Common.AsyncContinuation) NLog.LoggerImpl:Write (System.Type,NLog.Internal.TargetWithFilterChain,NLog.LogEventInfo,NLog.LogFactory) NLog.Logger:WriteToTargets (NLog.LogEventInfo,NLog.Internal.TargetWithFilterChain) NLog.Logger:WriteToTargets (NLog.LogLevel,System.IFormatProvider,string) NLog.Logger:Error (string) AltTester.AltTesterUnitySDK.Editor.AltTestRunListener:TestFinished (NUnit.Framework.Interfaces.ITestResult) (at Assets/AltTester/Editor/Scripts/AltTestRunListener.cs:49) NUnit.Framework.Internal.Execution.WorkItem:WorkItemComplete () NUnit.Framework.Internal.Execution.SimpleWorkItem:PerformWork () NUnit.Framework.Internal.Execution.WorkItem:RunTest () NUnit.Framework.Internal.Execution.WorkItem:Execute () NUnit.Framework.Internal.Execution.SimpleWorkItemDispatcher:Dispatch (NUnit.Framework.Internal.Execution.WorkItem) NUnit.Framework.Internal.Execution.CompositeWorkItem:RunChildren () NUnit.Framework.Internal.Execution.CompositeWorkItem:PerformWork () NUnit.Framework.Internal.Execution.WorkItem:RunTest () NUnit.Framework.Internal.Execution.WorkItem:Execute () NUnit.Framework.Internal.Execution.SimpleWorkItemDispatcher:Dispatch (NUnit.Framework.Internal.Execution.WorkItem) NUnit.Framework.Internal.Execution.CompositeWorkItem:RunChildren () NUnit.Framework.Internal.Execution.CompositeWorkItem:PerformWork () NUnit.Framework.Internal.Execution.WorkItem:RunTest () NUnit.Framework.Internal.Execution.WorkItem:Execute () NUnit.Framework.Internal.Execution.SimpleWorkItemDispatcher:RunnerThreadProc () System.Threading.ThreadHelper:ThreadStart () ``` 2. syntax error thrown by VSCode - code examples that generate the error: `Text.WaitForComponentProperty("UnityEngine.UI.Text", "cachedTextGenerator.characters", JToken.Parse("[{""cursorPos"":{},""charWidth"":12.0},{""cursorPos"":{},""charWidth"":8.0},{""cursorPos"":{},""charWidth"":7.0},{""cursorPos"":{},""charWidth"":8.0},{""cursorPos"":{},""charWidth"":4.0},{""cursorPos"":{},""charWidth"":7.0},{""cursorPos"":{},""charWidth"":8.0},{""cursorPos"":{},""charWidth"":8.0},{""cursorPos"":{},""charWidth"":7.0},{""cursorPos"":{},""charWidth"":8.0},{""cursorPos"":{},""charWidth"":3.0},{""cursorPos"":{},""charWidth"":8.0},{""cursorPos"":{},""charWidth"":4.0},{""cursorPos"":{},""charWidth"":3.0},{""cursorPos"":{},""charWidth"":8.0},{""cursorPos"":{},""charWidth"":12.0},{""cursorPos"":{},""charWidth"":8.0},{""cursorPos"":{},""charWidth"":0.0}]"), "UnityEngine.UI", 1, getPropertyAsString: true);` `ScoreText.WaitForComponentProperty("UnityEngine.UI.Text", "font.fontNames", JToken.Parse("[""Luckiest Guy""]"), "UnityEngine.UI", 1, getPropertyAsString: true);` ### Additional info Environment: - AltTester Unity SDK from the `development` branch - commit https://github.com/alttester/AltTester-Unity-SDK/commit/12be0c85bf7ae873f8a06c45ddb7610bcab981a4 - AltTester Desktop from the `development` branch - commit https://github.com/alttester/AltTester-Desktop/commit/7a86f8ad4b2a4a5e19e0e9274e7e1c301efa1941 ## Expected result ### ER There should be no errors for special characters or bad syntax when using the code generated in the Recorder for `WaitForComponent Property` ### Additional info ## Testability
iulianatodoran commented 3 weeks ago

Re-opening this ticket as mentioned in https://github.com/alttester/AltTester-Desktop/issues/1676

iulianatodoran commented 4 days ago

Re-opened https://github.com/alttester/AltTester-Desktop/issues/1676 so I will reopen this ticket as well.