microsoft / EasyRepro

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

[BUG] LookupItem "Loading..." for customerid #769

Open dfo-elca opened 4 years ago

dfo-elca commented 4 years ago

EasyRepro Version

UCI or Classic Web

Online or On Premise

Browser

While running the default CreateCaseUCI, at the step of setting the customerid, the browser stays at "Loading..." until it times out, instead of displaying the record. If I manually delete the last char and write it again, it finds the record and the test scenario ends correctly. I suspect it's related to the value being typed too fast by selenium.

Here is what it looks like: 2020-02-19 16_26_33-Window

Code: LookupItem customer = new LookupItem { Name = "customerid", Value = "aaron aina", Index = 0}; xrmApp.Entity.SetValue(customer);

AngelRodriguez8008 commented 4 years ago

It will wait 3 secs after finish after typing. Wait again until the Items show once with the text that you look for. Did you work with the latest version?

dfo-elca commented 4 years ago

Hi, thanks for the reply. It's the last version. The issue is that it displays "loading..." indefinitely, so waiting 3 secs doesn't fix it. The only way to clear this "loading..." message is, by hand in the browser, erasing part of the value and typing it again.

AngelRodriguez8008 commented 4 years ago

Hi,

I mention it because you say that Selenium is typing too fast.

I was able to reproduce it, in the Test UCITestCreateCase, same as your I guest, I wonder about that because I fix this test last week. However for other Lookup Tests it is working fine. I need to stop for the moment, if you find more information about it will help me to fix it later.

Thanks for the Feedback br.

dfo-elca commented 4 years ago

Thanks.

I confirm it's in the test UCITestCreateCase.

I let you know if I find a fix. I had this selenium speed idea because it can be reproduced also in CRM without using EasyRepro. Just copy/past a name in the LookUp field and it will do the same, but if you type it by hand, at a human pace, it works.

AngelRodriguez8008 commented 4 years ago

This Error just happen if the value is a Contact, for Accounts works fine. :-(

AngelRodriguez8008 commented 4 years ago

After the one retry attempt the value is set successfully for contacts.

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

          xrmApp.Navigation.OpenApp(UCIAppName.CustomerService);

          xrmApp.Navigation.OpenSubArea("Service", "Cases");

          xrmApp.CommandBar.ClickCommand("New Case");

          xrmApp.ThinkTime(500);

          xrmApp.Entity.SetValue("title", "Test Case " + TestSettings.GetRandomString(5, 10));

          var value = "Yew Soon";
          var customer = new LookupItem { Name = "customerid", Value = value };
          string customerName = null;
          int i = 1;
          do
          {
              try
              {
                  xrmApp.Entity.SetValue(customer);
                  xrmApp.ThinkTime(500);
                  customerName = xrmApp.Entity.GetValue(customer);
              }
              catch (Exception e)
              {
                  Console.WriteLine($"Attempts {i}/10. Fail: {e}");
              }

              i++;
          } while (customerName != value && i <= 10);

          Assert.IsNotNull(customerName);
          Assert.IsTrue(customerName.Contains(value));
          Console.WriteLine($"Test Pass Successfully after {i-1} attempts.");
      }
}

I suggest for this case to repair the build-in retry mechanism, this is not working at the moment. That will fix this Issue, I will open a Bug with this in intention.

Note: Simulate typing slowly or retyping the last char do not help, Run the follow code to try it yourself.

Click to expand! ```csharp [TestMethod] public void UCITestCreateCase_EnterCustomerId_Contact_RetypeLastChar() { var client = new WebClient(TestSettings.Options); using (var xrmApp = new XrmApp(client)) { xrmApp.OnlineLogin.Login(_xrmUri, _username, _password, _mfaSecrectKey); xrmApp.Navigation.OpenApp(UCIAppName.CustomerService); xrmApp.Navigation.OpenSubArea("Service", "Cases"); xrmApp.CommandBar.ClickCommand("New Case"); xrmApp.ThinkTime(500); xrmApp.Entity.SetValue("title", "Test Case " + TestSettings.GetRandomString(5, 10)); var value = "Yew Soon"; var browserOpts = new BrowserCommandOptions(Constants.DefaultTraceSource, "My Custom Set Lookup", 10, // retryAttempts is ignored Constants.DefaultRetryDelay, null, true, typeof(NoSuchElementException), typeof(StaleElementReferenceException)); string customerName = null; int i = 0; do { client.Execute(browserOpts, driver => { var input = driver.WaitUntilClickable(By.XPath("//input[@aria-label='Customer Lookup']")); if (input == null) return false; input.Click(); input.SendKeys(Keys.Control + "a"); input.SendKeys(Keys.Backspace); foreach (char c in value) { input.SendKeys(c.ToString()); Thread.Sleep(500); } // Retype the last char input.SendKeys(Keys.Backspace); Thread.Sleep(1500); input.SendKeys(value.Last().ToString()); Thread.Sleep(3000); input.SendKeys(Keys.ArrowDown + Keys.Enter); Thread.Sleep(3000); return true; }); var customer = new LookupItem { Name = "customerid" }; customerName = xrmApp.Entity.GetValue(customer); //if(customerName != value) // throw new InvalidOperationException($"{value} not found"); i++; } while (customerName != value && i < 10); Assert.IsNotNull(customerName); Assert.IsTrue(customerName.Contains(value)); } } ```
dfo-elca commented 4 years ago

I suggest for this case to repair the build-in retry mechanism, this is not working at the moment. That will fix this Issue, I will open a Bug with this in intention.

Thanks!

jowells1 commented 4 years ago

I was able to workaround this by doing a clearvalue prior to the setvalue:

// To work around the bug below, clearvalue first to initalize the field and then set it
xrmApp.Entity.ClearValue(new LookupItem { Name = "customerid"});

// Bug - System.InvalidOperationException: No Results Matching maria campbell Were Found. #769
xrmApp.Entity.SetValue(new LookupItem { Name = "customerid", Value = "maria campbell", Index = 0 });
VasanthChidambaram commented 4 years ago

I was able to workaround this by doing a clearvalue prior to the setvalue:

// To work around the bug below, clearvalue first to initalize the field and then set it
xrmApp.Entity.ClearValue(new LookupItem { Name = "customerid"});

// Bug - System.InvalidOperationException: No Results Matching maria campbell Were Found. #769
xrmApp.Entity.SetValue(new LookupItem { Name = "customerid", Value = "maria campbell", Index = 0 });

This is not working for me in Quick create form

VasanthChidambaram commented 4 years ago

Any fixes for this issue ? I was facing this issue only for selected values in lookup option

jazzyuppal commented 4 years ago

Hi,

Also facing this issue, running in Visual Studio 2019. Similar to others, the lookup appears but it just isn't selected. An exception is generated:

Managed Debugging Assistant 'ContextSwitchDeadlock' Message=Managed Debugging Assistant 'ContextSwitchDeadlock' : 'The CLR has been unable to transition from COM context 0x6e19a8 to COM context 0x6e1a60 for 60 seconds. The thread that owns the destination context/apartment is most likely either doing a non pumping wait or processing a very long running operation without pumping Windows messages. This situation generally has a negative performance impact and may even lead to the application becoming non responsive or memory usage accumulating continually over time. To avoid this problem, all single threaded apartment (STA) threads should use pumping wait primitives (such as CoWaitForMultipleHandles) and routinely pump messages during long running operations.'

Code being run was:

xrmApp.Entity.ClearValue(new LookupItem { Name = "customerid" }); xrmApp.Entity.SetValue(new LookupItem { Name = "customerid", Value = "Jas Limited", Index = 0 });