microsoft / EasyRepro

Automated UI testing API for Dynamics 365
MIT License
513 stars 286 forks source link

Function not working xrmApp.Entity.Save() #1232

Open fmamoon opened 2 years ago

fmamoon commented 2 years ago

Bug Report

If I install EasyRepro via nuget package on my Test Project xrmApp.Entity.Save() command is returning this below error: System.InvalidOperationException: 'Save Button is not available' Please note, same command used to work on previous version and still works direct from "Microsoft.Dynamics365.UIAutomation.Sample"

EasyRepro Version

UCI or Classic Web

Online or On Premise

Browser

Describe the bug
If I install EasyRepro's latest version via nuget package for my Test Project the command "xrmApp.Entity.Save()" is returning this error: System.InvalidOperationException: 'Save Button is not available' Please note, same command used to work on previous version via nuget installation and still works directly from "Microsoft.Dynamics365.UIAutomation.Sample" project

Special formatting / display
Not applicable

Code to reproduce
[TestMethod] public void CreateContact() { var client = new WebClient(TestSettings.Options); using (var xrmApp = new XrmApp(client)) { xrmApp.OnlineLogin.Login(_xrmUri, _username, _password, _mfaSecretKey);

    xrmApp.Navigation.OpenApp(UCIAppName.Sales);

    xrmApp.Navigation.OpenSubArea("Sales", "Contacts");

    xrmApp.CommandBar.ClickCommand("New");

    xrmApp.Entity.SetValue("firstname", TestSettings.GetRandomString(5, 10));
    xrmApp.Entity.SetValue("lastname", TestSettings.GetRandomString(5, 10));

    xrmApp.Entity.Save();   // This is where the error occurs
    xrmApp.ThinkTime(500);
}

}

Expected behavior
Contact is Saved

Screenshots
Error on Save

Additional context
I am using Chrome. Tried both .Net Version 4.6 & 4.7.2

ejueldotnet commented 2 years ago

Bug also occurs on Microsoft Edge Version 96.0.1054.29 (Official build) (64-bit).

ejueldotnet commented 2 years ago

Issue was with Microsoft.Dynamics365.UIAutomation.Api.UCI\DTO\AppElementReference.cs

Pulling latest version of repo resolve the issue for me.

Older versions of repo had { "Entity_Save" , "//button[contains(@data-id, 'form-save-btn')]"},

However latest repo version uses { "Entity_Save" , "//button[contains(@id, 'SavePrimary')]"},

VikariiCGI commented 2 years ago

@zekeinclusa, I see this code

        internal BrowserCommandResult<bool> Save(int thinkTime = Constants.DefaultThinkTime)
        {
            ThinkTime(thinkTime);

            return this.Execute(GetOptions($"Save"), driver =>
            {
                Actions action = new Actions(driver);
                action.KeyDown(Keys.Control).SendKeys("S").Perform();

                return true;
            });
        }
VikariiCGI commented 2 years ago

Anyway save button works well!

ritesh035 commented 2 years ago

I am facing a similar issue @VikariiCGI please help me understand what needs to be added in code to resolve the issue. I have already added the required NuGet package.

ejueldotnet commented 2 years ago

@ritesh035 Pulling the latest version of the NuGet package should resolve.

What happened last time was the HTML code and tags built in to D365 changed, so when EasyRepro/Selenium tried to save it was looking for HTML tags that no longer exist (thereby requiring an update to the repo).

The newest version of EasyRepro is sending the keyboard keys Ctrl+S, which is a shortcut in D365 to save the document (so instead of relying on HTML tags staying constant, it is now relying on a keyboard shortcut staying constant).

reachsuja commented 2 years ago

@zekeinclusa I have got the latest version of NuGet package Dynamics365.UIAutomation.Api version 9.2.21084.148 and Powerapps.UIAutomation.Api 9.0.2. But still have the same issue. Can you please advice which version of the package it is fixed?

at-sterling commented 2 years ago

@zekeinclusa I also have the latest Dynamics365.UIAutomation.Api version 9.2.21084.148 NuGet package, but the issue still persists. It would be great if you could let me know your version and any other steps you took to resolve this issue! For the time being I wrote a manual save function that sends the keys Crtl+S, but aligning to the standard would be much more sustainable for long-term development.

ejueldotnet commented 2 years ago

@reachsuja Sorry, I'm currently maintaining my own branch to support the newest MS Edge browser (EasyRepro currently only supports the older non-Chromium based browser, weird since the newer one came out in early 2020). Guessing it's a webdriver issue since the save code in question is the same as mine and works on Edge webdriver 98.0.1108.43.

Like @at-sterling said, you could create your own manual save function that sends the Ctrl+S key (not sure why they changed it away from Ctrl+S), but then you're maintaining and trying to keep it up to date with the current EasyRepro (pulling in new changes every couple months is a pain when you don't want your manual changes overwritten).

If you do it yourself, you'll want to update the save function in WebClient.cs from

internal BrowserCommandResult<bool> Save(int thinkTime = Constants.DefaultThinkTime)
        {
            ThinkTime(thinkTime);

            return this.Execute(GetOptions($"Save"), driver =>
            {
                var save = driver.WaitUntilAvailable(By.XPath(AppElements.Xpath[AppReference.Entity.Save]),
                    "Save Buttton is not available");

                save?.Click();

                return true;
            });
        }

and change it to this (thanks @VikariiCGI):

internal BrowserCommandResult<bool> Save(int thinkTime = Constants.DefaultThinkTime)
        {
            ThinkTime(thinkTime);

            return this.Execute(GetOptions($"Save"), driver =>
            {
                Actions action = new Actions(driver);
                action.KeyDown(Keys.Control).SendKeys("S").Perform();

                return true;
            });
        }

Looking at the error "Save Buttton is not available" you're getting in the main EasyRepro WebClient.cs

AppReference.Entity.Save references the following code in AppElementReference.cs { "Entity_Save" , "//button[contains(@id, 'SavePrimary')]"},

If you're a front end programmer (or know a little HTML) you could debug and hit F12 on Chrome at the save screen and see why the save button isn't working.

dharani81 commented 1 year ago

I am having the latest nuget package but still got the error when I tried save using xrmApp.Entity.Save(); so I update the code in webclient.cs and updated the references. It fixed the save error but throwing another error "Saving in progress" .Please help me to fix this. Please find below is the issue screen shot. Thank you error