Note that there are some explanatory texts on larger screens.

plurals
  1. POControls re-initialization using WatiN
    text
    copied!<p>I ran in to a situation where I need to re-initialize the controls of each page when the page gets loaded for each test. I have separated the controls declaration of a page in one code file and operation that are performed on those controls in another code file. </p> <p>I have exposed those operations to the test cases, so that no controls are passed from test cases. I have implemented Singleton for controls initialization. Due to this, the first test case excutes with out any issues. When second test kicks off, it says "Object reference not set to an instance of an object." when trying to access control that is already initialized.</p> <pre><code>public partial class Login : Page { protected TextField txtUserName; protected TextField txtPassword; protected TextField txtConPassword; public Login() { this.txtUserName = Util.Browser.TextField(Find.ById("username")); this.txtPassword = Util.Browser.TextField(Find.ById("password")); this.txtConPassword = Util.Browser.TextField(Find.ByValue("password")); } } public partial class Login { /// &lt;summary&gt; /// Set user name. /// &lt;/summary&gt; /// &lt;param name="userName"&gt;User name.&lt;/param&gt; public void SetUserName(string userName) { this.txtUserName.TypeText(userName); //Util.SetTextHelper(this.txtUserName, userName); } } </code></pre> <p>I guess the controls get initialized only when Browser gets loaded with Document. When the first test ends, Browser gets closed and disposed. So when the Browser gets re-initialized (for the second test) with the document since the controls initialization implemented using a Singleton, the control values throws the error.</p> <p>This issue can be resolved by not implementing Singleton, but re-initializing the controls where ever required does not make sense.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload