Aaron的测试生活小说

半两五钱,笃志向前
  首页  :: 新随笔  :: 联系 :: 管理

Selenium-Rc使用简单示例

Posted on 2009-02-09 21:27  Aaron Wu  阅读(630)  评论(0编辑  收藏  举报

      原文发表于2008-09-26 23:00:43

      今天在论坛上看到这个问题,就出来说一下:Selenium-Rc单独使用,需要添加对于ThoughtWorks.Selenium.Core的引用,然后可以自定义脚本,做web自动化测试~~

贴一部分C#代码:

using System;
using System.Text;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Selenium;

namespace SelenuimTestProject
{
    /// <summary>
    /// UnitTest1 的摘要说明
    /// </summary>
    [TestClass]
    public class UnitTest1
    {
        private ISelenium browser;
        public UnitTest1()
        {
            //
            // TODO: 在此处添加构造函数逻辑
            //
        }

        [TestMethod]
        public void TestMethod1()
        {
            browser = new DefaultSelenium("localhost",
               4444, "*iexplore", "http://www.google.com");
           // browser = new DefaultSelenium("localhost",4444,@"*custom C:\Program Files\Internet Explorer\iexplore.exe","http://www.google.com");
            browser.Start();

            browser.Open("http://www.google.com/webhp?hl=en");
            browser.Type("q", "hello world");
            browser.Click("btnG");
           
            browser.WaitForPageToLoad("5000");
            browser.Stop();
           
           // Assert.AreEqual("hello world - Google Search", browser.GetTitle());
        } 
    }
}