跳轉到內容

WebObjects/Project WONDER/Frameworks/ERSelenium

來自華夏公益教科書,自由的教科書

快速入門

[編輯 | 編輯原始碼]

您也可以使用 Selenium IDE 來建立和編輯測試

概述和使用注意事項

[編輯 | 編輯原始碼]

ERSelenium 為有效使用 SeleniumCore 與 WebObjects 應用程式提供了一些功能,包括

  • 可在每個測試之前/之後執行的自定義設定/拆卸操作。
  • 基本 URL 獨立性。
  • 支援 HTML 和 Selenese 測試格式(計劃支援 Java)。
  • 從專案原始碼樹中的檔案“即時”生成測試套件。
  • 可書籤的直接操作 URL,用於執行所有測試(可用於自動化測試)。
  • 元命令(在註釋中指定的特殊指令)。

SeleniumCore 是一個強大的 javascript 工具包,用於 Web 應用程式“黑盒”測試。它模擬各種使用者操作,例如:點選超連結、在輸入欄位中編輯文字、從列表中選擇專案等等。

使用 ERSelenium

[編輯 | 編輯原始碼]

您可以直接從工作區使用 ERSelenium

  1. 將其指定為專案的 工作區依賴項。
  2. 在專案的 Properties 檔案中啟用它
SeleniumTestsEnabled=true

可以在 Properties 中啟用 ERSelenium 的除錯輸出,方法是

log4j.logger.er.selenium = DEBUG

其他 ERSelenium 屬性

  • SeleniumTestsRoot="SomeOtherPath" - 更改測試位置。預設情況下,ERSelenium 會在“Resources/Selenium”中搜索測試。
  • SeleniumActionsClass="FullClassName" - 指定包含方法的類,這些方法應該在使用 SeleniumAction 直接操作進行測試之前和期間執行(有關詳細資訊,請參見下文)。預設情況下,使用 SeleniumDefaultSetupActions 類。
  • SeleniumReportPath="PathName" - 指定測試完成後建立的報告檔案的路徑。預設值為“./Contents/Resources/”。

在 SeleniumTestsRoot 資料夾(預設情況下為 Resources/Selenium)中,您應該建立測試層次結構。測試分為組,每組位於自己的資料夾中。每個資料夾中應該包含一組測試檔案,每個檔案都採用 ERSelenium 支援的格式之一。示例層次結構

./Resources
  ./Selenium
    ./registration
      ./successful.sel
      ./alreadyexists.sel
    ./shop
      ./buyitem.html
      ./notenoughmoney.html
      ./transfer.sel

您可以使用標準 HTML 和 wiki 風格的 Selenese 格式來編寫測試,儘管 Selenese 格式通常是首選。

要執行所有測試,請將您的瀏覽器指向 SeleniumStartTesting 直接操作:http://[baseurl]/wa/SeleniumStartTesting

例如:http://127.0.0.1/cgi-bin/WebObjects/SampleProject.woa/-42421/wa/SeleniumStartTesting

要執行特定組的測試,請新增“/TestGroupName”。

http://[baseurl]/wa/SeleniumStartTesting/TestGroupName
http://127.0.0.1/cgi-bin/WebObjects/SampleProject.woa/-42421/wa/SeleniumStartTesting/registration

為 ERSelenium 編寫測試的一些提示

[編輯 | 編輯原始碼]
  • 不要在 open/openWindow 命令中使用完整 URL(http://[baseurl] 部分將由 ERSelenium 新增)。
  |open|/wa/EditPerson|
  |open|/|
  • 您可以透過開啟 /wa/SeleniumAction/methodName URL 來使用 SeleniumActionsClass 屬性中指定的類的設定/拆卸方法,例如
  |open|/wa/SeleniumAction/resetSession|
  • 您可以使用 @repeat-@values-@done 元命令來執行測試的特定部分,並在文字框中編輯不同的值,例如
  |open|/|
  @repeat
  ...some actions...
  @values __selenium_test@ @__sel notcorrect@@
  |type|xpath=id('content')/input|__selenium_test@incorrectdomain|
  ...some actions...
  @done

@repeat 和 @done 之間的命令將重複多次,每次在“xpath=id('content')/input”輸入欄位中使用新的值。

注意:在 Selenese 格式中,不以“|”開頭的行被視為註釋,因此上面的示例中的元命令將被 Selenium IDE 安全地處理。

  • Selenium IDE Firefox 外掛XPath Checker 對建立和編輯 Selenium 測試非常有用。Selenium IDE Selenese 原始碼外掛(帶適當的註釋支援)位於 ERSelenium/Resources/selenese-ide-plugin.js 中。
華夏公益教科書