Object initialisation problem.

Class library usage, coding and language questions.
User avatar
felixk91
Posts: 34
Joined: Wed Feb 10, 2016 11:16 pm

Object initialisation problem.

Post by felixk91 » Tue Aug 20, 2019 7:29 am

Hi there,

I am trying to run some BDD tests using Ranorex API, SpecFlow and Nunit framework.
While running I got the following exception:

Code: Select all

The type initializer for 'Test.Automation.ObjRepo.LoginDialog' threw an exception.
The following is the object class:

Code: Select all

using Ranorex;

namespace Test.Automation.ObjRepo
{
    public class LoginDialog
    {
        //public LoginDialog() { }

        private static Form LoginForm = "/form[@title~'^Pryda Build Designer']";
        private Text Username { get; set; } = LoginForm.FindSingle<Text>("/text[@AccessibleName='User name:']");
        private Text Password { get; set; } = LoginForm.FindSingle<Text>("/text[@AccessibleName='Password:']");
        private Button LogOnButton { get; set; } = LoginForm.FindSingle<Button>("/button[@text='Log on']");

        public void ActivateLogOnDailog()
        {
            LoginForm.Activate();
        }

        public Text GetUsername()
        {
            return Username.TextValue;
        }

        public void SetUsername(string username)
        {
            Username.Click();
            Username.PressKeys(username);
        }

        public void SetPassword(string password)
        {
            Password.Click();
            Password.PressKeys(password);
        }

        public void LogOnUser()
        {
            LogOnButton.Click();
        }
    }
}
Can someone help to understand what is the root of the exception?

Thanks,
Felix.

User avatar
RobinHood42
Posts: 324
Joined: Fri Jan 09, 2015 3:24 pm

Re: Object initialisation problem.

Post by RobinHood42 » Thu Aug 22, 2019 11:45 am

Hey,

Why did you comment our the constructor? This might be a problem. Did you import the correct bit version of the Ranorex DLL's and are you using the right .NET Framework.
This is no Ranorex exception, there is a problem in your implementation. Without the full stack trace, it is almost impossible to provide any help. I would recommend debugging your code and if this doesn't give you the answer, post the whole stack trace.

Cheers,
Robin