一直忘记写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的更多相关文章

  1. 使用Selenium IDE和webDriver进行自动化软件测试

    1.Selenium IDE 在Chrome浏览器上登录谷歌应用商店可以安装Selenium IDE插件(3.0以上版本的Selenium IDE不支持录制的脚本导出,所以这里使用到的是应用商店上的另 ...

  2. [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 ...

  3. 基于webdriver的jmeter性能测试-Selenium IDE

    前言: 由于某些项目使用了WebGL技术,需要高版本的Firefox和Chrome浏览器才能支持浏览,兼容性很弱,导致Loadrunner和jmeter(badboy)无法正常进行录制脚本.因此我们采 ...

  4. 自动化测试模型 Selenium IDE Selenium Gird2

    1.线性测试 每个测试脚本相对独立,且不产生其他依赖与调用,其实就是单纯的来模拟用户完整的 操作场景.前一篇所写的测试脚本就属于线性测试. 优点:每个脚本完整且独立 缺点:测试用例的开发与维护成本高 ...

  5. 【Selenium】3.介绍Selenium IDE

    本文供学习交流之用,没有商业用途,没有盈利. 完全是我自己为督促自己学习而翻译的.翻译的不好,见谅.来源于:http://www.guru99.com/introduction-selenuim-id ...

  6. Selenium IDE 工具总结

    基本介绍: Selenium工具专门为WEB应用程序编写的一个验收测试工具. Selenium的核心:browser bot,是用JavaScript编写的. Selenium工具有4种:Seleni ...

  7. 自动化测试辅助工具(Selenium IDE等)

    本随表目录 Selenium IDE安装和使用 FireBug安装和使用 FirePath安装和使用   Selenium IDE安装 方式一:打开Firefox-->添加组件-->搜索出 ...

  8. Selenium IDE 3.6 命令Command详解

    学以致用,个人觉得要学老外的东西,最好的方法就是自己翻译一遍.因此准备把SIDE官网的一些文档,按工作所需做些翻译整理.本文是命令这一块的提纲,未全部完成,占坑中. Selenium IDE中的命令其 ...

  9. 开源Web自动化测试工具Selenium IDE

    Selenium IDE(也有简写SIDE的)是一款开源的Web自动化测试工具,它实现了测试用例的录制与回放. Selenium IDE目前版本为 3.6 系列,支持跨浏览器运行,所以IDE的UI从原 ...

随机推荐

  1. 第一个js库文件

    <!DOCTYPE html> <html xmlns=;         ;                     }                 };     })(); ...

  2. 应该如何入门deep learning呢?从UFLDL开始!

    抱歉,大家,这里不是要分享如何学习deep learning,而是想要记录自己学习deep learning的小历程,算是给自己的一点小动力吧,希望各位业内前辈能够多多指教! 看到有网友提到,Andr ...

  3. JS日期格式化(网上转载)

    JS日期格式化(网上转载) <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <ht ...

  4. Delphi逆向

    Delphi反汇编内部字符串处理函数/过程不完全列表 名称 参数 返回值 作用 等价形式 / 备注 _PStrCat EAX :目标字符串 EDX :源字符串 EAX 连接两个 Pascal 字符串 ...

  5. jquery图片放大器插件

    将鼠标移动到一张图片上来的时候,放大该图片的某些细节. <html> <head> <script src="../js/jquery-1.6.js" ...

  6. A JSTL primer, Part 2: Getting down to the core

    In the initial article of this series, you got your first look at JSTL. We described the use of its  ...

  7. 学点PYTHON基础的东东--数据结构,算法,设计模式---单向链表

    看来看来,还是以下这个实现最优雅.. 其它的,要么NODE冗余,要么初始化丑陋... #!/usr/bin/env python # -*- coding: utf-8 -*- class Node: ...

  8. 使用session技术来实现网上商城购物车的功能

    首先.简单的了解session和cookie的区别: 一.session和cookie的区别: session是把用户的首写到用户独占的session中(服务器端) cookie是把用户的数据写给用户 ...

  9. mpi冒泡排序并行化

    一.实验目的与实验要求 1.实验目的 (1)学会将串行程序改为并行程序. (2)学会mpich2的使用. (3)学会openmp的配置. (4)mpi与openmp之间的比较. 2.实验要求 (1)将 ...

  10. 转:Build Your First JavaScript Library

    http://net.tutsplus.com/tutorials/javascript-ajax/build-your-first-javascript-library/ Step 1: Creat ...