microsoft / EasyRepro

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

Unable to load Dynamics 365 Apps page in UCI once login is successful #863

Closed veerasekharbathala closed 4 years ago

veerasekharbathala commented 4 years ago

Bug Report

Issues should only be created for items related to covered functionality.

Not covered functionality, feature requests, and questions should use the Feature Request or Question templates.

EasyRepro Version

UCI or Classic Web

Online or On Premise

Browser

Describe the bug
I tried with releases/v9.1 and develop branches code. I am executing the easyrepro sample test cases and tried with CreateAccountUCI. UCITestCreateAccount sample test case.

Below ADFS Login redirect code is used to login to Dynamics 365 online UCI app. The code is executing as expected, user name, password entered and authentication is successful. However, the page is redirected to office 365 home page instead of Dynamics 365 apps.

Do we have different ADFS Login redirect code for UCI? Can you share ADFS Login redirect code for UCI?

Special formatting / display

Code to reproduce

using Microsoft.Dynamics365.UIAutomation.Api.UCI;
using Microsoft.Dynamics365.UIAutomation.Browser;
using OpenQA.Selenium;
using System;

namespace Microsoft.Dynamics365.UIAutomation.Sample
{
    class ADFSLogin
    {
        public static void ADFSLoginAction(LoginRedirectEventArgs args)
        {
            //Login Page details go here.  You will need to find out the id of the password field on the form as well as the submit button. 
            //You will also need to add a reference to the Selenium Webdriver to use the base driver. 

            //Example
            //--------------------------------------------------------------------------------------
            var d = args.Driver;
            d.FindElement(By.Id("passwordInput")).SendKeys(args.Password.ToUnsecureString());

            try
            {
                d.ClickWhenAvailable(By.Id("submitButton"), new TimeSpan(0, 0, 2));

            }
            catch (Exception)
            {

            }
            d.WaitForPageToLoad();

            if (d.IsVisible(By.XPath(Elements.Xpath[Reference.Login.StaySignedIn])))
            {
                d.ClickWhenAvailable(By.XPath(Elements.Xpath[Reference.Login.StaySignedIn]));
            }
        }
    }
}

Used below code in CreateAccountUCI. UCITestCreateAccount to call Login method

 xrmApp.OnlineLogin.Login(_xrmUri, _username, _password, _mfaSecretKey, ADFSLogin.ADFSLoginAction);

Please find CreateAccountUCI class code below.

using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.Dynamics365.UIAutomation.Api.UCI;
using Microsoft.Dynamics365.UIAutomation.Browser;
using System;
using System.Security;

namespace Microsoft.Dynamics365.UIAutomation.Sample.UCI
{
    [TestClass]
    public class CreateAccountUCI
    {

        private readonly SecureString _username = System.Configuration.ConfigurationManager.AppSettings["OnlineUsername"].ToSecureString();
        private readonly SecureString _password = System.Configuration.ConfigurationManager.AppSettings["OnlinePassword"].ToSecureString();
        private readonly SecureString _mfaSecretKey = System.Configuration.ConfigurationManager.AppSettings["MfaSecretKey"].ToSecureString();
        private readonly Uri _xrmUri = new Uri(System.Configuration.ConfigurationManager.AppSettings["OnlineCrmUrl"].ToString());

        [TestMethod]
        public void UCITestCreateAccount()
        {
            var client = new WebClient(TestSettings.Options);
            using (var xrmApp = new XrmApp(client))
            {
                xrmApp.OnlineLogin.Login(_xrmUri, _username, _password, _mfaSecretKey, ADFSLogin.ADFSLoginAction);

                xrmApp.Navigation.OpenApp(UCIAppName.Sales);

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

                xrmApp.CommandBar.ClickCommand("New");

                xrmApp.Entity.SetValue("name", TestSettings.GetRandomString(5,15));

                xrmApp.Entity.Save();

            }

        }
    }
}

Expected behavior
Expecting to see below Dynamics 365 apps page once the authentication is successful. image

Screenshots

Once the authentication is successful, below page is visible to user.

image

veerasekharbathala commented 4 years ago

Please find online crm Url config from app.config file.

  <add key="OnlineCrmUrl" value="https://****.crm3.dynamics.com/" />
AngelRodriguez8008 commented 4 years ago

Your are trying to open the Sales App. Do you has it installed?

Maybe you should choose the right App, at this line: xrmApp.Navigation.OpenApp(UCIAppName.Sales);

veerasekharbathala commented 4 years ago

I tried to open the apps which are already installed. The page is still redirected to office 365 home page once the login is successful and xrmApp is not able to load appropriate app.

Please find screenshots below.

image

image

AngelRodriguez8008 commented 4 years ago

Sorry, i misunderstood your question.

What if you navigate to D365 in your Redirect Action or after Login, driver.Navigate().GoToUrl(_xrmUri);