Good day everyone,
I've got a question regarding the use of the test framework for forms. I have some custom code that sets some fields to not editable in the EcoResProductDetailsExtended form if some criteria are met. The code itself works fine. However, I also wanted to write some unit tests for this, to easily test my code in future upgrades etc.
So what I did:
- Recorded a task in F&O via the task recorder
- Downloaded the recorded task and imported it as unit test in Visual Studio via Extensions -> Dynamics 365 -> Addins -> Imported task recording
- Modified the generated code to write 2 test methods. One test to verify that the fields are editable in scenario 1, and another test to verify that the fields are readonly in scenario 2.
To my suprise however, the fields are readonly in both cases. Just to be sure, I disabled all my custom code for these fields, but still the fields are readonly.
This is my test case (slightly simplified to show only relevant parts):
class MyFormTest extends SysTestCase { protected EcoResProductDetailsExtendedFormAdaptor EcoResProductDetailsExtendedForm; public void testFieldEditable() { changecompany('XXXX') { using (var c = ClientContext::create()) { //Go to Product information management > Products > Released products. using (var c1 = c.navigate(menuItemDisplayStr(ecoresproductdetailsextendedgrid),formStr(EcoResProductDetailsExtended),Microsoft.Dynamics.TestTools.Dispatcher.MenuItemType::Display)) { EcoResProductDetailsExtendedForm = c1.form(); //In the list, click the link in the selected row. EcoResProductDetailsExtendedForm.HeaderGrid().selectRecord(); EcoResProductDetailsExtendedForm.systemDefinedViewEditButton().click(); this.assertTrue(EcoResProductDetailsExtendedForm.EcoResProduct_SearchName().editable()); } } } } }
In my test setup (not included in the snippet) I made sure company XXXX is created, and has 1 released product. I checked that the grid contains 1 product by adding the following debug line to the test.
Info(int2Str(EcoResProductDetailsExtendedForm.HeaderGrid().count()));
Anyone got an idea why this test fails? Am I missing some setup to be able to edit a product via the form in my unit test? I have been writing more unit tests in Dynamics, but this is my first test involving forms like this.
When I open the UI the field can be edited normally:
Only during my unit test the editable() seems to return false.
As far I know the released products form is non editable from UI. It is same at list page level and at item level also. Only may be custom fields would be editable. Are you asking this only?
André Arnaud de Cal...
291,979
Super User 2025 Season 1
Martin Dráb
230,848
Most Valuable Professional
nmaenpaa
101,156