您的位置:軟件測試 > 開源軟件測試 > 開源單元測試工具 > Nunit
在.Net配置Selenium和Nunit測試框架
作者:網(wǎng)絡(luò)轉(zhuǎn)載 發(fā)布時間:[ 2013/12/27 9:09:04 ] 推薦標(biāo)簽:Selenium 單元測試 Nunit

第1步:.Net中C#引用Selenium

  .NET中需要使用到Selenium時,需要引用Selenium的dll,

   配置Selenium操作步驟:

  1.1、References處右鍵選擇Add Reference,Browse選擇  Selenium目錄" seleniumselenium-dotnet-client-driver-1.0.1ThoughtWorks.Selenium.Core.dll

  1.2、添加一個引用:using  Selenium;

第2步:引用Nunit

   2.1:右鍵點擊reference->add reference->選擇nunit.framework

   2.2:添加一個引用:using NUnit.Framework

    using System;

    using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;

namespaceopenEmail
{
   [TestFixture]
    public classopenEmail
    {
       [Test]
       publicvoidopenEmail(

          {

                Selenium.ISeleniumff =newDefaultSelenium("localhost", 4444,"*firefox","http://mail.163.com");

                ff.Start();

                ff.Open("http://mail.163.com ");

                ff.WindowMaximize();

                ff.Type("username","wbk001@163.com");

                ff.Type("password","123456");

                ff.Click("//button[@type='submit'] ");

           }


    }
}

Seleum學(xué)習(xí):

定位頁面的元素,selenium提供如下強(qiáng)大的定位元素的方法。

· id=id

· name=name

· dom=javascriptExpression

· xpath=xpathExpression

· link=textPattern

· css=cssSelectorSyntax

1: 通過id和name來選擇元素

   ff.Type("username","wbk001@sina.com");

2:通過鏈接文字來選擇元素

ff.Click("link=博客");

3:通過Xpath來選擇元素

ff.Click("//button[@type='submit'] ");

ff.Click("//input[@value='' and @type='submit']");

可以在firfox下安裝組件:Selenium IDE Buttons(firfox--工具-添加組件)

用Selenium IDE來選擇元素(Selenium IDE 可以錄制)。

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