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

[BUG] GetValue not working #765

Closed
4 tasks
imartinflores opened this issue Feb 18, 2020 · 13 comments
Closed
4 tasks

[BUG] GetValue not working #765

imartinflores opened this issue Feb 18, 2020 · 13 comments
Labels

Comments

@imartinflores
Copy link
Contributor

imartinflores commented Feb 18, 2020

Bug Report

xrmApp.Entity.GetValue command not working.

EasyRepro Version

  • Microsoft Dynamics 365 Online Version 9.1 (9.1.x) (DB 9.1.x) online

UCI or Classic Web

  • UCI (XrmApp)

Online or On Premise

  • Online

Browser

  • Chrome

Describe the bug
Hi guys, seems like the GetValue command is not working. I have checked EasyRepro repo and it seems to be trying to find "input" or "textarea" tagname when using the GetValue command.

if (fieldContainer.FindElements(By.TagName("input")).Count > 0)
{
var input = fieldContainer.FindElement(By.TagName("input"));
if (input != null)
{
IWebElement fieldValue = input.FindElement(By.XPath(AppElements.Xpath[AppReference.Entity.TextFieldValue].Replace("[NAME]", field)));
text = fieldValue.GetAttribute("value").ToString();

                    // Needed if getting a date field which also displays time as there isn't a date specifc GetValue method
                    var timefields = driver.FindElements(By.XPath(AppElements.Xpath[AppReference.Entity.FieldControlDateTimeTimeInputUCI].Replace("[FIELD]", field)));
                    if (timefields.Any())
                    {
                        text = $" {timefields.First().GetAttribute("value")}";
                    }
                }
            }
            else if (fieldContainer.FindElements(By.TagName("textarea")).Count > 0)
            {
                text = fieldContainer.FindElement(By.TagName("textarea")).GetAttribute("value");
            }
            else
            {
                throw new Exception($"Field with name {field} does not exist.");
            }

Some of the LookupItems are now

or
    so it is throwing "Field element {name} does not exist. This was working fine on Friday. We picked the issue yesterday, and we know that there was a Microsoft update during the weekend.

    Code to reproduce

    xrmApp.Entity.GetValue(new LookupItem { Name = "name"});

    Expected behavior
    LookupItem value should be found

    Screenshots

    lookup

    lookup2

    If you can look into this ASAP should be great. Thanks

@AngelRodriguez8008
Copy link
Contributor

Hi @imartinflores,

Thanks for your feedback.

for a lookup value you should use the follow overload of GetValue

string lookupValue = xrmApp.Entity.GetValue(new LookupItem { Name = "primarycontactid" });

Can you check please that your bug is not the same that #756?

PR #764 should fix it.

br

@Haywaii
Copy link

Haywaii commented Feb 18, 2020

Hi @AngelRodriguez8008,

I work with @imartinflores and we are already doing the way you offer.
Our description was not entirely correct i must admit so good point from you :)
We will update the problem but even by using Lookup it doesn't work.

Like we said, our assumption so far is that something change on UI with the MS update because we didn't change anything on our code and it was working fine before.
I even checked in the Entity itself and the field id is there.

@AngelRodriguez8008
Copy link
Contributor

AngelRodriguez8008 commented Feb 18, 2020

Hi @Haywaii,

Yes, it doesn't works, because this the PR is not merged yet to 'develop' & released. But is the same Issue as #756?

To be sure you can run your code as I show in this comment.
or you can get the code from PR #764 & try with this.

That will call the "new" logic. After this PR get approved you will be able to work as usual, with ´GetValue(LookupItem)´ instead the ´GetValue(LookupItem[])´ which now is working fine in 'develop' branch.

Thanks & br

@imartinflores
Copy link
Contributor Author

imartinflores commented Feb 18, 2020

Hi @AngelRodriguez8008 , thanks for the answer. Yes, that's ok, do you know when this will get merged ?
By the way, I think the Xpath is not correct for Lookups, we still have some failures when trying to find elements like this one:

Entity_LookupFieldExistingValue: //*[@data-id='[NAME].fieldControl-LookupResultsDropdown_[NAME]_selected_tag']

Seems like not all of the LookupItems have the same xpath, you are using it on the TryGetValue.

xpath1

xpath2

Thank you.

@AngelRodriguez8008
Copy link
Contributor

From the implementation GetValue(LookupItem[]) I deduce that you get in HTML an when the field do not contains any value. I such case GetValue return am empty string. Is it your case?

@imartinflores
Copy link
Contributor Author

Yes, before was returning "---" as it is the value that the field has. Now, even if it has "---" it returns empty, we can change that on our tests, but need to confirm we will always return empty in this case.

@AngelRodriguez8008
Copy link
Contributor

Try this:

using Microsoft.Dynamics365.UIAutomation.Browser;
// in Tests
Assert.IsTrue(lookupValue.IsEmptyValue()); 

You should have already in your API:

Microsoft.Dynamics365.UIAutomation.Browser.StringExtensions: 65-66:         
public static bool IsEmptyValue(this string fieldValue)
            => string.IsNullOrWhiteSpace(fieldValue?.Trim('-')); // null, Empty or "---"

You will never need to change your tests again :-)

Note: or you can implement your own IsEmptyLookupValue & you will be able to change it just in one place.

@AngelRodriguez8008
Copy link
Contributor

Hi @imartinflores,

The PR is merged can we close this Issue?

Thanks & br

@imartinflores
Copy link
Contributor Author

Yes, very nice !

Thank you!

@AngelRodriguez8008
Copy link
Contributor

Sorry. I mean:
Can you close it please?
I'm not able to do it.

@imartinflores
Copy link
Contributor Author

@AngelRodriguez8008 have you updated the nuget package ?

@AngelRodriguez8008
Copy link
Contributor

Sorry. I'm not able to do it. Probably the MS guys did it.

@imartinflores
Copy link
Contributor Author

No worries, thanks for helping!

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