Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I have heard this problem before and meant to investigate this for a while. Now that WatiN 2.0 beta 1 is available I sat down and created a helper class to solve this problem with Visual Studios test runner. Following the helper class and the revamped test class. I also <a href="http://watinandmore.blogspot.com/2009/03/reusing-ie-instance-in-vs-test.html" rel="noreferrer">blogged</a> about this solution to give it even more exposure.</p> <pre><code>public class IEStaticInstanceHelper { private IE _ie; private int _ieThread; private string _ieHwnd; public IE IE { get { var currentThreadId = GetCurrentThreadId(); if (currentThreadId != _ieThread) { _ie = IE.AttachToIE(Find.By("hwnd", _ieHwnd)); _ieThread = currentThreadId; } return _ie; } set { _ie = value; _ieHwnd = _ie.hWnd.ToString(); _ieThread = GetCurrentThreadId(); } } private int GetCurrentThreadId() { return Thread.CurrentThread.GetHashCode(); } } </code></pre> <p>And the test class using this helper:</p> <pre><code>[TestClass] public class UnitTest { private static IEStaticInstanceHelper ieStaticInstanceHelper; [ClassInitialize] public static void testInit(TestContext testContext) { ieStaticInstanceHelper = new IEStaticInstanceHelper(); ieStaticInstanceHelper.IE = new IE("http://news.bbc.co.uk"); } public IE IE { get { return ieStaticInstanceHelper.IE; } set { ieStaticInstanceHelper.IE = value; } } [ClassCleanup] public static void MyClassCleanup() { ieStaticInstanceHelper.IE.Close(); ieStaticInstanceHelper = null; } [TestMethod] public void testOne() { Assert.IsTrue(IE.ContainsText("Low graphics")); } [TestMethod] public void testTwo() { Assert.IsTrue(IE.ContainsText("Low graphics")); } } </code></pre> <p>HTH, Jeroen</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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