microsoft / EasyRepro

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

beta / 9.0.2 : Adding a common Interface to WebClient and Browser #234

Open NicolasPrats opened 5 years ago

NicolasPrats commented 5 years ago

Hello,

Microsoft.Dynamics365.UIAutomation.Api.Browser and Microsoft.Dynamics365.UIAutomation.Api.UCI.WebClient have a lot of common properties/methods. Could you add interfaces that would be implemented by the both types please ? Today, if we want test a scenario in both web refresh ui and unified interface, we have to write 2 tests. With a common interface, the 2 tests could share a lot of code.

Here is a sample that we can write today:

[TestMethod]
        public void UCITestOpenActiveAccount()
        {
            var client = new WebClient(TestSettings.Options);
            using (var xrmApp = new XrmApp(client))
            {
                xrmApp.OnlineLogin.Login(_xrmUri, _username, _password);
                xrmApp.Navigation.OpenApp("UCI");
                // App initialized, the true test begins here
                xrmApp.Navigation.OpenSubArea("Sales", "Accounts");                
                xrmApp.Grid.Search("04");
                xrmApp.Grid.OpenRecord(0);
                xrmApp.Entity.SetValue("name", "Contoso");
                xrmApp.Entity.Save();
            }
        }

        [TestMethod]
        public void WEBTestOpenActiveAccount()
        {
            using (var xrmBrowser = new Api.Browser(TestSettings.Options))
            {
                xrmBrowser.LoginPage.Login(_xrmUri, _username, _password);
                xrmBrowser.GuidedHelp.CloseGuidedHelp();
                // Browser initialized, the true test begins here
                xrmBrowser.Navigation.OpenSubArea("Sales", "Accounts");
                xrmBrowser.Grid.Search("04");
                xrmBrowser.Grid.OpenRecord(0);
                xrmBrowser.Entity.SetValue("name", "contoso");
                xrmBrowser.Entity.Save();
            }
        }

It would be easier to maintain if we could write something like this:

[TestMethod]
        public void UCITestOpenActiveAccount()
        {
            var client = new WebClient(TestSettings.Options);
            using (var xrmApp = new XrmApp(client))
            {
                xrmApp.OnlineLogin.Login(_xrmUri, _username, _password);
                xrmApp.Navigation.OpenApp("UCI");
                // App initialized, the true test begins here
                OpenActiveAccount(xrmApp);
            }
        }

        [TestMethod]
        public void WEBTestOpenActiveAccount()
        {
            using (var xrmBrowser = new Api.Browser(TestSettings.Options))
            {
                xrmBrowser.LoginPage.Login(_xrmUri, _username, _password);
                xrmBrowser.GuidedHelp.CloseGuidedHelp();
                // Browser initialized, the true test begins here
                OpenActiveAccount(xrmBrowser);
            }
        }

private static void OpenActiveAccount(IClient client)
        {
            client.Navigation.OpenSubArea("Sales", "Accounts");
            client.Grid.Search("04");
            client.Grid.OpenRecord(0);
            client.Entity.SetValue("name", "Contoso");
            client.Entity.Save();
        }
TYLEROL commented 5 years ago

Thanks @NicolasPrats. It looks like this post got missed earlier. I've added this as a backlog item to review with my colleagues.

We're making efforts to try and make the codebase easier to use and reduce overall effort for our consumers to utilize it. I like the idea and thank you for suggesting it.

We're in the middle of updates for v9.1 support for legacy client and unified interface, hopefully we'll have those available in the next ~3 weeks. After that we should have a better idea on how/when we could consider implementing this idea. Either myself or a colleague will circle back and update this thread after we've had a chance to discuss it further.

Best Regards, Tyler