コード例 #1
0
        public void MigratingElementObjectToHtmlControls()
        {
            // If you already have tests written using WebAii that you want to gradually move to
            // you can use the HTML wrapper class's constructor passing in the existing element
            // object from you current code.

            // The first line is a line of code in your existing test case.
            Element myButtonElement1 = Find.ById("htmlbutton");
            // Add this line to your code to start using the HTML element wrapper class instead.
            HtmlButton buttonObj1 = new HtmlButton(myButtonElement1);

            // Or the next feature is to use the AssignElement() method. Using this method you
            // can wrap any existing element object into one of the new HTML wrapper classes.

            // The first line is a line of code in your existing test case.
            Element myHtmlButtonElement2 = Find.ById("htmlbutton");
            // Create a new control instance and assign the existing element to it.
            HtmlButton buttonObj2 = new HtmlButton();

            buttonObj2.AssignElement(myHtmlButtonElement2);

            // The last advanced feature is the .As<TControl> construct. The .As<TControl>
            // construct acts like a typecast converting your plain element object into the
            // typecast HTML element wrapper object.

            // The first line is a line of code in your existing test case.
            Element myHtmlButtonElement3 = Find.ById("htmlbutton");

            // Make a comparison using the .As<TControl> construct.
            Assert.IsTrue(myHtmlButtonElement3.As <HtmlButton>().InnerText.Equals("Html Button", StringComparison.OrdinalIgnoreCase));
        }