使用Watin做Web UI Automation Test

1.使用Package Manager Console 安装Watin



PM> install-package watin




2.准备一个测试页面:



<html xmlns="http://www.w3.org/1999/xhtml">
<head >
    <title></title>
</head>
<body>


    <div>
    <input type="text" id="txtUserName"/>
        <input type="button" id="btnSubmit" value="Submit"/>
    </div>
    
    <script>
        document.getElementById("btnSubmit").onclick = function() {
            document.getElementById("txtUserName").value = "hello";
        }
    </script>
</body>
</html>




3.deploy测试页面到本地



4.创建UT,添加代码:



IE ie = new IE();


            ie.GoTo("http://192.168.0.30:81/LocalWebApp/watinTest/1.html");
            ie.ShowWindow(NativeMethods.WindowShowStyle.Maximize);
            
            ie.TextField(Find.ById("txtUserName")).TypeText("watin");
            ie.Button(Find.ById("btnSubmit")).Click();


            var txt  = ie.TextField(Find.ById("txtUserName"));
            Assert.IsTrue(txt.Value == "hello");







你可能感兴趣的:(使用Watin做Web UI Automation Test)