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从原 ...
随机推荐
- 淘宝自己的前端框架KISSY(类似jquery) - 简易指南
KISSY 是由阿里集团前端工程师们发起创建的一个开源 JS 框架. 具备模块化.高扩展性.组件齐全,接口一致.自主开发.适合多种应用场景等特性. 在以下方面具有一定优势: A.拥有大量的中文文档: ...
- 使用 Android Studio 跑新浪微博SDK Demo遇到的问题及解决
概述 这是新浪微博官方 Android SDK Demo 使用 Android Studio 导入.编译并运行通过的版本. 源码:WeiboSdkDemo 官方项目请点击: weibo_android ...
- poj 2060 Taxi Cab Scheme (最小路径覆盖)
http://poj.org/problem?id=2060 Taxi Cab Scheme Time Limit: 1000MS Memory Limit: 30000K Total Submi ...
- [转载].Net中如何操作IIS(源代码)
///***********************************************************///************** IIS控制管理类 1.0 Beta ** ...
- UnitOfWork机制的实现和注意事项
UnitOfWork机制 /*一点牢骚: * UnitOfWork机制的蛋疼之处: * UnitOfWork机制,决定了插入新的实体前,要预先设置数据库中的主键Id,尽管数据库自己生产主键. * ...
- ECSHOP报错误Deprecated: preg_replace(): The /e modifier is depr
http://www.ecshoptemplate.com/article-1850.html
- CSU1326+背包+并查集
先预处理出有多少个任务即可 #include<stdio.h> #include<stdlib.h> #include<string.h> #include< ...
- codeforces #305 B Mike and Feet
跟之前做过的51Nod的移数博弈是一样的QAQ 我们考虑每个数的贡献 定义其左边第一个比他小的数的位置为L 定义其右边第一个比他小的数的位置为R 这个可以用排序+链表 或者 单调队列 搞定 那么对于区 ...
- [mock]12月28日
假设我们有一个全局升序数组,这个数组长度unlimited现在我们有一个全局的指针和一个目标target值,target和指针你不可见.但是有以下几个操作bool istag();void gorig ...
- 107. Binary Tree Level Order Traversal II
题目: Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from ...