Page 1 of 1

Object initialisation problem.

Posted: Tue Aug 20, 2019 7:29 am
by felixk91
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.

Re: Object initialisation problem.

Posted: Thu Aug 22, 2019 11:45 am
by RobinHood42
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