Vs2008采用Selenium进行Web 功能测试
2009-07-28 14:47
274 查看
1.采用selenium录制脚本。
录制的脚本如下:
在Vs2008中新建一个C#测试项目
添加引用
当然,实际可能用不了这么多dll,但是刚开始还是都加上。
把Selenium IDE生成的C#程序拷贝到这个测试程序里,然后做下修改。
添加using Microsoft.VisualStudio.TestTools.UnitTesting;
注释掉//using NUnit.Framework;
[TestFixture] -->[TestClass]
[SetUp]--->[TestInitialize]
[TearDown]--> [TestCleanup]
[Test]--->[TestMethod]
具体代码如下:
CTRL+F5运行。Ok.
关于FireFox测试的时候配置问题可以参考网站。特别是Firefox通过设置代理上网的时候,Selenium启动FireFox访问外网的时候是采用FireFox安装的默认配置,需要自己设置一个给FireFox用的配置文件。
http://girliemangalo.wordpress.com/2009/02/05/creating-firefox-profile-for-your-selenium-rc-tests/
录制的脚本如下:
using System; using System.Text; using System.Text.RegularExpressions; using System.Threading; using NUnit.Framework; using Selenium; namespace SeleniumTests { [TestFixture] public class Untitled 2 { 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 TheUntitled 2Test() { selenium.Open("/"); selenium.Click("link=新 闻"); selenium.WaitForPageToLoad("30000"); selenium.Click("link=网页"); selenium.WaitForPageToLoad("30000"); selenium.Click("link=贴 吧"); selenium.WaitForPageToLoad("30000"); selenium.Click("link=MP3"); selenium.Click("link=MP3"); selenium.WaitForPageToLoad("30000"); selenium.Click("//center"); selenium.Click("link=图 片"); selenium.WaitForPageToLoad("30000"); selenium.Click("link=视 频"); selenium.WaitForPageToLoad("30000"); selenium.Click("link=网 页"); selenium.WaitForPageToLoad("30000"); } } }
在Vs2008中新建一个C#测试项目
添加引用
当然,实际可能用不了这么多dll,但是刚开始还是都加上。
把Selenium IDE生成的C#程序拷贝到这个测试程序里,然后做下修改。
添加using Microsoft.VisualStudio.TestTools.UnitTesting;
注释掉//using NUnit.Framework;
[TestFixture] -->[TestClass]
[SetUp]--->[TestInitialize]
[TearDown]--> [TestCleanup]
[Test]--->[TestMethod]
具体代码如下:
using System; using System.Text; using System.Text.RegularExpressions; using System.Threading; using Microsoft.VisualStudio.TestTools.UnitTesting; //using NUnit.Framework; using Selenium; namespace SeleniumTests { //[TestFixture] [TestClass] public class Untitled { private ISelenium selenium; private StringBuilder verificationErrors; //[SetUp] [TestInitialize] public void SetupTest() { //selenium = new DefaultSelenium("localhost", 4444, "*chrome", "http://change-this-to-the-site-you-are-testing/"); selenium = new DefaultSelenium("localhost", 4444, "*chrome", "http://www.baidu.com"); selenium.Start(); verificationErrors = new StringBuilder(); } //[TearDown] [TestCleanup] public void TeardownTest() { try { selenium.Stop(); } catch (Exception) { // Ignore errors if unable to close the browser } Assert.AreEqual("", verificationErrors.ToString()); } // [Test] [TestMethod] public void TheUntitledTest() { selenium.Open("/"); selenium.Click("link=新 闻"); selenium.WaitForPageToLoad("30000"); selenium.Click("link=网页"); selenium.WaitForPageToLoad("30000"); selenium.Click("link=贴 吧"); selenium.WaitForPageToLoad("30000"); selenium.Click("link=MP3"); selenium.Click("link=MP3"); selenium.WaitForPageToLoad("30000"); selenium.Click("//center"); selenium.Click("link=图 片"); selenium.WaitForPageToLoad("30000"); selenium.Click("link=视 频"); selenium.WaitForPageToLoad("30000"); selenium.Click("link=网 页"); selenium.WaitForPageToLoad("30000"); } } }
CTRL+F5运行。Ok.
关于FireFox测试的时候配置问题可以参考网站。特别是Firefox通过设置代理上网的时候,Selenium启动FireFox访问外网的时候是采用FireFox安装的默认配置,需要自己设置一个给FireFox用的配置文件。
http://girliemangalo.wordpress.com/2009/02/05/creating-firefox-profile-for-your-selenium-rc-tests/
相关文章推荐
- 使用分层的 Selenium 框架进行复杂 Web 应用的自动测试
- 使用分层的 Selenium 框架进行复杂 Web 应用的自动测试
- 【javaweb:Servlet】采用BeanUtils进行网站注册的Servlet
- selenium webdriver读取excel进行数据驱动测试
- 使用 CasperJS 对 Web 网站进行功能测试
- 使用分层的Selenium框架进行复杂 Web 应用的自动测试
- selenium webdriver读取excel进行数据驱动测试
- ruby+selenium-webdriver一步一步进行自动化测试(3)——面向对象编程
- 使用VS2005进行WEB功能测试
- ruby+selenium-webdriver一步一步进行自动化测试------面向对象编程
- ruby+selenium-webdriver一步一步进行自动化测试----学习总结陈述
- 使用VS2005进行WEB功能测试
- 使用开源工具SeleniumRC进行功能测试
- 初学 用 Selenium 进行功能测试
- 分层 Selenium 框架进行复杂 Web 应用程序自动化测试
- Selenium WebDriver对cookie进行处理绕过登录验证码
- 使用selenium和webdriver进行自动化测试
- 使用分层的 Selenium 框架进行复杂 Web 应用的自动测试
- 使用selenium webdriver进行元素定位
- Selenium Webdriver启动IE、Chrome、Firefox三大浏览器进行测试