配置selenium rc for HTTPS测试

上一篇 / 下一篇  2012-03-26 15:14:16 / 个人分类:Selenium

配置selenium rc for HTTPS测试
51Testing软件测试网!t,d`!Xj-U
selenium is an automation tool, you can get it form. here: seleium.openqa.org

9d3Qsb G8n a0用selenium测试HTTPS比较麻烦,搞了三天才将基本的东西设置好
1。选择工具
(y~#_G7[Lz;I1Z0selenium有好几种,首先需要确定的是哪种工具适合
* selenium IDE: 是一个firefox的plug-in,这个基本上对任何测试都有用,主要是因为可以省下大量的手写测试的时间。根据我的经验,最新的版本(1.0 beta)在RHEL 5.0上不能用,所以我用的是0.87版本。
g7v2{[{0在这里下载:http://selenium-ide.openqa.org/download.jsp不过它只能在firefox上用
51Testing软件测试网fp8K$W/jqr
* selenium rc : 这个是用来遥控的。(rc = remote controller)如果你需要在一台电脑上控制其它几台电脑进行测试,我用的就是这个。不过我用它的主要原因是它支持比较多的脚本语言(perl,python。。。)写自动测试程序比较容易

{p8L+nh#PZyj0* selenium core : 只能支持Selenese语言(a simple scrīpting language. Selenese has a number of strict limitations: it has no conditionals (no "if" statements), and it has no loops (no "for" statements). This can make writing complicated tests difficult or even impossible.)如果需要知道比较具体的区别的话,还是看它们自己的文件:http://wiki.openqa.org/pages/viewpage.action?pageId=7632
51Testing软件测试网#G1Y l.JQ[hb/N
2。配置
I0w7eUSN}0配置有很多步骤和方面,首先需要了解的是selenium rc的工作流程
图片看起来好像复杂,但是实际上我们可以将所有的部件放到一台机器上。我们需要了解的是它的工作流程。
/u/na Z$bU3IX0selenium包含三个部件:
y l4F-cD0测试程序(testing scrīpt)51Testing软件测试网'D1W*X1qg\r-o
selenium rc (selenium server)51Testing软件测试网/t,u5ZfB;v-Q,^ Y JG
browser (firefox, in my case)
Z Cc,Pr]h!e0他们之间的关系如下
er+}:?C*a3RXA0testing scrīpt <=>selenium server <=> browser
M GA;r"bp#lg!\#P0(1)测试程序将HTTP/HTTPS请求发给selenium server
/I7[(N'd J0(2)selenium server将请求转发(also called proxing)给browser,51Testing软件测试网%p}3@p2IZ|C
(3)browser 执行请求,得到执行结果,然后回复给selenium server51Testing软件测试网v1S pX GYP/L
(4)selenium server 将回复转发给测试程序*51Testing软件测试网1h&p.ZhoQ
(5)测试程序检验测试结果,记录之,然后执行下一个测试
/C6y.O7c~H @8g\0这个过程中,selenium server和browser必须要在同一台机器上,但是测试程序可以随意。我的配置是三者都在同一台机器上。
测试环境配置 (testing environment configuration)
^9\]y&` p Nb8F(sX0* perl  (我使用的是perl) 51Testing软件测试网/\6e3tcI&i)I'}%r
  用perl写selenium的测试程序需要首先安装必要的module:  Test::WWW::Selenium  51Testing软件测试网UT0i%A7~ G^m
  我的安装方式如下: 51Testing软件测试网4KR]W\
  $> yum install perl.CPAN.386   
N0K+l ^l9d;O0      -- yum 是linux里面的程序包安装程序 51Testing软件测试网Y4W/PN${?
  $> perl -MCPAN -e "install Test::WWW::Selenium"  
n8]~E3T%Jk9N)Az{n0      --安装Selenium会同时要求你同时安装一些其它的module,比如Test::Mock Test::MockObject Test::More Test::Exception Test::Mock:LWP Test::Pod. 如果你的CPAN配置好了的话,这些安装都是自动的,安装过程中如果有提问,直接回车就好,一般不会有太多问题   (如果需要重新配置perl CPAN,比如说我
mL1d R/}!zm6K0   $> perl -MCPAN -e "shell\"  
d-] ? Yi&OT0   CPAN> o conf init
* JAVA51Testing软件测试网~9[QnV }jSX)BR
  Selenium server 是用Java写的,所以你需要有JAVA。我开始用的是IBM JAVA 1.5后来才发现不行,就转到了SUN的JRE1.6
* Selenium Core : 在selenium rc 的网站上说需要 selenium core,但是我的经验是不必管它
* Selenium Server:  51Testing软件测试网!R&Y8?{yc2{
** 下载: Selenium 1.0 Major release  
:b3FJZxe0** unzip selenium-remote-control-1.0-beta-1-dist.zip 51Testing软件测试网!a+tu\K
** 到这里其实就可以了,但是让程序跑起来,这里需要一个额外的配置: 将firefox-bin放到系统路径里面去
u3b)C!X!ytf0   $> export PATH=$PATH:/usr/lib/firefox-1.5.0.9*

Pk[$MpY0* HTTPS 51Testing软件测试网v_6d$|dL}{
前面的都很简单。如果你不需要测试HTTPS,那么前面的配置就足够了。但是要让selenium server用HTTPS,还需要将一个专门用于测试的cert放到firefox里面去。步骤如下: 
Q^:LD+ZO%A"_9U)bk0** open firefox 
;RDo3Y5b"[T!u0** import certificates:  51Testing软件测试网[sS&VTi
*** go to "Edit->Preference"
m/we}W,x6Y0   -> open "Advanced" tab51Testing软件测试网qSs-uIpV
   -> click "Security" (or "Encryption" )  
_ef~Qvw(C bg0   -> click "view certificates", a new window will open,  51Testing软件测试网f r:h1HaaZ
   -> then select "Web Sites" tab 
I x;zy5cmw1x0   -> then click "import"(图片如下)
 
 
3。最后一步,就是怎么让程序跑起来。这里有三个问题需要注意:
:Quq rM8x.Pi d01> selenium rc beta 1。0 的SSL cert已经过期了(4/18/2008),所以我们需要将我们的系统时间改回到过期之前。
P8Z(kX C@k0$> date 041800002007
$fxn_#D"n3@L02> 需要用让selenium server使用刚刚设定好的firefox profile51Testing软件测试网)fO:Ag{
3> 需要设置一个特定的参数(trustAllCertificates),让所有的SSL请求能够顺利通达。[这条在selenium正式的网站上没有写出来,是通过看源程序找到的]

g:fk \b w0我的命令如下:
 
让selenium server跑起来:
mI&_-?,[#]0java -jar ~/server/selenium-server.jar \51Testing软件测试网F*I;@zRHh DU
     -log /tmp/selenium.log \51Testing软件测试网[Y$H_ NF8L[
     -trustAllSSLCertificates \
$x)i"\oHV P1b0     -multiWindow \
(D }A`6{{:u0     -firefoxProfileTemplate /opt/ipatest.profile
 
15:52:10.698 INFO - Writing debug logs to /tmp/selenium.log
MyH4~HTQ015:52:10.699 INFO - Java: Sun Microsystems Inc. 10.0-b1951Testing软件测试网/O-Fww*}S ^
15:52:10.699 INFO - OS: Linux 2.6.18-8.el5 i386
&u-Y$dg;jG5|015:52:10.702 INFO - v1.0-beta-1 [2201], with Core v1.0-beta-1 [1994]51Testing软件测试网s/WJ4yBj
15:52:10.758 INFO - Version Jetty/5.1.x
+` ^q4[V)m.`xs-v015:52:10.760 INFO - Started HttpContext[/selenium-server/driver,/selenium-server/driver]51Testing软件测试网7_0C{7b!|i"{NC!g&c
15:52:10.762 INFO - Started HttpContext[/selenium-server,/selenium-server]51Testing软件测试网9XM i%B R,Z'^
15:52:10.763 INFO - Started HttpContext[/,/]51Testing软件测试网:N _spMJ@
15:52:10.772 INFO - Started SocketListener on 0.0.0.0:4444
8{-fFW8H015:52:10.773 INFO - Startedorg.mortbay.jetty.Server@5ac072
让测试程序跑起来:51Testing软件测试网 bBrr(ZI9B)K9S7k
perl test.pl
51Testing软件测试网;}]L:g0J]5O
我的test.pl 程序开头部分如下:
{bRx0d1Y0----------------------------
2@j'I^&s*ES5}[0#!/usr/bin/perl
51Testing软件测试网nv6j%~7ik
use strict;
F#WU ])tWAP:S0use warnings;51Testing软件测试网+g(h_0Sf0y0TB2T
use Time::HiRes qw(sleep);
A"B(^6E!`slt0use Test::WWW::Selenium;51Testing软件测试网.Y p5ui4F
use Test::More "no_plan";51Testing软件测试网 t2O2LS:X
use Test::Exception;
my $sel = Test::WWW::Selenium->new( host => "localhost",51Testing软件测试网Z o2s-` k\^cU-G
                                    port => 4444,
]L&r F#qP6?!Y%M8uT5G0                                    browser => "*firefox",51Testing软件测试网-aW5a7@L4t7f%L
                                    browser_url => "https://some.com");
 
$sel->open_ok("/testpage");
#{ZizxZ A[O0$sel->click_ok("link=Add User");
Pj0`;p3wZ)TXK4]:X0$sel->wait_for_page_to_load_ok("30000");
5[0[$}bAb2g!V Q-mX0$sel->type_ok("form_title", "auto001");
i?Sa-\s(g]7H#U0$sel->type_ok("form_givenname", "selenium");51Testing软件测试网A3dt'Ge3b:X%J
$sel->type_ok("form_sn", "001");
_^)Vy'\2J0$sel->type_ok("form_krbprincipalkey", "redhat123");51Testing软件测试网kjU8JPz-E'}D
$sel->type_ok("form_krbprincipalkey_confirm", "redhat123");51Testing软件测试网iVf7[ jy2q!D
$sel->click_ok("document.form.submit[1]");
^-V#j9^ Gy%T0$sel->wait_for_page_to_load_ok("30000");51Testing软件测试网.Oy j4zj*y6ue%Z&hK.Q
$sel->is_text_present_ok("s001 added!");51Testing软件测试网!Z_@x#Y i
$sel->click_ok("link=Find Users");
0[-F3AJs-YYsfw?0$sel->wait_for_page_to_load_ok("30000");
nJv!SQ1W0$sel->type_ok("uid", "s101");
A8m"j^LrDh IQ0$sel->click_ok("//input[\@value='Find Users']");
-cZk/s_0$sel->wait_for_page_to_load_ok("30000");
f}3DNkk`0$sel->type_ok("uid", "s001");
---------------------------51Testing软件测试网QC4`srMS
我其实没有写什么东西,上面的程序都是selenium IDE自动录的。

^K8P;je^ Lx0 

TAG:

 

评分:0

我来说两句

Open Toolbar