microsoft / EasyRepro

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

xrmApp.Entity.SetValue() method is not working #944

Open srinu24k opened 4 years ago

srinu24k commented 4 years ago

Bug Report

EasyRepro Version

UCI or Classic Web

Online or On Premise

Browser

Describe the bug
Lookup field is not accepting the value although its available in the list. Message: Test method Microsoft.Dynamics365.UIAutomation.abc.UCI.Entities.PSACases.Projects_17113_ValidateFieldsOnPlanBPFStage threw exception: System.InvalidOperationException: List does not contain a record with the name: Lifetouch Inc. image

Special formatting / display
No Code to reproduce
string Customer = ConfigurationManager.AppSettings["EndCustomer"].ToString(); try { _xrmApp.ThinkTime(WaitTime.WaitFor_3_Sec);

            Log.Info($"Setting Value {Customer} Into Customer field");

            _xrmApp.Entity.SetValue(new LookupItem { Name EntityFieldSchemaReference.ProjectTemplateElementId["Customer"], Value = Customer });

            _xrmApp.ThinkTime(WaitTime.WaitFor_2_Sec);
        }

Expected behavior
It should accept the value into the lookup. image

badarmunirr commented 4 years ago

@srinu24k you can set lookup value like this LookupItem LookupVeriable = new LookupItem { Name = LookupFieldName, Value = LookupFieldValue, Index = 0 }; global.xrmApp.Entity.SetValue(LookupVeriable);

srinu24k commented 4 years ago

@badarmunirr , the code doesn't work as it's no difference with the code i have shared

badarmunirr commented 4 years ago

@srinu24k try this LookupItem LookupVeriable = new LookupItem { Name = "Customer", Value = "Lifetouch Inc", Index = 0 }; xrmApp.Entity.SetValue(LookupVeriable); if customer is your field name . it should work because I have just ran a follow with lookup and its working for me

srinu24k commented 4 years ago

@badarmunirr It wont works. the issue is not how you are using the SetValue() method.

Have debugged the method and came to know that this below piece of code in SetLookUpByValue(IWebDriver driver, LookupItem control, int index) method is not working where it should return an integer >0 but it's returning 0 only. Hence it is failing.

        var dialogItems = OpenDialog(flyoutDialog).Value;

        driver.WaitForTransaction();
        if (dialogItems.Count == 0)
            throw new InvalidOperationException($"List does not contain a record with the name:  {control.Value}");

        if (index + 1 > dialogItems.Count)
        {
            throw new InvalidOperationException($"List does not contain {index + 1} records. Please provide an index value less than {dialogItems.Count} ");
        }

        var dialogItem = dialogItems[index];
        driver.ClickWhenAvailable(By.Id(dialogItem.Id));

Now Can you please provide a fix for this?

srinu24k commented 4 years ago

Below is the further investigation of the code, where title links are expected to return an integer > 0 but returns only 0.

image

srinu24k commented 4 years ago

@badarmunirr any update for the fix?

nareshbak commented 4 years ago

Any update on this. I am also facing the same issue

srinu24k commented 4 years ago

@nareshbak , try this piece of code once. It works for me. Let me know if you face any issue further.

public BrowserCommandResult<List> OpenDialog(IWebElement dialog) { var list = new List(); var dialogItems = dialog.FindElements(By.XPath(".//li"));

        foreach (var dialogItem in dialogItems)
        {
            //var titleLinks = dialogItem.FindElements(By.XPath(".//label/span"));
            var divLinks = dialogItem.FindElements(By.XPath(".//div"));

            if (divLinks != null && divLinks.Count > 0)
            {
                //var title = titleLinks[0].GetAttribute("innerText");
                var divId = divLinks[0].GetAttribute("id");

                list.Add(new ListItem()
                {
                    //Title = title,
                    Id = divId,
                });
            }
        }

        return list;
    }
nareshbak commented 4 years ago

This is working for me @srinu24k . Thanks for this fix