您的位置:軟件測試 > 開源軟件測試 > 開源功能測試工具 > Selenium
Selenium自動化測試用例設(shè)計注意事項(二)
作者:網(wǎng)絡(luò)轉(zhuǎn)載 發(fā)布時間:[ 2013/1/28 10:52:45 ] 推薦標(biāo)簽:

  上面的Python代碼打開一個文本文件,這個文件每行包含不同的搜索字符串。然后代碼保存字符串到一個字符串?dāng)?shù)組,對數(shù)值進(jìn)行遍歷,使用搜索字符串進(jìn)行查詢,并進(jìn)行斷言。

  這是一個非常簡單的例子,但其中的思路表明,可以很簡單的使用編程、腳本語言進(jìn)行數(shù)據(jù)驅(qū)動的測試。有關(guān)更多示例,請參閱 Selenium RC wiki 來了解如何從電子表格讀取數(shù)據(jù)或使用TestNG的提供數(shù)據(jù)。此外,這是一個在自動化測試的專業(yè)人士圈內(nèi)眾所周知的話題之一,包括那些不使用Selenium的自動化圈子,因此搜索互聯(lián)網(wǎng)上的“數(shù)據(jù)驅(qū)動測試”,會得到許多關(guān)于這一主題的博客。

  數(shù)據(jù)庫驗證

  另一種常見的測試類型是,比較用戶界面上的數(shù)據(jù)和存儲在后臺數(shù)據(jù)庫中的數(shù)據(jù)。因為你也可以使用一種編程語言進(jìn)行數(shù)據(jù)庫查詢,假設(shè)你有數(shù)據(jù)庫相關(guān)的函數(shù),你可以用它們來檢索數(shù)據(jù),然后使用這些數(shù)據(jù)來驗證頁面上所顯示的數(shù)據(jù)是正確的。

  考慮如下例子,從數(shù)據(jù)庫中進(jìn)行檢索注冊電子郵件地址,然后再和界面上的數(shù)據(jù)進(jìn)行比較。代碼如下,先建立一個數(shù)據(jù)庫連接,并從數(shù)據(jù)庫中檢索數(shù)據(jù),使用的是Java語言:

// Load Microsoft SQL Server JDBC driver.
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
 
// Prepare connection url.
String url = "jdbc:sqlserver://192.168.1.180:1433;DatabaseName=TEST_DB";
 
// Get connection to DB.
public static Connection con =
DriverManager.getConnection(url, "username", "password");
 
// Create statement object which would be used in writing DDL and DML
// SQL statement.
public static Statement stmt = con.createStatement();
 
// Send SQL SELECT statements to the database via the Statement.executeQuery
// method which returns the requested information as rows of data in a
// ResultSet object.
 
ResultSet result =  stmt.executeQuery
("select top 1 email_address from user_register_table");
 
// Fetch value of "email_address" from "result" object.
String emailaddress = result.getString("email_address");
 
// Use the emailAddress value to login to application.
selenium.type("userID", emailaddress);
selenium.type("password", secretPassword);
selenium.click("loginButton");
selenium.waitForPageToLoad(timeOut);
Assert.assertTrue(selenium.isTextPresent("Welcome back" +emailaddress), "Unable to log in for user" +emailaddress)

  這是一個簡單的Java例子從數(shù)據(jù)庫中檢索數(shù)據(jù)。

  本文轉(zhuǎn)載自:http://www.loggingselenium.com/

相關(guān)鏈接:
上一頁1234下一頁
軟件測試工具 | 聯(lián)系我們 | 投訴建議 | 誠聘英才 | 申請使用列表 | 網(wǎng)站地圖
滬ICP備07036474 2003-2017 版權(quán)所有 上海澤眾軟件科技有限公司 Shanghai ZeZhong Software Co.,Ltd