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

Any idea why login field loading but not password field when running on azure self hosted agent? #958

Open
shiyamtj opened this issue Sep 2, 2020 · 5 comments
Labels

Comments

@shiyamtj
Copy link

shiyamtj commented Sep 2, 2020

Question

Any idea why login field loading but not password field when running on azure self hosted agent?
This behavior not showing when I execute automated tests on local machine, but showing this issue when executing on self hosted agents.
Am I missing any configuration on repro?

AutomationTestsPlanProgressRemovedSensored1

@Shakevg
Copy link
Contributor

Shakevg commented Sep 28, 2020

@shiyamtj I also faced the same issue, but it is reproduced really now. Issue that test switch to the password field too fast. Previously I implementation custom login with additional sleep after navigation to the password field.
Does it reproduce always?

@shiyamtj
Copy link
Author

shiyamtj commented Sep 29, 2020

@Shakevg Yeah. Yes, it is reproducible always on CI. This behavior can be seen when after a test got fail.
Any solution for it?

@Shakevg
Copy link
Contributor

Shakevg commented Oct 15, 2020

@shiyamtj Can try custom login implementation (but it is without MFA support)?

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

namespace Dynamics365WebTAF.Pages
{
    public class LoginPages
    {
        private readonly By SubmitButtonLocator = By.XPath("//input[@type='submit']");

        private readonly WebClient Client;
        private readonly IWebDriver Driver;

        public LoginPages(WebClient client)
        {
            Client = client;
            Driver = Client.Browser.Driver;
        }

		public void Login(
            Uri uri,
            SecureString username,
            SecureString password)
        {
			PerformLogin(uri, username, password);
			if (!Client.Browser.Options.UCITestMode)
				return;
			InitializeModes(true);
        }

        private void PerformLogin(
            Uri uri,
            SecureString username,
            SecureString password)
        {
            var num = Client.OnlineDomains == null || Client.OnlineDomains.Any(d => uri.Host.EndsWith(d)) ? 1 : 0;
            Driver.Navigate().GoToUrl(uri);
            if (num != 0)
            {
                if (Driver.IsVisible(By.Id("use_another_account_link")))
                    Driver.ClickWhenAvailable(By.Id("use_another_account_link"));
                Driver.WaitUntilAvailable(By.XPath(Elements.Xpath[Reference.Login.UserId]),
                    $"The Office 365 sign in page did not return the expected result for UserName form and the user '{username.ToUnsecureString()}' could not be signed in.");
                Driver.WaitUntilAvailable(By.XPath(Elements.Xpath[Reference.Login.UserId])).Click();
                Thread.Sleep(TimeSpan.FromSeconds(2));
                Driver.WaitUntilAvailable(By.XPath(Elements.Xpath[Reference.Login.UserId]))
                    .SendKeys(username.ToUnsecureString());
                Thread.Sleep(TimeSpan.FromSeconds(2));
                Driver.WaitUntilAvailable(SubmitButtonLocator).Click();
                
                Thread.Sleep(TimeSpan.FromSeconds(2));
                if (Driver.IsVisible(By.Id("aadTile")))
                    Driver.WaitUntilAvailable(By.Id("aadTile")).Click(true);

                Driver.WaitUntilAvailable(By.XPath(Elements.Xpath[Reference.Login.LoginPassword]),
                    $"The Office 365 sign in page did not return the expected result for Password form and the user '{username.ToUnsecureString()}' could not be signed in.");
                
                Driver.WaitUntilAvailable(By.XPath(Elements.Xpath[Reference.Login.LoginPassword]))
                    .SendKeys(password.ToUnsecureString());
                Driver.WaitUntilAvailable(SubmitButtonLocator).Click();
                Thread.Sleep(1000);
                Driver.WaitUntilVisible(By.XPath(Elements.Xpath[Reference.Login.StaySignedIn]), new TimeSpan(0, 0, 5));
                if (Driver.IsVisible(By.XPath(Elements.Xpath[Reference.Login.StaySignedIn])))
                    Driver.ClickWhenAvailable(By.XPath(Elements.Xpath[Reference.Login.StaySignedIn]));
                WaitForCrmPageToLoad(Driver);
            }
        }

        private void InitializeModes(bool onlineLoginPath = false)
        {
            var uri = Driver.Url;
            var queryParams = "";

            if (Client.Browser.Options.UCITestMode) queryParams += "&flags=testmode=true,easyreproautomation=true";

            if (!string.IsNullOrEmpty(queryParams) && !uri.Contains(queryParams))
            {
                var testModeUri = uri + queryParams;

                Driver.Navigate().GoToUrl(testModeUri);

                Driver.WaitForPageToLoad();

                if (!onlineLoginPath) Driver.WaitForTransaction();
            }
        }

        /// <summary>
        ///     Wait for Dynamics 365 web app load
        /// </summary>
        /// <param name="driver">Web driver</param>
        public static void WaitForCrmPageToLoad(IWebDriver driver)
        {
            var timeout = new TimeSpan?(Constants.DefaultTimeout);

            Action<IWebElement> SuccessCallback(IWebDriver webDriver)
            {
                return _ =>
                {
                    if (!webDriver.HasElement(By.XPath(Elements.Xpath[Reference.Login.CrmUCIMainPage])))
                        return;
                    webDriver.WaitForTransaction(new TimeSpan?());
                };
            }

            var successCallback = SuccessCallback(driver);
            var by = By.XPath(Elements.Xpath[Reference.Login.CrmMainPage]);
            driver.WaitUntilVisible(by, timeout, successCallback);
        }
    }
}

@AngelRodriguez8008
Copy link
Contributor

AngelRodriguez8008 commented Jul 18, 2023

I have self-hosted agents, it works properly, no custom login is required. What is an azure self-hosted agent?

Looks like the PC is too slow, you can use:

            // For one
            var options = TestSettings.Options;
            options.TimeFactor = 1.5f;
            var client = new WebClient(options);
            
            // or Global, Static, for all tests, on [ClassInitialize] method
            TestSettings.SharedOptions.TimeFactor = 1.5f;

AngelRodriguez8008 added a commit to AngelRodriguez8008/EasyRepro that referenced this issue Jul 20, 2023
Isuue microsoft#958  ->  Add Option TimeFactor
If not use incognito mode, create a Temporal Chrome Profite in to avoid ask for login every time
@AngelRodriguez8008
Copy link
Contributor

@shiyamtj @Shakevg I add a Pull Request that support my sample code. Sorry, this logic was implemented just in my fork.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants