在.Net配置Selenium和Nunit测试框架

上一篇 / 下一篇  2010-11-12 15:04:50 / 个人分类:测试工具

selenium是一个非常棒的Web测试工具


1步:.Net中C#引用Selenium

  .NET中需要使用到Selenium时,需要引用Seleniumdll,

   配置Selenium操作步骤:

  1.1References处右键选择Add ReferenceBrowse选择  Selenium目录" selenium\selenium-dotnet-client-driver-1.0.1\ThoughtWorks.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;

namespace
openEmail
{
   
[TestFixture]
    public class
openEmail
    {
       
[Test]
       public
voidopenEmail(

          {

                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学习

定位页面的元素,selenium提供如下强大的定位元素的方法。

· id=id

· name=name

· dom=javascriptExpression

· xpath=xpathExpression

· link=textPattern

· css=cssSelectorSyntax

1: 通过idname来选择元素

   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 可以录制)。

  

 


TAG:

 

评分:0

我来说两句

Open Toolbar