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

I am getting property not found error #944

Closed
akshaysarode31 opened this issue Jul 29, 2024 · 5 comments
Closed

I am getting property not found error #944

akshaysarode31 opened this issue Jul 29, 2024 · 5 comments

Comments

@akshaysarode31
Copy link

akshaysarode31 commented Jul 29, 2024

Below is my Selectors.yaml

LoginForm:
  UsernameInput:
    Type: css
    Value: '#username'
  PasswordInput:
    Type: css
    Value: '#password'
  SubmitButton:
    Type: css
    Value: '#submit'
   public static class SelectorsLoader
{
    public static IDictionary<string, IDictionary<string, Selector>> LoadSelectors(string path)
    {
        var deserializer = new DeserializerBuilder()
            .WithNamingConvention(CamelCaseNamingConvention.Instance)
            .Build();

        using var reader = new StreamReader(path);
        var selectors = deserializer.Deserialize<Dictionary<string, Dictionary<string, Selector>>>(reader);

        // Explicitly convert to IDictionary
        IDictionary<string, IDictionary<string, Selector>> result = new Dictionary<string, IDictionary<string, Selector>>();
        foreach (var kvp in selectors)
        {
            result[kvp.Key] = new Dictionary<string, Selector>(kvp.Value);
        }

        return result;
    }
}

public class Selector
{
    public string Type { get; set; }
    public string Value { get; set; }
}
}

While running this code at line var selectors = deserializer.Deserialize<Dictionary<string, Dictionary<string, Selector>>>(reader);
I am getting error

YamlDotNet.Core.YamlException : Property 'Type' not found on type 'PlaywrightFramework.Helpers.Selector'.

Could you please help me with this and suggest what wrong I am doing here?

@EdwardCooke
Copy link
Collaborator

Try removing the WithNamingConvention from your DeserializerBuilder

@akshaysarode31
Copy link
Author

akshaysarode31 commented Jul 30, 2024

@EdwardCooke This helped Thank you. Just out of curiosity how was WithNamingConvention causing the issue?

@EdwardCooke
Copy link
Collaborator

The naming conventions aren’t the most reliable when deserializing. It is a bit surprising that it didn’t work because it looked like it should have based on the yaml and property names.

@EdwardCooke
Copy link
Collaborator

I realized why it didn’t work and why the error was confusing. When the error said Type with the capital T it was referring to the key in the yaml. Not the property on the class. With camel case naming convention it was expecting the key to be type in the yaml with a lowercase t.

I’m closing this since it’s complete.

@akshaysarode31
Copy link
Author

I realized why it didn’t work and why the error was confusing. When the error said Type with the capital T it was referring to the key in the yaml. Not the property on the class. With camel case naming convention it was expecting the key to be type in the yaml with a lowercase t.

I’m closing this since it’s complete.

This makes sense. Thank you looking back into this.

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