selenium-RC压缩包 v1.0.3 官方版
- 软件大小:20.00MB (20,971,520 字节)
- 软件类别:编程书集 -> 编程控件
- 软件授权:免费软件 软件语言:简体中文
- 更新时间:2020/06/03
- 软件厂商:
- 软件官网:
- 应用平台:
selenium rc : rc是remote control的缩写,这种方式是使用具体的语言来编写测试 类,然后进行测试,它的功能就是用来模拟一个浏览器,主要测试的就是web方面的东西。它支持的语言非常多,C#,Java都行,看网上好多例子都是Java的。这个东西好像一个库文件一样,自己编程调用的。
SeleniumRC就是使用程式语言编写脚本,通过Selenium RC服务器作为代理服务器去访问应用从而达到测试的目的.由于Selenium RC不再需要依附Firefox,所以其可以在其它更多的浏览器上进行测试,而这也是我们做WEB测试的一个比较重要的问题(解决了因为担心浏览器兼容问题而重要做测试的问题). RC的脚本由于是程序语言编写,所以更为灵活强大.并且它支持的语言极为丰富.所以RC是Selenium测试工具中的应用最广的.同时,它对测试人员编程水平要求也较高.
Selenium 的版本
Selenium 现在存在2个版本,一个叫 selenium-core, 一个叫selenium-rc 。
selenium-core 是使用HTML的方式来编写测试脚本,你也可以使用 Selenium-IDE来录制脚本,但是目前Selenium-IDE只有 FireFox 版本。
Selenium-RC 是 selenium-remote control 缩写,是使用具体的语言来编写测试类。
selenium-rc 支持的语言非常多,这里我们着重关注java的方式。这里讲的也主要是 selenium-rc,因为个人还是喜欢这种方式 :-)
windows下安装selenium-RC
1.安装
解压后,打开cmd。
Selenium Server 是用Java语言编写的,需要在JRE 1.5.0或者更高的版本下运行。
检查是否安装了JRE,操作如下: 在命令行中执行:
java –version
可以看到如下的关于你安装的java的版本信息:
C:\Documents and Settings\Administrator>java -version
java version "1.6.0_15"
Java(TM) SE Runtime Environment (build 1.6.0_15-b03)
Java HotSpot(TM) Client VM (build 14.1-b02, mixed mode, sharing)
相反,如果看到的是错误信息,则需要安装JRE,或者是将它填加到PATH环境变量中去。
selenium-remote-control-1.0.3.rar解压出来selenium-remote-control-1.0.3
把里面的:selenium-server-1.0.3
把他放在:
开始-运行cmd,切换到selenium-server.jar所在的目录下 执行命令:java -jar selenium-server.jar 启动成功。
selenium安装完成。
selenium-rc 一些使用方法
在 selenium-remote-control-0.9.0/server 目录里,我们运行 java -jar selenium-server.jar之后你就会看到一些启动信息。要使用 selenium-rc ,启动这个server 是必须的。
当然,启动的时候有许多参数,这些用法可以在网站里看看教程,不过不加参数也已经足够了。
selenium server 启动完毕了,那么我们就可以开始编写测试类了!
我们先有个概念,selenium 是模仿浏览器的行为的,当你运行测试类的时候,你就会发现selenium 会打开一个
浏览器,然后浏览器执行你的操作。
usingSystem;usingSystem.Text;usingNUnit.Framework;usingSelenium;namespaceSeleniumTests{[TestFixture]publicclassUntitled{privateISeleniumselenium;privateStringBuilderverificationErrors;[SetUp]publicvoidSetupTest(){selenium=newDefaultSelenium("localhost",4444,"*chrome","http://localhost:16447/News.aspx");selenium.Start();verificationErrors=newStringBuilder();}[TearDown]publicvoidTeardownTest(){try{selenium.Stop();}catch(Exception){//Ignoreerrorsifunabletoclosethebrowser}Assert.AreEqual("",verificationErrors.ToString());}[Test]publicvoidTheUntitledTest(){selenium.Open("/News.aspx");try{Assert.IsTrue(selenium.IsTextPresent("悼模友“王自武”不飞"));}catch(AssertionExceptione){verificationErrors.Append(e.Message);}selenium.Click("link=悼模友“王自武”不飞");}}}
代码十分简单,作用就是初始化一个 Selenium 对象。其中:url : 就是你要测试的网站localhost: 可以不是localhost,但是必须是 selenium server 启动的地址*iexplore 或者*chrome (IE或者火狐浏览器): 可以是其它浏览器类型,可以在网站上看都支持哪些。
下面我就要讲讲怎么使用selenium 这个对象来进行测试。
1、测试文本输入框
假设页面上有一个文本输入框,我们要测试的内容是 在其中输入一些内容,然后点击一个按钮,看看页面的是否跳转到需要的页面。
[Test]publicvoidCnblogTest(){selenium=newDefaultSelenium("localhost",4444,"*chrome","http://passport.cnblogs.com/register.aspx");selenium.Start();selenium.Open("http://passport.cnblogs.com/register.aspx");selenium.Type("xpath=//input[@id='ctl00_holderLeft_txt_userName']","dupeng0811");//selenium.WaitForPageToLoad("2000");Assert.AreEqual(selenium.GetValue("xpath=//input[@id='ctl00_holderLeft_txt_userName']"),"dupeng0812");selenium.Stop();}
代码解释:1、调用 selenium.open 方法,浏览器会打开相应的页面2、使用 type 方法来给输入框输入文字3、等待页面载入-selenium.WaitForPageToLoad("2000");4、看看页面中的文本框中填入的是不是我们输入的内容呢?
将Assert.AreEqual(selenium.GetValue("xpath=//input[@id='ctl00_holderLeft_txt_userName']"),"dupeng0812");
更改后
2、测试下拉框
[Test]publicvoidSelectTest(){selenium=newDefaultSelenium("localhost",4444,"*chrome","http://www.webkey.cn/demo/docs/index2.asp?url=/demo/docs/menuselect/");selenium.Start();selenium.Open("http://www.webkey.cn/demo/docs/index2.asp?url=/demo/docs/menuselect/");selenium.Select("xpath=//select[@id='city']","index=2");Assert.AreEqual(selenium.GetSelectedIndex("xpath=//select[@id='city']"),"2");}
代码注释:
1、使用selenium.Select("xpath=//select[@id='city']","index=2"); 来寻找页面中的下拉框。
2、使用selenium.GetSelectedIndex("xpath=//select[@id='city']"),"2")来获取下拉框的内容。
可以看到,我们可以使用 select 方法来确定选择下拉框中的哪个选项。
3、测试check box
[Test]publicvoidCheckBoxTest(){selenium=newDefaultSelenium("localhost",4444,"*chrome","http://passport.cnblogs.com/register.aspx");selenium.Start();selenium.Open("http://passport.cnblogs.com/register.aspx");selenium.Check("xpath=//input[@id='ctl00_holderLeft_cblPosition_2']");}
代码注释:
1、使用selenium.Check来寻找checkBox
2、xpath下还是使用=//input
4、判断页面是否存在一个元素
[Test]publicvoidisExistElementTest(){selenium=newDefaultSelenium("localhost",4444,"*chrome","http://passport.cnblogs.com/register.aspx");selenium.Start();selenium.Open("http://passport.cnblogs.com/register.aspx");Assert.AreEqual(selenium.IsElementPresent("xpath=//input[@id='ctl00_holderLeft_cblPosition_2']"),true);}
代码注释:
1、使用selenium.IsElementPresent来判断是否存在该元素。
selenium 还有更多的用法,例如弹出页面等等。当面对没见过的测试要求时,我最笨的方法就是按照api文档一个一个找,好在不多,肯定能找到。
启动Selenium测试服务器
打开cmd进入selenium-server-1.0-beta-2目录,输入“java -jar selenium-server.jar”(需要先安装JRE),启动Selenium测试服务器。
运行测试案例(1).运行测试案例:
(2).测试结果:
恩,案例Pass了,如果案例失败的话,Error Meesage会说明失败的原因。(注意:和Firefox一样,IE下也有屏蔽弹出网页功能,修改设置方法:MenuBar->Tools->Popup Blocker->Turn off Popup Blocker,或者在Popup Blocker Settings里面配置。)