Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot login to our MS Dynamics CRM 365 OnPremise login page. #289

Closed
rtulaila opened this issue Jan 9, 2019 · 7 comments
Closed

Cannot login to our MS Dynamics CRM 365 OnPremise login page. #289

rtulaila opened this issue Jan 9, 2019 · 7 comments

Comments

@rtulaila
Copy link

rtulaila commented Jan 9, 2019

  1. Updated app.Config file with Username, pwd and URL
  2. Updated TestADFSLogin .cs file with login details.
    Cannot login to our MS Dynamics CRM 365 OnPremise web page
    Need Help.
@TYLEROL
Copy link
Member

TYLEROL commented Jan 10, 2019

Hello @rtulaila ,

Could you share details on which code branch you're using (v8.1, v8.2, v9.0...), the version of your Dynamics 365 organization, and the error you're receiving when trying to run the tests?

Thanks,
Tyler

@rtulaila
Copy link
Author

Hi Tyler,
-I am using code branch : releases/OnPremise Updated Feb 2, 2018 by Michał Krawczyk

-Our MS Dynamics 365 Version : 1612 (8.2.2.112)(DB 8.2.2112) on-premises

-I am not getting any error message and TestADFSLogin .cs is passed.
The chrome window opens with URL and shows the page and closes without logging in :(

Here is the code I am running TestADFSLogin .cs

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

// Wait CRM page to load
// d.WaitForPageToLoad();

d.WaitUntilVisible(By.XPath(Elements.Xpath[xrmUri.ToString()]), new TimeSpan(0, 0, 60),
e => { e.WaitForPageToLoad(); },
f => { throw new Exception("Login page failed."); });
//---------------------------------------------------------------------------
}

Thank you
rtuliala

@TYLEROL
Copy link
Member

TYLEROL commented Jan 11, 2019

Thanks @rtulaila . This is an example of the 'ADFSLoginAction' from our latest code branches. Could you give this a try?

 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));

            //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."); });

        }

You pay need to add a call prior to the 'password' send keys in the event the username is not already populated in your ADFS login page.

Please let me know if you have success using this, or if you encounter any issues.

Thanks,
Tyler

@rtulaila
Copy link
Author

Hi Tyler,
Thank you for your quick response:

Tried the new code and I am getting one error msg for follwoing Line:
d.WaitUntilVisible(By.XPath(Elements.Xpath[Reference.Login.CrmMainPage]) ,new TimeSpan(0, 0, 60),

1>------ Build started: Project: Microsoft.Dynamics365.UIAutomation.Sample.OnPremise, Configuration: Debug Any CPU ------
1>C:\Users\RTulaila\Source\EasyRepro\Microsoft.Dynamics365.UIAutomation.Sample.Shared\ADFSLogin.cs(43,56,43,71): error CS0234: The type or namespace name 'Login' does not exist in the namespace 'Microsoft.Dynamics365.UIAutomation.Reference' (are you missing an assembly reference?)

========== Build: 0 succeeded, 1 failed, 3 up-to-date, 0 skipped ==========

@TYLEROL
Copy link
Member

TYLEROL commented Jan 11, 2019

@rtulaila - I haven't used the OnPremises branch in some time as we don't officially support that branch. There were some changes in that branch that aren't compatible with the code I provided (minor issues). My apologies for missing that in my earlier reply.

I went ahead and checked in a test method ADFSLoginActionTest() to the ADFSLogin.cs file. Once you pull the latest changes, you should be able to alter the TestADFSLogin method to consume ADFSLogionActionTest instead. Add this to the Login() method call as shown below.

I hope this unblocks and you're able to login and see the Dynamics CRM main page. I'll stay tuned for your update.

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

Best Regards,
Tyler

@rtulaila
Copy link
Author

Hi Tyler,
Thank you for checking in new code for us. I run the new code and ADFSLoginActionTest() PASSED with no errors. But again same thing happened browser opened and closed. Login didn't work.
I guess the code is not getting Username and pwd or something wrong with our browser or URL
I will debug this weekend and get back to you on Monday.

Thanks for all your help.
rtulaila

@rtulaila
Copy link
Author

@TYLEROL
Good news finlay we are able to login to our OnPremise CRM 365. The issue is in LoginPage.cs
starting at line 88 It checks if the path ends to see if it’s expected for online, if not then it tries to pass the credentials in the url under http:// and skips the callback entirely.

Now we need to customize "Microsoft.Dynamics365.UIAutomation.Sample.Shared" code and run other tests. I will be reaching you if I we have any issues.
Thanks for your help.
rtulaila

@TYLEROL TYLEROL closed this as completed Jan 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants