selenium IDE & Remote Control & Webdriver
一直忘记写selenium的开始学习的过程,今天趁五一,天气有雨,写下这文章
1.进入selnium官网,了解selenium1,2,grid的区别。下载c#相关的包(使用c#的人非常少)

2.使用IED录制脚本,用C#导出,观察脚本的写法。当然需要在selenium官网下载IDE(firefox)
2.1下载插件成功后会在firefox看到selenium IDE,点击

2.2使用IDE录制对www.google.com的搜索操作

2.3可以导出相应的c# remote control 或webdriver脚本

2.3.1使用selenium 1 (Remote control)记得需要启动 rc server,脚本才能运行
原理图:

主要代码:
using System;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using NUnit.Framework;
using Selenium; namespace SeleniumTests
{
[TestFixture]//测试类
public class re
{
private ISelenium selenium;
private StringBuilder verificationErrors; [SetUp]//测试准备(数据,方法)
public void SetupTest()
{
selenium = new DefaultSelenium("localhost", , "*chrome", "https://www.google.com.hk/");
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 TheReTest()
{
selenium.Open("/");
selenium.Type("id=lst-ib", "SELENIUM");
}
}
}
2.3.2 使用selenium 2(selenium 1+webdriver)
原理:利用浏览器native support来操作浏览器,因为firefox有浏览器原生组件webdriver.xpi,故不需要像IE,Chrome需要使用其他命令为浏览器native的调用
FirefoxDriver初始化成功之后,默认会从http://localhost:7055开始,而ChromeDriver则大概是http://localhost:46350

需要在vs references 引进相应的.dll(如果你建的solution为unitTest,需要应用nunit.framework.dll)

主要代码:
using System;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.Support.UI; namespace SeleniumTests
{
[TestFixture]
public class Wb
{
private IWebDriver driver;
private StringBuilder verificationErrors;
private string baseURL;
private bool acceptNextAlert = true; [SetUp]
public void SetupTest()
{
driver = new FirefoxDriver();
baseURL = "https://www.google.com.hk/";
verificationErrors = new StringBuilder();
} [TearDown]
public void TeardownTest()
{
try
{
driver.Quit();
}
catch (Exception)
{
// Ignore errors if unable to close the browser
}
Assert.AreEqual("", verificationErrors.ToString());
} [Test]
public void TheWbTest()
{
driver.Navigate().GoToUrl(baseURL + "/");
driver.FindElement(By.Id("lst-ib")).Clear();
driver.FindElement(By.Id("lst-ib")).SendKeys("SELENIUM");
}
private bool IsElementPresent(By by)
{
try
{
driver.FindElement(by);
return true;
}
catch (NoSuchElementException)
{
return false;
}
} private bool IsAlertPresent()
{
try
{
driver.SwitchTo().Alert();
return true;
}
catch (NoAlertPresentException)
{
return false;
}
} private string CloseAlertAndGetItsText() {
try {
IAlert alert = driver.SwitchTo().Alert();
string alertText = alert.Text;
if (acceptNextAlert) {
alert.Accept();
} else {
alert.Dismiss();
}
return alertText;
} finally {
acceptNextAlert = true;
}
}
}
}
可以说selenium自动化的基本脚本就完成了,可以run进行调试了,方法有:nunit/resharper
selenium IDE & Remote Control & Webdriver的更多相关文章
- 使用Selenium IDE和webDriver进行自动化软件测试
1.Selenium IDE 在Chrome浏览器上登录谷歌应用商店可以安装Selenium IDE插件(3.0以上版本的Selenium IDE不支持录制的脚本导出,所以这里使用到的是应用商店上的另 ...
- [Training Video - 1] [Selenium Basics] [What is Selenium IDE,RC,Webdriver, TestNG, Junit And Ant]
Selenium IDE (Only support in Firefox): - Record and Run - UI interface - User extensions - Conversi ...
- 基于webdriver的jmeter性能测试-Selenium IDE
前言: 由于某些项目使用了WebGL技术,需要高版本的Firefox和Chrome浏览器才能支持浏览,兼容性很弱,导致Loadrunner和jmeter(badboy)无法正常进行录制脚本.因此我们采 ...
- 自动化测试模型 Selenium IDE Selenium Gird2
1.线性测试 每个测试脚本相对独立,且不产生其他依赖与调用,其实就是单纯的来模拟用户完整的 操作场景.前一篇所写的测试脚本就属于线性测试. 优点:每个脚本完整且独立 缺点:测试用例的开发与维护成本高 ...
- 【Selenium】3.介绍Selenium IDE
本文供学习交流之用,没有商业用途,没有盈利. 完全是我自己为督促自己学习而翻译的.翻译的不好,见谅.来源于:http://www.guru99.com/introduction-selenuim-id ...
- Selenium IDE 工具总结
基本介绍: Selenium工具专门为WEB应用程序编写的一个验收测试工具. Selenium的核心:browser bot,是用JavaScript编写的. Selenium工具有4种:Seleni ...
- 自动化测试辅助工具(Selenium IDE等)
本随表目录 Selenium IDE安装和使用 FireBug安装和使用 FirePath安装和使用 Selenium IDE安装 方式一:打开Firefox-->添加组件-->搜索出 ...
- Selenium IDE 3.6 命令Command详解
学以致用,个人觉得要学老外的东西,最好的方法就是自己翻译一遍.因此准备把SIDE官网的一些文档,按工作所需做些翻译整理.本文是命令这一块的提纲,未全部完成,占坑中. Selenium IDE中的命令其 ...
- 开源Web自动化测试工具Selenium IDE
Selenium IDE(也有简写SIDE的)是一款开源的Web自动化测试工具,它实现了测试用例的录制与回放. Selenium IDE目前版本为 3.6 系列,支持跨浏览器运行,所以IDE的UI从原 ...
随机推荐
- C# - Lambda 表达式
Lambda 表达式分为三个部分: 1 参数定义部分.参数是未类型化的,因此编译器可以根据上下文推断出他们的类型. 2 =>运算符,把Lambda表达式的参数与表达式体分开. 3 表达式体. d ...
- [SQL SERVER系列]之嵌套子查询和相关子查询
子查询有两种类型,一种是只返回一个单值的子查询,这时它可以用在一个单值可以使用的地方,这时子查询可以看作是一个拥有返回值的函数:另外一种是返回一列值的子查询,这时子查询可以看作是一个在内存中临时存在的 ...
- SC命令详解
我们知道在MStools SDK,也就是在Resource Kit有一个很少有人知道的命令行软件,SC.exe,这个软件向所有的Windows NT和Windows 2000要求控制他们的API函数. ...
- c++ 读写锁
#ifndef THREAD_UTIL_H #define THREAD_UTIL_H #include <pthread.h> namespace spider { class Auto ...
- js注册登录审核
<script type="text/javascript"> $(function(){ $("#sendSms").click(function ...
- Chp3: Stacks and Queue
1. 说明如何用两个队列来实现一个栈,并分析有关栈操作的运行时间. 解法:1.有两个队列q1和q2,先往q1内插入a,b,c,这做的都是栈的push操作.2.现在要做pop操作,即要得到c,这时可以将 ...
- nginx如何解决超长请求串
nginx是一个强大的http服务器,但是在使用过程中发现,当遇到超长的post请求或者get请求时,nginx会返回413.400.414等状态码,这是因为请求串长度超过了nginx默认的缓存大小或 ...
- 微软在 .NET 3.5 新增了一个 HashSet 类,在 .NET 4 新增了一个 SortedSet 类,本文介绍他们的特性,并比较他们的异同。
微软在 .NET 3.5 新增了一个 HashSet 类,在 .NET 4 新增了一个 SortedSet 类,本文介绍他们的特性,并比较他们的异同. .NET Collection 函数库的 Has ...
- iOS顶部滑动菜单:FDSlideBar 与NinaPagerView
FDSlideBar 是一个顶部滑动菜单,如常见的网易.腾讯新闻等样式.该控件支持自定颜色.字体等多种样式风格.菜单间切换流畅,具有较好的体验性.下部的内容展示经过挣 扎,最后选择了 UITableV ...
- JavaScript 获取客户端计算机硬件及系统信息
1.浏览器信息 //浏览器信息 function BrowserInfo() { var userLanguage = navigator.userLanguage; // 用户在自己的操作系 ...