microsoft / PowerApps-TestEngine

MIT License
100 stars 30 forks source link

`System.NullReferenceException: Object reference not set to an instance of an object.` error with Combo Box #164

Closed m-saikiran closed 1 year ago

m-saikiran commented 1 year ago

App: SampleAppforTestEngine_20221026141239.zip

Test Suite:

testSuite:
  testSuiteName: SampleTestSuite
  testSuiteDescription: Verify the functionality of ComboBox in Canvas App
  persona: User1
  appLogicalName: <REDACTED>

  testCases:
    - testCaseName: NavigateToSecondScreen
      testSteps: |
        = Select('Button1');
          SetProperty('ComboBox1'.SelectedItems, Table({'Name':"Record 1"}));          
testSettings:
  recordVideo: true
  browserConfigurations:
    - browser: Chromium

environmentVariables:
  users:
    - personaName: User1
      emailKey: user1Email
      passwordKey: user1Password

Describe the bug

Test Engine throws System.NullReferenceException: Object reference not set to an instance of an object. error when setting a value to Combo box control in Power Apps Canvas App. Here, SetProperty() function is used to set the value.

To Reproduce

Steps to reproduce the behavior:

  1. Insert a Combo Box control in Power Apps Canvas App.
  2. Use a Dataverse table or a collection as a datasource for the above created Combo Box control. The column name of the table should be anything other than Value.
  3. Write a test case that sets the value of Combo Box as below:
    SetProperty('ComboBox1'.SelectedItems, Table({'Name':"Sample App"}));

Expected Behavior:

Test Engine should set the value of Combo Box as defined in the SetProperty() function.

Actual Behavior:

The test has failed with the below errors:

PS /<REDACTED>/PowerApps-TestEngine/src/PowerAppsTestEngine> dotnet run
Test results will be stored in: TestOutput/2fed15

---------------------------------------------------------------------------
RUNNING TEST SUITE: SampleTestSuite
---------------------------------------------------------------------------

Browser configuration: {"Browser":"Chromium","Device":null,"ScreenWidth":null,"ScreenHeight":null,"ConfigName":null}

Browser setup finished

Browser context created

Test infrastructure setup finished

Successfully navigate page to target URL.

---------------------------------------------------------------------------
RUNNING TEST CASE: NavigateToSecondScreen
---------------------------------------------------------------------------

[Warning]: Syntax check failed. Now attempting to execute lines step by step

------------------------------

Executing SetProperty function.

[Error]: System.AggregateException: One or more errors occurred. (Exception has been thrown by the target of an invocation.)
 ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
 ---> System.AggregateException: One or more errors occurred. (Object reference not set to an instance of an object.)
 ---> System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.PowerApps.TestEngine.PowerApps.PowerAppFunctions.SetPropertyTableAsync(ItemPath itemPath, TableValue value) in /<REDACTED>/PowerApps-TestEngine/src/Microsoft.PowerApps.TestEngine/PowerApps/PowerAppFunctions.cs:line 239
   at Microsoft.PowerApps.TestEngine.PowerApps.PowerAppFunctions.SetPropertyAsync(ItemPath itemPath, FormulaValue value) in /<REDACTED>/PowerApps-TestEngine/src/Microsoft.PowerApps.TestEngine/PowerApps/PowerAppFunctions.cs:line 186
   at Microsoft.PowerApps.TestEngine.PowerFx.Functions.SetPropertyFunction.SetProperty(RecordValue obj, StringValue propName, FormulaValue value) in /<REDACTED>/PowerApps-TestEngine/src/Microsoft.PowerApps.TestEngine/PowerFx/Functions/SetPropertyFunction.cs:line 44
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
   at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at System.Threading.Tasks.Task.Wait()
   at Microsoft.PowerApps.TestEngine.PowerFx.Functions.SetPropertyFunction.Execute(RecordValue obj, StringValue propName, FormulaValue value) in /<REDACTED>/PowerApps-TestEngine/src/Microsoft.PowerApps.TestEngine/PowerFx/Functions/SetPropertyFunction.cs:line 32
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Span`1& arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at Microsoft.PowerFx.ReflectionFunction.Invoke(FormulaValue[] args)
   at Microsoft.PowerFx.ReflectionFunction.<GetTexlFunction>b__7_0(FormulaValue[] args)
   at Microsoft.PowerFx.CustomSetPropertyFunction.InvokeAsync(FormulaValue[] args, CancellationToken cancellation)
   at Microsoft.PowerFx.EvalVisitor.TryHandleSetProperty(CallNode node, EvalVisitorContext context)
   at Microsoft.PowerFx.EvalVisitor.Visit(CallNode node, EvalVisitorContext context)
   at Microsoft.PowerFx.ParsedExpression.EvalAsync(RecordValue parameters, CancellationToken cancel)
   at Microsoft.PowerFx.RecalcEngine.EvalAsync(String expressionText, CancellationToken cancel, RecordValue parameters, ParserOptions options)
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
   at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
   at System.Threading.Tasks.Task`1.get_Result()
   at Microsoft.PowerFx.RecalcEngine.Eval(String expressionText, RecordValue parameters, ParserOptions options)
   at Microsoft.PowerApps.TestEngine.PowerFx.PowerFxEngine.Execute(String testSteps) in /<REDACTED>/PowerApps-TestEngine/src/Microsoft.PowerApps.TestEngine/PowerFx/PowerFxEngine.cs:line 123
   at Microsoft.PowerApps.TestEngine.PowerFx.PowerFxEngine.ExecuteWithRetryAsync(String testSteps) in /<REDACTED>/PowerApps-TestEngine/src/Microsoft.PowerApps.TestEngine/PowerFx/PowerFxEngine.cs:line 70
   at Microsoft.PowerApps.TestEngine.SingleTestRunner.RunTestAsync(String testRunId, String testRunDirectory, TestSuiteDefinition testSuiteDefinition, BrowserConfiguration browserConfig, String queryParams) in /<REDACTED>/PowerApps-TestEngine/src/Microsoft.PowerApps.TestEngine/SingleTestRunner.cs:line 142

---------------------------------------------------------------------------
SampleTestSuite TEST SUMMARY
---------------------------------------------------------------------------

Total cases: 1

Cases passed: 0

Cases skipped: 0

Cases failed: 1

Test results can be found here: TestOutput/2fed15/Results_2fed15dd-f34b-4247-9fe5-7f71a62c55d6.trx

Additional context

I believe that the source code is expecting the column name of table to be Value. The tests ran successfully when we made the below changes:

  1. Updated the column name in the table to Value
  2. Updated the SetProperty as follows SetProperty('ComboBox1'.SelectedItems, Table({'Value':"Record 1"}));

Additionally, if the column name is set to Value in SetProperty() function, without changing it in the Datasource (Dataverse), below error is thrown:


[Error]: System.AggregateException: One or more errors occurred. (Exception has been thrown by the target of an invocation.)
 ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
 ---> System.AggregateException: One or more errors occurred. (Error: Contract failure: Unspecified.
    at Z (https://content.powerapps.com/resource/app/5ov1l0job96ha/publish/js/pa.core.bundle3.js:62:78486)
    at Object.u [as checkValue] (https://content.powerapps.com/resource/app/5ov1l0job96ha/publish/js/pa.core.bundle3.js:62:76240)
    at ControlWidget.interactWithControlAsync (https://content.powerapps.com/resource/app/2lc91ftsgjsce/publish/js/pa.common.bundle1.js:4:146461)
    at interactWithControl (/<REDACTED>/PowerApps-TestEngine/src/Microsoft.PowerApps.TestEngine/JS/PublishedAppTesting.js:186:146)
    at eval (eval at onMessage (https://pa-static-ms.azureedge.net/resource/webplayerdynamic/publishedapp/preloadindex?preloadIndexPath=https%3A%2F%2Fcontent.powerapps.com%2Fresource%2Fapp%2Fmu7r2b8lrlh44%2Fpreloadindex.web.html&PowerAppsLanguage=en-US&loader=inline&lv=d5r9l51q3u44d&serviceWorkerUrl=https%3A%2F%2Fpa-static-ms.azureedge.net%2Fresource%2Fwebplayer%2Fhashedresources%2Fp681v2nkcinh5%2Fjs%2FPowerAppsServiceWorker.PublishedApp.js&unregisterServiceWorkersHash=61al1u62ufj72&piv=48DEC944&featureGates={%22publishedAppServiceWorker%22:false}:1:10728), <anonymous>:3:26)
    at onMessage (https://pa-static-ms.azureedge.net/resource/webplayerdynamic/publishedapp/preloadindex?preloadIndexPath=https%3A%2F%2Fcontent.powerapps.com%2Fresource%2Fapp%2Fmu7r2b8lrlh44%2Fpreloadindex.web.html&PowerAppsLanguage=en-US&loader=inline&lv=d5r9l51q3u44d&serviceWorkerUrl=https%3A%2F%2Fpa-static-ms.azureedge.net%2Fresource%2Fwebplayer%2Fhashedresources%2Fp681v2nkcinh5%2Fjs%2FPowerAppsServiceWorker.PublishedApp.js&unregisterServiceWorkersHash=61al1u62ufj72&piv=48DEC944&featureGates={%22publishedAppServiceWorker%22:false}:255:10759))
 ---> Microsoft.Playwright.PlaywrightException: Error: Contract failure: Unspecified.
    at Z (https://content.powerapps.com/resource/app/5ov1l0job96ha/publish/js/pa.core.bundle3.js:62:78486)
    at Object.u [as checkValue] (https://content.powerapps.com/resource/app/5ov1l0job96ha/publish/js/pa.core.bundle3.js:62:76240)
    at ControlWidget.interactWithControlAsync (https://content.powerapps.com/resource/app/2lc91ftsgjsce/publish/js/pa.common.bundle1.js:4:146461)
    at interactWithControl (/<REDACTED>/PowerApps-TestEngine/src/Microsoft.PowerApps.TestEngine/JS/PublishedAppTesting.js:186:146)
    at eval (eval at onMessage (https://pa-static-ms.azureedge.net/resource/webplayerdynamic/publishedapp/preloadindex?preloadIndexPath=https%3A%2F%2Fcontent.powerapps.com%2Fresource%2Fapp%2Fmu7r2b8lrlh44%2Fpreloadindex.web.html&PowerAppsLanguage=en-US&loader=inline&lv=d5r9l51q3u44d&serviceWorkerUrl=https%3A%2F%2Fpa-static-ms.azureedge.net%2Fresource%2Fwebplayer%2Fhashedresources%2Fp681v2nkcinh5%2Fjs%2FPowerAppsServiceWorker.PublishedApp.js&unregisterServiceWorkersHash=61al1u62ufj72&piv=48DEC944&featureGates={%22publishedAppServiceWorker%22:false}:1:10728), <anonymous>:3:26)
    at onMessage (https://pa-static-ms.azureedge.net/resource/webplayerdynamic/publishedapp/preloadindex?preloadIndexPath=https%3A%2F%2Fcontent.powerapps.com%2Fresource%2Fapp%2Fmu7r2b8lrlh44%2Fpreloadindex.web.html&PowerAppsLanguage=en-US&loader=inline&lv=d5r9l51q3u44d&serviceWorkerUrl=https%3A%2F%2Fpa-static-ms.azureedge.net%2Fresource%2Fwebplayer%2Fhashedresources%2Fp681v2nkcinh5%2Fjs%2FPowerAppsServiceWorker.PublishedApp.js&unregisterServiceWorkersHash=61al1u62ufj72&piv=48DEC944&featureGates={%22publishedAppServiceWorker%22:false}:255:10759)
   at Microsoft.Playwright.Transport.Connection.InnerSendMessageToServerAsync[T](String guid, String method, Object args) in /_/src/Playwright/Transport/Connection.cs:line 164
   at Microsoft.Playwright.Transport.Connection.WrapApiCallAsync[T](Func`1 action, Boolean isInternal) in /_/src/Playwright/Transport/Connection.cs:line 479
   at Microsoft.Playwright.Core.Frame.EvaluateAsync[T](String script, Object arg) in /_/src/Playwright/Core/Frame.cs:line 496
   at Microsoft.PowerApps.TestEngine.TestInfra.PlaywrightTestInfraFunctions.RunJavascriptAsync[T](String jsExpression) in /<REDACTED>/PowerApps-TestEngine/src/Microsoft.PowerApps.TestEngine/TestInfra/PlaywrightTestInfraFunctions.cs:line 278
   at Microsoft.PowerApps.TestEngine.PowerApps.PowerAppFunctions.SetPropertyTableAsync(ItemPath itemPath, TableValue value) in /<REDACTED>/PowerApps-TestEngine/src/Microsoft.PowerApps.TestEngine/PowerApps/PowerAppFunctions.cs:line 249
   at Microsoft.PowerApps.TestEngine.PowerApps.PowerAppFunctions.SetPropertyAsync(ItemPath itemPath, FormulaValue value) in /<REDACTED>/PowerApps-TestEngine/src/Microsoft.PowerApps.TestEngine/PowerApps/PowerAppFunctions.cs:line 186
   at Microsoft.PowerApps.TestEngine.PowerFx.Functions.SetPropertyFunction.SetProperty(RecordValue obj, StringValue propName, FormulaValue value) in /<REDACTED>/PowerApps-TestEngine/src/Microsoft.PowerApps.TestEngine/PowerFx/Functions/SetPropertyFunction.cs:line 44
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
   at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at System.Threading.Tasks.Task.Wait()
   at Microsoft.PowerApps.TestEngine.PowerFx.Functions.SetPropertyFunction.Execute(RecordValue obj, StringValue propName, FormulaValue value) in /<REDACTED>/PowerApps-TestEngine/src/Microsoft.PowerApps.TestEngine/PowerFx/Functions/SetPropertyFunction.cs:line 32
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Span`1& arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at Microsoft.PowerFx.ReflectionFunction.Invoke(FormulaValue[] args)
   at Microsoft.PowerFx.ReflectionFunction.<GetTexlFunction>b__7_0(FormulaValue[] args)
   at Microsoft.PowerFx.CustomSetPropertyFunction.InvokeAsync(FormulaValue[] args, CancellationToken cancellation)
   at Microsoft.PowerFx.EvalVisitor.TryHandleSetProperty(CallNode node, EvalVisitorContext context)
   at Microsoft.PowerFx.EvalVisitor.Visit(CallNode node, EvalVisitorContext context)
   at Microsoft.PowerFx.ParsedExpression.EvalAsync(RecordValue parameters, CancellationToken cancel)
   at Microsoft.PowerFx.RecalcEngine.EvalAsync(String expressionText, CancellationToken cancel, RecordValue parameters, ParserOptions options)
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
   at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
   at System.Threading.Tasks.Task`1.get_Result()
   at Microsoft.PowerFx.RecalcEngine.Eval(String expressionText, RecordValue parameters, ParserOptions options)
   at Microsoft.PowerApps.TestEngine.PowerFx.PowerFxEngine.Execute(String testSteps) in /<REDACTED>/PowerApps-TestEngine/src/Microsoft.PowerApps.TestEngine/PowerFx/PowerFxEngine.cs:line 130
   at Microsoft.PowerApps.TestEngine.PowerFx.PowerFxEngine.ExecuteWithRetryAsync(String testSteps) in /<REDACTED>/PowerApps-TestEngine/src/Microsoft.PowerApps.TestEngine/PowerFx/PowerFxEngine.cs:line 70
   at Microsoft.PowerApps.TestEngine.SingleTestRunner.RunTestAsync(String testRunId, String testRunDirectory, TestSuiteDefinition testSuiteDefinition, BrowserConfiguration browserConfig, String queryParams) in /<REDACTED>/PowerApps-TestEngine/src/Microsoft.PowerApps.TestEngine/SingleTestRunner.cs:line 142

Note: These test cases work fine without any issues in Test Studio.

Due to this issue, I couldn't proceed further on testing.

clairewu0218 commented 1 year ago

Hi,

Could you send us the app file again? Not sure why I cannot download the attached app.

Thanks, Claire

m-saikiran commented 1 year ago

Hi @clairewu0218,

Here is the app file: SampleAppforTestEngine_20221026141239.zip

Let me know if you still can't download it.

clairewu0218 commented 1 year ago

Hi @m-saikiran,

I modified the syntax to be SetProperty('ComboBox1'.SelectedItems, Table({Value:"Record 1"})); and it worked on my end. Feel free to let me know if it doesn't work for you.

Now test engine throws error if a Table input is not in the format of Table({Value:"some value"}), which is a bug. I'm working on fixing it and thanks for your help in identifying this.

clairewu0218 commented 1 year ago

Hi @m-saikiran,

The bug was fixed. Feel free to let us know if you have further questions. Thanks!