• <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>
  • Selenium私房菜系列5 -- 第一個Selenium RC測試案例

    發表于:2011-10-08來源:未知作者:領測軟件測試網采編點擊數: 標簽:selenium
    Selenium簡介》中講過,Selenium RC支持多種語言編寫測試案例,如:C#,Python。在工作中,我傾向于是用Python這類動態語言編寫測試案例,因為這樣的測試案例無需編譯:>,試想如果你有1000個測試案例,每個都要編譯,那會給編譯服務器很大的壓力,而且案例修

      《Selenium簡介》中講過,Selenium RC支持多種語言編寫測試案例,如:C#,Python。在工作中,我傾向于是用Python這類動態語言編寫測試案例,因為這樣的測試案例無需編譯:>,試想如果你有1000個測試案例,每個都要編譯,那會給編譯服務器很大的壓力,而且案例修改后,還得重新編譯才能運行:<。但在本系列的文章中,我還是打算使用C#編寫示范例子。

      Selenium RC下載:http://seleniumhq.org/download/

    Selenium私房菜系列5 -- 第一個Selenium RC測試案例 - swl632 - 我的<STRONG><A  target=博客" border="1" height="162" src="/uploads/allimg/111008/09464B412-0.jpg" width="374" />

      寫Selenium RC的測試案例

      上一篇《Selenium IDE的使用》中,提到了Selenium IDE可以把錄制的腳本轉為其他語言的腳本,所以我繼續用上一篇的腳本為例子,下面是把腳本語言轉換為C#后的代碼:

      using System;

      using System.Text;

      using System.Text.RegularExpressions;

      using System.Threading;

      using NUnit.Framework;

      using Selenium;

      namespace SeleniumTests

      {

      [TestFixture]

      public class NewTest

      {

      private ISelenium selenium;

      private StringBuilder verificationErrors;

      [SetUp]

      public void SetupTest()

      {

      selenium = new DefaultSelenium("localhost", 4444, "*chrome", "http://change-this-to-the-site-you-are-testing/");

      selenium.Start();

      verificationErrors = new StringBuilder();

      }

      [TearDown]

      public void TeardownTest()

      {

      try

      {

      selenium.Stop();

      }

      catch (Exception)

      {

      // Ignore errors if unable to close the browser

      }

      Assert.AreEqual("", verificationErrors.ToString());

      }

      [Test]

      public void TheNewTest()

      {

      selenium.Open("/");

      selenium.Type("kw", "hyddd");

      selenium.Click("sb");

      selenium.WaitForPageToLoad("30000");

      try

      {

      Assert.IsTrue(selenium.IsTextPresent("hyddd - 博客園"));

      }

      catch (AssertionException e)

      {

      verificationErrors.Append(e.Message);

      }

      selenium.Click("//table[@id='1']/tbody/tr/td/a/font");

      }

      }

      }

      在這里,轉換后的腳本使用了NUnit測試框架,為了簡化,我用VS的Test Project代替(當然你也可以用Console Application建立測試工程的),步驟如下:

      1.建立Test Project

    Selenium私房菜系列5 -- 第一個Selenium RC測試案例 - swl632 - 我的博客

      2.導入DLL引用

      把selenium-dotnet-client-driver-1.0-beta-2目錄中的ThoughtWorks.Selenium.Core.dll,ThoughtWorks.Selenium.IntegrationTests.dll,ThoughtWorks.Selenium.UnitTests.dll加入項目:

    Selenium私房菜系列5 -- 第一個Selenium RC測試案例 - swl632 - 我的博客

      3.把上面自動生成的代碼再改一下

      using System;

      using System.Text;

      using System.Collections.Generic;

      using Microsoft.VisualStudio.TestTools.UnitTesting;

      using Selenium;

      namespace SeleniumTest

      {

      [TestClass]

      public class UnitTest1

      {

      [TestMethod]

      public void Test()

      {

      //127.0.0.1為Selenium測試服務器位置。

      //4444為Selenium測試服務器監聽端口。

      //*iexplore為啟動瀏覽器類型,我把它改為了IE瀏覽器。

      //http://www.baidu.com為源地址。

      ISelenium selenium = new DefaultSelenium("127.0.0.1", 4444, "*iexplore", "http://www.baidu.com");

      selenium.Start();

      selenium.Open("/");

      selenium.Type("kw", "hyddd");

      selenium.Click("sb");

      selenium.WaitForPageToLoad("30000");

      Assert.IsTrue(selenium.IsTextPresent("hyddd - 博客園"));

      selenium.Click("//table[@id='1']/tbody/tr/td/a/font");

      selenium.Close();

      selenium.Stop();

      }

      }

      }

      4.啟動Selenium測試服務器

      打開cmd進入selenium-server-1.0-beta-2目錄,輸入“java -jar selenium-server.jar”(需要先安裝JRE),啟動Selenium測試服務器。

    Selenium私房菜系列5 -- 第一個Selenium RC測試案例 - swl632 - 我的博客

    原文轉自:http://www.kjueaiud.com

    老湿亚洲永久精品ww47香蕉图片_日韩欧美中文字幕北美法律_国产AV永久无码天堂影院_久久婷婷综合色丁香五月

  • <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>