使用Watin做Web UI Automation Test

mybwu_com發表於2014-03-30

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");







相關文章