您的位置:軟件測試 > 開源軟件測試 > 開源功能測試工具 > Selenium
Selenium 總結說明
作者:網絡轉載 發(fā)布時間:[ 2014/2/18 16:41:49 ] 推薦標簽:Selenium 功能測試工具 錄制腳本

  代碼十分簡單,作用是初始化一個Selenium對象。其中:

  url :是你要測試的網站

  localhost: 可以不是localhost,但是必須是selenium server啟動的地址

  *iexplore : 可以是其它瀏覽器類型,可以在網站上看都支持哪些。

  下面我要講講怎么使用selenium這個對象來進行測試。

 1、測試文本輸入框

  假設頁面上有一個文本輸入框,我們要測試的內容是在其中輸入一些內容,然后點擊一個按鈕,看看頁面的是否跳轉到需要的頁面。

   1. public void test1() {  
   2.           
   3.     selenium.open("http://xxx.xxx.xxx/yyy");  
   4.           
   5.     selenium.type("xpath=//input[@name='userID']", "test-user");  
   6.     selenium.click("xpath=//input[@type='button']");  
   7.     selenium.waitForPageToLoad("2000");  
   8.     assertEquals(selenium.getTitle(), "Welcome");  
   9. }

  上面的代碼是這個意思:

  1)調用selenium.open方法,瀏覽器會打開相應的頁面

  2)使用type方法來給輸入框輸入文字

  3)等待頁面載入

  4)看看新的頁面標題是不是我們想要的。

  2、測試下拉框

   1. public void test1() {      
   2.               
   3.     selenium.open("http://xxx.xxx.xxx/yyy");      
   4.               
   5.     selenium.select("xpath=//SELECT[@name='SBBUSYO']", "index=1");  
   6.     selenium.click("xpath=//input[@type='button']");      
   7.     selenium.waitForPageToLoad("2000");      
   8.     assertEquals(selenium.getTitle(), "Welcome");      
   9. }   

  可以看到,我們可以使用select方法來確定選擇下拉框中的哪個選項。

  select方法還有很多用法,具體去看看文檔吧。

  3、測試check box

   1. public void test1() {          
   2.                   
   3.     selenium.open("http://xxx.xxx.xxx/yyy");          
   4.                   
   5.     selenium.check("xpath=//input[@name='MEICK_000']");    
   6.     selenium.click("xpath=//input[@type='button']");          
   7.     selenium.waitForPageToLoad("2000");          
   8.     assertEquals(selenium.getTitle(), "Welcome");          
   9. }    

  我們可以使用check方法來確定選擇哪個radio button。

4、得到文本框里的文字

  1. assertEquals(selenium.getValue("xpath=//input[@name='WNO']"), "1");

  getValue方法是得到文本框里的數值,可不是getText方法,用錯了可郁悶了。

  5、判斷頁面是否存在一個元素

  1. assertTrue(selenium.isElementPresent("xpath=//input[@name='MEICK_000']"));

  一般這個是用來測試當刪除一些數據后,頁面上有些東西不會顯示的情況。

上一頁12下一頁
軟件測試工具 | 聯系我們 | 投訴建議 | 誠聘英才 | 申請使用列表 | 網站地圖
滬ICP備07036474 2003-2017 版權所有 上海澤眾軟件科技有限公司 Shanghai ZeZhong Software Co.,Ltd