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

Tyne ·
更新时间:2024-09-21
· 737 次阅读

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

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

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



net .NET nunit selenium 框架

需要 登录 后方可回复, 如果你还没有账号请 注册新账号