microsoft / EasyRepro

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

dynamics 365 adfs login not working of build 8.1 tried with adfs login getting object reference error on commenting xrmBrowser.GuidedHelp.CloseGuidedHelp(); please help #642

Open deep-hub opened 4 years ago

deep-hub commented 4 years ago

Please help. Will really appreciate on quick response. Thanks in advance.

Please let me know what changes to made. Easy repro version 8.1, I check earlier post, it was written ADFS login works fine.

------------Contact page information of web browser dynamic 365

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

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

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

    [TestMethod]
    public void TestCreateNewContact()
    {
        using (var xrmBrowser = new XrmBrowser(TestSettings.Options))
        {
            xrmBrowser.LoginPage.Login(_xrmUri, _username, _password);
           // xrmBrowser.GuidedHelp.CloseGuidedHelp();

            xrmBrowser.ThinkTime(500);
            xrmBrowser.Navigation.OpenSubArea("Sales", "Contacts");

            xrmBrowser.ThinkTime(2000);
            xrmBrowser.Grid.SwitchView("Active Contacts");

            xrmBrowser.ThinkTime(1000);
            xrmBrowser.CommandBar.ClickCommand("New");

            xrmBrowser.ThinkTime(5000);

            var fields = new List<Field>
            {
                new Field() {Id = "firstname", Value = "Test"},
                new Field() {Id = "lastname", Value = "Contact"}
            };
            xrmBrowser.Entity.SetValue(new CompositeControl() {Id = "fullname", Fields = fields});
            xrmBrowser.Entity.SetValue("emailaddress1", "test@contoso.com");
            xrmBrowser.Entity.SetValue("mobilephone", "555-555-5555");
            xrmBrowser.Entity.SetValue("birthdate", DateTime.Parse("11/1/1980"));
            xrmBrowser.Entity.SetValue(new OptionSet {Name = "preferredcontactmethodcode", Value = "Email"});

            xrmBrowser.CommandBar.ClickCommand("Save");
            xrmBrowser.ThinkTime(5000);

        }
    }
}

}

-------------------ADFS login page information-----------------

using Microsoft.VisualStudio.TestTools.UnitTesting; using Microsoft.Dynamics365.UIAutomation.Api; using Microsoft.Dynamics365.UIAutomation.Browser; using OpenQA.Selenium; using System; using System.Collections.Generic; using System.Security;

namespace Microsoft.Dynamics365.UIAutomation.Sample { [TestClass] public class ADFSLogin { private readonly SecureString _username = System.Configuration.ConfigurationManager.AppSettings["OnlineUsername"].ToSecureString(); private readonly SecureString _password = System.Configuration.ConfigurationManager.AppSettings["OnlinePassword"].ToSecureString(); private readonly Uri _xrmUri = new Uri(System.Configuration.ConfigurationManager.AppSettings["OnlineCrmUrl"].ToString());

    [TestMethod]
      public void TestCustomLogin()
    {
        using (var xrmBrowser = new XrmBrowser(TestSettings.Options))
        {
            xrmBrowser.LoginPage.Login(_xrmUri, _username, _password, CustomLoginAction);
        }
    }

    public void CustomLoginAction(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("userNameInput")).SendKeys(args.Password.ToUnsecureString());
        d.FindElement(By.Id("passwordInput")).SendKeys(args.Password.ToUnsecureString());
        d.ClickWhenAvailable(By.Id("submitButton"), new TimeSpan(0, 0, 2));

        //Insert any additional code as required for the SSO scenario

        //Wait for CRM Page to load
        d.WaitUntilVisible(By.XPath(Elements.Xpath[Reference.Login.CrmMainPage])
            , new TimeSpan(0, 0, 60),
        e =>
        {
            e.WaitForPageToLoad();
            e.SwitchTo().Frame(0);
            e.WaitForPageToLoad();
        },
            f => { throw new Exception("Login page failed."); });
        //--------------------------------------------------------------------------------------
    }

/*

    [TestMethod]
    public void TestADFSLogin()
    {
        using (var xrmBrowser = new XrmBrowser(TestSettings.Options))
        {
            xrmBrowser.LoginPage.Login(_xrmUri, _username, _password, ADFSLoginAction);
        }
    }

    public 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());
        //   d.ClickWhenAvailable(By.Id("submitButton"), new TimeSpan(0, 0, 2));
        //   d.WaitForPageToLoad();
        //--------------------------------------------------------------------------------------
    } */
}

}

deep-hub commented 4 years ago

@TYLEROL

kramburley commented 4 years ago

Hi I am a bit new to this as well but will try my best to help.

Can you share how you are getting your errors in detail? What steps to make to recreate this error etc...

spr0ut commented 4 years ago

Came across this error recently and ended up changing the Loginresult in LoginDialog.cs to wrap the password sendkeys/submit (L128-L130) within the following:

driver.WaitUntilVisible(By.CssSelector("div[id$='loginMessage']"));
                    if (driver.IsVisible(By.CssSelector("div[id$='loginMessage']")))
{
//sendkeys stuff...
}

Might not help, but there you go.

deep-hub commented 4 years ago

Thanks for everyone for the reply. Please rply as soon as possible. It will be really helpful. I am working on this project whereby I required ADFS login to be working.

Basically I am trying to run contact,case, lead test cases, which requires ADFS login to enter the website. but it is not working , though ADFS page is available. and in earlier post @TYLEROL mentioned in version 8.1 , ADFS page is there , so it should work, but it is not working for me. I dont know if i have mentioned ADFS page data into contact entity or not.

Do i have do extra coding for it in contact, lead, case entity test case page. Please let me know. Thanks in advance.

contact code create contact adfs login

deep-hub commented 4 years ago

@TYLEROL @jason-lachance @spr0ut

Could you please provide resolution to above query, stuck in this, tried all the methods.

Thanks in advance!!!!!

TYLEROL commented 4 years ago

@deep-hub , what error message are you receiving as a part of the failed test for the ADFS login?

Assuming a standard ADFS forms based login experience, what you have so far looks okay. Do you know which version of ADFS you are using?

Note: You must be using a forms based login experience -- this will not work for a Windows Authentication prompt.

Thanks, Tyler