您的位置:軟件測(cè)試 > 開源軟件測(cè)試 > 開源功能測(cè)試工具 > Selenium
使用開源工具SeleniumRC進(jìn)行功能測(cè)試
作者:網(wǎng)絡(luò)轉(zhuǎn)載 發(fā)布時(shí)間:[ 2013/12/10 14:21:28 ] 推薦標(biāo)簽:

  在測(cè)試前必須先啟動(dòng)他,啟動(dòng)過(guò)程:開始-運(yùn)行-cmd-cd <服務(wù)器端目錄>-java -jar selenium-server.jar(服務(wù)器端其實(shí)是個(gè)Jar文件)

  然后可以進(jìn)行客戶端,本文用C#來(lái)進(jìn)行測(cè)試,首先建立一個(gè)C#類庫(kù)工程,添加引用selenium-dotnet-client-driver-1.0.1目錄下的所有DLL。

  下面,新建類SeleniumTest,具體代碼如下:

 1     [TestFixture]
 2     public class SeleniumTest
 3     {
 4         private ISelenium selenium;
 5         private StringBuilder verificationErrors;
 6
 7         [SetUp]
 8         public void SetupTest()
 9         {
10             selenium = new DefaultSelenium("localhost", 4444, "*iexplore", "http://localhost:2896/WebTestSite/");
11             selenium.Start();
12           
13             verificationErrors = new StringBuilder();
14         }
15
16         [TearDown]
17         public void TeardownTest()
18         {
19             try
20             {
21                 selenium.Stop();
22             }
23             catch (Exception)
24             {
25                 // Ignore errors if unable to close the browser
26              }
27             Assert.AreEqual("", verificationErrors.ToString());
28         }
29
30         [Test]
31         public void TheSeleniumTest()
32         {
33             selenium.Open("/WebTestSite/");
34             selenium.Type("TextBox1", "qeq");
35             selenium.Type("TextBox2", "qwe");
36             selenium.Click("Button1");
37
38            //判斷是否出現(xiàn)alert("fail")
39              Assert.AreEqual("fail", selenium.GetAlert());
40          
41             selenium.Type("TextBox1", "123");
42             selenium.Type("TextBox2", "123");
43             selenium.Click("Button1");
44             Assert.AreEqual("fail", selenium.GetAlert());
45
46          //點(diǎn)擊鏈接
47              selenium.Click("link=2");
48          //等待
49              selenium.WaitForPageToLoad("30000");
50             selenium.Click("link=3");
51             selenium.WaitForPageToLoad("30000");
52           
53         }
54         [Test]
55         public void TestTitle()
56         {
57             selenium.Open("/WebTestSite/**.aspx");
58             Assert.AreEqual("yourtitle", selenium.GetTitle());
59          
60         }
61     }

  這樣,建好了,可以打開NUit進(jìn)行測(cè)試,也可以直接寫個(gè)main進(jìn)行測(cè)試。

  seleniumhq官方文檔:

  http://seleniumhq.org/docs/05_selenium_rc.html#introduction

上一頁(yè)12下一頁(yè)
軟件測(cè)試工具 | 聯(lián)系我們 | 投訴建議 | 誠(chéng)聘英才 | 申請(qǐng)使用列表 | 網(wǎng)站地圖
滬ICP備07036474 2003-2017 版權(quán)所有 上海澤眾軟件科技有限公司 Shanghai ZeZhong Software Co.,Ltd