配置selenium rc for HTTPS測試

發表于:2008-07-23來源:作者:點擊數: 標簽:seleniumSeleniumHTTPS
配置selenium rc for HTTPS測試 selenium is an automation tool, you can get it form here: seleium.openqa.org 用selenium測試HTTPS比較麻煩,搞了三天才將基本的東西設置好 1。選擇工具 selenium有好幾種,首先需要確定的是哪種工具適合 * selenium IDE:


配置selenium rc for HTTPS測試


selenium is an automation tool, you can get it form here: seleium.openqa.org

用selenium測試HTTPS比較麻煩,搞了三天才將基本的東西設置好

1。選擇工具
selenium有好幾種,首先需要確定的是哪種工具適合

* selenium IDE: 是一個firefox的plug-in,這個基本上對任何測試都有用,主要是因為可以省下大量的手寫測試的時間。根據我的經驗,最新的版本(1.0 beta)在RHEL 5.0上不能用,所以我用的是0.87版本。
在這里下載http://selenium-ide.openqa.org/download.jsp不過它只能在firefox上用

* selenium rc : 這個是用來遙控的。(rc = remote controller)如果你需要在一臺電腦上控制其它幾臺電腦進行測試,我用的就是這個。不過我用它的主要原因是它支持比較多的腳本語言(perl,python。。。)寫自動測試程序比較容易

* 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

2。配置
配置有很多步驟和方面,首先需要了解的是selenium rc的工作流程

圖片看起來好像復雜,但是實際上我們可以將所有的部件放到一臺機器上。我們需要了解的是它的工作流程。
selenium包含三個部件:
測試程序(testing scrīpt)
selenium rc (selenium server)
browser (firefox, in my case)
他們之間的關系如下
testing scrīpt <=>selenium server <=> browser
(1)測試程序將HTTP/HTTPS請求發給selenium server
(2)selenium server將請求轉發(also called proxing)給browser,
(3)browser 執行請求,得到執行結果,然后回復給selenium server
(4)selenium server 將回復轉發給測試程序*
(5)測試程序檢驗測試結果,記錄之,然后執行下一個測試
這個過程中,selenium server和browser必須要在同一臺機器上,但是測試程序可以隨意。我的配置是三者都在同一臺機器上。

測試環境配置 (testing environment configuration)
* perl  (我使用的是perl) 
  用perl寫selenium的測試程序需要首先安裝必要的module:  Test::WWW::Selenium  
  我的安裝方式如下: 
  $> yum install perl.CPAN.386   
      -- yum 是linux里面的程序包安裝程序 
  $> perl -MCPAN -e "install Test::WWW::Selenium"  
      --安裝Selenium會同時要求你同時安裝一些其它的module,比如Test::Mock Test::MockObject Test::More Test::Exception Test::Mock:LWP Test::Pod. 如果你的CPAN配置好了的話,這些安裝都是自動的,安裝過程中如果有提問,直接回車就好,一般不會有太多問題   (如果需要重新配置perl CPAN,比如說我
   $> perl -MCPAN -e "shell\"  
   CPAN> o conf init

* JAVA
  Selenium server 是用Java寫的,所以你需要有JAVA。我開始用的是IBM JAVA 1.5后來才發現不行,就轉到了SUN的JRE1.6

* Selenium Core : 在selenium rc 的網站上說需要 selenium core,但是我的經驗是不必管它

* Selenium Server:  
** 下載: Selenium 1.0 Major release  
** unzip selenium-remote-control-1.0-beta-1-dist.zip 
** 到這里其實就可以了,但是讓程序跑起來,這里需要一個額外的配置: 將firefox-bin放到系統路徑里面去
   $> export PATH=$PATH:/usr/lib/firefox-1.5.0.9*

* HTTPS 
前面的都很簡單。如果你不需要測試HTTPS,那么前面的配置就足夠了。但是要讓selenium server用HTTPS,還需要將一個專門用于測試的cert放到firefox里面去。步驟如下: 
** open firefox 
** import certificates:  
*** go to "Edit->Preference"
   -> open "Advanced" tab
   -> click "Security" (or "Encryption" )  
   -> click "view certificates", a new window will open,  
   -> then select "Web Sites" tab 
   -> then click "import"(圖片如下)

 

3。最后一步,就是怎么讓程序跑起來。這里有三個問題需要注意:
1> selenium rc beta 1。0 的SSL cert已經過期了(4/18/2008),所以我們需要將我們的系統時間改回到過期之前。
$> date 041800002007
2> 需要用讓selenium server使用剛剛設定好的firefox profile
3> 需要設置一個特定的參數(trustAllCertificates),讓所有的SSL請求能夠順利通達。[這條在selenium正式的網站上沒有寫出來,是通過看源程序找到的]


我的命令如下:

讓selenium server跑起來:
java -jar ~/server/selenium-server.jar \
     -log /tmp/selenium.log \
     -trustAllSSLCertificates \
     -multiWindow \
     -firefoxProfileTemplate /opt/ipatest.profile

15:52:10.698 INFO - Writing debug logs to /tmp/selenium.log
15:52:10.699 INFO - Java: Sun Microsystems Inc. 10.0-b19
15:52:10.699 INFO - OS: Linux 2.6.18-8.el5 i386
15:52:10.702 INFO - v1.0-beta-1 [2201], with Core v1.0-beta-1 [1994]
15:52:10.758 INFO - Version Jetty/5.1.x
15:52:10.760 INFO - Started HttpContext[/selenium-server/driver,/selenium-server/driver]
15:52:10.762 INFO - Started HttpContext[/selenium-server,/selenium-server]
15:52:10.763 INFO - Started HttpContext[/,/]
15:52:10.772 INFO - Started SocketListener on 0.0.0.0:4444
15:52:10.773 INFO - Started org.mortbay.jetty.Server@5ac072

讓測試程序跑起來:
perl test.pl

我的test.pl 程序開頭部分如下:
----------------------------
#!/usr/bin/perl

use strict;
use warnings;
use Time::HiRes qw(sleep);
use Test::WWW::Selenium;
use Test::More "no_plan";
use Test::Exception;

my $sel = Test::WWW::Selenium->new( host => "localhost",
                                    port => 4444,
                                    browser => "*firefox",
                                    browser_url => "

$sel->open_ok("/testpage");
$sel->click_ok("link=Add User");
$sel->wait_for_page_to_load_ok("30000");
$sel->type_ok("form_title", "auto001");
$sel->type_ok("form_givenname", "selenium");
$sel->type_ok("form_sn", "001");
$sel->type_ok("form_krbprincipalkey", "redhat123");
$sel->type_ok("form_krbprincipalkey_confirm", "redhat123");
$sel->click_ok("document.form.submit[1]");
$sel->wait_for_page_to_load_ok("30000");
$sel->is_text_present_ok("s001 added!");
$sel->click_ok("link=Find Users");
$sel->wait_for_page_to_load_ok("30000");
$sel->type_ok("uid", "s101");
$sel->click_ok("http://input[\@value='Find Users']");
$sel->wait_for_page_to_load_ok("30000");
$sel->type_ok("uid", "s001");

---------------------------
我其實沒有寫什么東西,上面的程序都是selenium IDE自動錄的。

 

原文轉自:http://www.anti-gravitydesign.com

国产97人人超碰caoprom_尤物国产在线一区手机播放_精品国产一区二区三_色天使久久综合给合久久97