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从原 ...
随机推荐
- nginx流量带宽等请求状态统计( ngx_req_status)
介绍 ngx_req_status用来展示nginx请求状态信息,类似于apache的status,nginx自带的模块只能显示连接数等等信息,我们并不能知道到底有哪些请求.以及各url域名所消耗的带 ...
- AirDrop显示名字的修改问题
AirDrop的名字来源是设备登陆的iCloud账户 打开iCloud设置 把个人信息的名字改成自己的即可 前提是你的账号没有借朋友用过,如果朋友用过恰好没注销,你的通讯录又有你的朋友的号码,很有可能 ...
- 自定义Angular指令与jQuery实现的Bootstrap风格数据双向绑定的单选&多选下拉框
先说点闲话,熟悉Angular的猿们会喜欢这个插件的. 00.本末倒置 不得不承认我是一个喜欢本末倒置的人,学生时代就喜欢先把晚交的作业先做,留着马上就要交的作业不做,然后慢悠悠做完不重要的作业,卧槽 ...
- The 5th Zhejiang Provincial Collegiate Programming Contest---ProblemG:Give Me the Number
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2971 题意:将输入的英文数字表达转化为阿拉伯数字. #include< ...
- SQL Server 2008 设计与实现笔记(一)
Chart5 create database MovieRental; select name, SUSER_SNAME(sid) as [login] from sys.database_princ ...
- jquery 清空动态append添加元素,remove方法
<html> <head> <script type="text/javascript" src="jquery-1.9.1.js" ...
- linux下执行 ls,cat等一些命令报出 -bash: /bin/cat: Cannot allocate memory 有没解决的方法
环境变量配置出错了cd -- 进入用户目录vim .bash_profile删除以前PATH这一行,把下面的粘帖进去PATH=$PATH:$HOME/bin:/root:/root/snapshot/ ...
- c#做动态(gif)中文验证码
无意中在国外论坛发现一个gif动画类,我使用它来制作了一个动态验证码 : 一:首先新建一个类库 1:新建AnimatedGifEncoder类 using System; using System.C ...
- codeforces #310 div1 C
操作无论是U还是L,都会使原图形分裂成两个图形,且两个图形的操作互不影响 我们又发现由于操作点只可能在下斜线上,如果将操作按x排序 那么无论是U还是L,都会将操作序列完整分割成两半,且两个操作序列互不 ...
- 首次接触Winform前端交互
首次接触到在winform中加入网页,且跟前端脚本交互.找了一下这方面的资料 此博文转载原地址为:http://www.cnblogs.com/Charles2008/archive/2009/08/ ...