microsoft / EasyRepro

Automated UI testing API for Dynamics 365
MIT License
521 stars 288 forks source link

[HOW-TO] Facing the error - "Cannot read properties of undefined" when running in the headless mode #1293

Open bugboogie666 opened 2 years ago

bugboogie666 commented 2 years ago

Question

What is your question? My script is setting entity fields on the product form. When this field (e.g. contract length) is set, there is a JSscript calling async operation(code from backend) to perform some calculations on the fly within the form. Setting this field works perfectly when I use selenium and easyrepro in non-headless mode. But with using headless options I am getting this error

dialog with the message "Cannot read properties of undefined(reading 'ResultJson')" is shown for me.

screen_2022-05-04-15-11-18

Versions: `<?xml version="1.0" encoding="utf-8"?>

` 2022 release wave 1 enabled App name: Kentico CRM App Organization name: Kentico Sandbox 20212909 Server version: 9.2.22041.00157 Client version: 1.4.4116-2204.1 Session ID: 8c96276f-fecc-4e22-9621-4e1fe1f3afb3 Time: 5/4/2022 3:47:31 PM GMT+0200 (Central European Summer Time) Code sample: // And that order has a new yearly subscription product with quantiy 1 and contract length 12 var product = order.AddProduct(); product.ClearExistingProductContainer("*source"); product.ExistingProduct = "Business - 1 Website Auto-Scalable Subscription with Source Code (Yearly)"; XrmApp.ThinkTime(2000); product.ContractLength = "24"; //SeleniumHelper.SetElementValue(product.ContractLengthElement, "36.00"); Logger.Info("CL field set."); XrmApp.ThinkTime(4000); order = product.Command("Save & Close"); My Implementation of getter(setter): [Description("Contract Length")] public string ContractLength { get { return XrmApp.Entity.GetValue(SalesOrderDetail.Fields.ken_contractlength); } set { XrmApp.Entity.SetValue(SalesOrderDetail.Fields.ken_contractlength, value); } } Implementation of command method internal T Command(string command) where T : new() { Logger.Info($"Clicking {command} button --> {new T().GetType()}"); try { XrmApp.CommandBar.ClickCommand(command); } catch (Exception ex) { SeleniumHelper.TakeScreenShot(); Logger.Error(ex.Message); Logger.Error(ex.StackTrace); throw; } Logger.Info($"Command {command} performed successfully."); return new T(); } Is anyone here who has faced this kind of issues? This situation is very frustrating.
tipsey commented 2 years ago

Have you tried setting the viewport in for headless mode?

using System.Drawing;

var client = new WebClient(TestSettings.Options); if (TestSettings.Options.Headless) client.Browser.Driver.Manage().Window.Size = new Size(1920, 1080);