生活随笔
收集整理的這篇文章主要介紹了
软件测试——实验四
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
一、目的和要求
(1)學習使用了解 Selenium 自動化功能測試工具,了解 Selenium 測試工具的測
試模式和過程;
(2)掌握使用 Selenium 錄制測試腳本、執行并分析測試腳本。
(1)撰寫實驗報告,主要填寫本人測試步驟和自己的實驗體會。
(2)提交錄制的測試腳本。
(3)提交檢測結果。
二、實驗內容
(1)使用 Selenium 對 MercuryTours 網站進行功能測試。要求錄制預訂機票的完6
整過程,然后執行測試腳本并分析結果。
(2)設置至少三個檢驗點,觀測檢測結果。
三、測試用例的編寫
錄制測試腳本前的準備
在測試前需要先確認網站以及 Selenium 是否符合測試需求。確認已經知道如何對應用程序進行測試,例如要測那些功能、操作步驟、輸入的數據、預期的結果等。打開 Selenium IDE 后,選擇“在新項目中錄制一個新的測試”,輸入項目名以及需要測試的網址后,開始進行錄制。
Selenium 安裝
Mtours 航空網站的安裝
Mtours 航空網站本地服務開啟
瀏覽器輸入 http://localhost:8080/Mtours,創建一個用戶。
錄制測試腳本
根據想要測試的功能模塊,對 Web 應用進行操作,Selenium 會錄制用戶的一系列操作,并將這些操作轉換為指令集存儲下來。
加強測試腳本
在測試腳本中加入檢查點,可以檢查網頁超級鏈接、對象屬性或是字符串,以驗證應用程序的功能是否正確。Selenium 提供了三種驗證方法,assert、verify以及 waitfor,其區別如下:
Assert:失敗時,該測試將終止;
Verify:失敗時,該測試繼續執行,并將錯誤日志記錄在日顯示屏;
Waitfor:等待某些條件變為真,一般使用在 Ajax 應用程序的測試。調試腳本(對測試腳本除錯)
在修改過測試腳本之后,需要調試測試腳本,檢查腳本是否存在錯誤,以確
保測試腳本能正常且流暢的執行。執行測試腳本
點擊執行測試按鈕后,Selenium 將執行腳本中的指令集,包括用戶添加的驗證類指令集。
分析測試結果
查看日志輸出中的運行結果,分析測試執行的結果,若出現問題,則記錄問題,并找出應用程序的問題所在。導出測試用例(選做)
可以嘗試將測試腳本導出成代碼的形式并運行,如導出成 JUnit。
import org
.junit
.Test
;
import org
.junit
.Before
;
import org
.junit
.After
;
import
static org
.junit
.Assert
.*;
import
static org
.hamcrest
.CoreMatchers
.is
;
import
static org
.hamcrest
.core
.IsNot
.not
;
import org
.openqa
.selenium
.By
;
import org
.openqa
.selenium
.WebDriver
;
import org
.openqa
.selenium
.firefox
.FirefoxDriver
;
import org
.openqa
.selenium
.chrome
.ChromeDriver
;
import org
.openqa
.selenium
.remote
.RemoteWebDriver
;
import org
.openqa
.selenium
.remote
.DesiredCapabilities
;
import org
.openqa
.selenium
.Dimension
;
import org
.openqa
.selenium
.WebElement
;
import org
.openqa
.selenium
.interactions
.Actions
;
import org
.openqa
.selenium
.support
.ui
.ExpectedConditions
;
import org
.openqa
.selenium
.support
.ui
.WebDriverWait
;
import org
.openqa
.selenium
.JavascriptExecutor
;
import org
.openqa
.selenium
.Alert
;
import org
.openqa
.selenium
.Keys
;
import java
.util
.*;
import java
.net
.MalformedURLException
;
import java
.net
.URL
;
public class FourTest
{private WebDriver driver
;private Map
<String
, Object
> vars
;JavascriptExecutor js
;@Beforepublic
void setUp() {driver
= new
ChromeDriver();js
= (JavascriptExecutor
) driver
;vars
= new HashMap
<String
, Object
>();}@Afterpublic
void tearDown() {driver
.quit();}@Testpublic
void four() {driver
.get("http://localhost:8080/mtours/servlet/WelcomeServlet");driver
.manage().window().setSize(new
Dimension(945, 1140));driver
.findElement(By
.name("userName")).click();driver
.findElement(By
.name("userName")).sendKeys("shaoyinghao");driver
.findElement(By
.name("password")).click();driver
.findElement(By
.name("password")).click();driver
.findElement(By
.name("password")).sendKeys("syh416");driver
.findElement(By
.name("login")).click();driver
.findElement(By
.cssSelector("font:nth-child(1) > input:nth-child(2)")).click();driver
.findElement(By
.name("airline")).click();{WebElement dropdown
= driver
.findElement(By
.name("airline"));dropdown
.findElement(By
.xpath("//option[. = 'Blue Skies Airlines']")).click();}driver
.findElement(By
.name("airline")).click();driver
.findElement(By
.name("findFlights")).click();driver
.findElement(By
.name("reserveFlights")).click();driver
.findElement(By
.name("passFirst0")).click();driver
.findElement(By
.name("passFirst0")).sendKeys("shao");driver
.findElement(By
.name("passLast0")).click();driver
.findElement(By
.name("passLast0")).sendKeys("yinghao");driver
.findElement(By
.name("creditnumber")).click();driver
.findElement(By
.name("creditnumber")).sendKeys("121");driver
.findElement(By
.name("buyFlights")).click();assertThat(driver
.findElement(By
.cssSelector("font > b b > font")).getText(), is("$764 USD"));assertThat(driver
.findElement(By
.cssSelector("font > font > font font")).getText(), is("$58 USD"));assertThat(driver
.findElement(By
.cssSelector("tr:nth-child(7) font:nth-child(2)")).getText(), is("AX 121"));}
}
四、測試結果的分析
測試成功
五、測試文檔的撰寫
六、心得與體會
(1)學習了解了 Selenium 自動化功能測試工具
(2)編寫測試了 Selenium 測試工具的測試模式和過程
(3)掌握 Selenium 錄制測試腳本、執行并分析測試腳本。
總結
以上是生活随笔為你收集整理的软件测试——实验四的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。