Try   HackMD

跨瀏覽器測試(手動設定WebDriver)

您可將Recorder錄製出的測試案例於多種瀏覽器上運行,包含桌面瀏覽器Chrome、Firefox、Edge、Safari,與Android上之瀏覽器。本文將介紹如何在同一台電腦上達成跨瀏覽器測試。

桌面瀏覽器

  1. 安裝Java SE
  2. 建立一個目錄,例如selenium_server
  3. 下載Selenium Server (建議版本:4.8.0)
  4. selenium-server-{version}.jar存放至selenium_server目錄
  5. 下載瀏覽器Web Driver並存放至selenium_server目錄

    下列為目前Rapi支援的瀏覽器

    Chrome

    1. 下載chromeDriver,請選擇符合電腦上瀏覽器版本
    2. 解壓縮後存放至selenium_server目錄

    Firefox

    1. 下載geckodriver,請選擇符合電腦上作業系統版本
    2. 解壓縮後存放至selenium_server目錄

    Edge

    1. 下載msedgedriver,請選擇符合電腦上瀏覽器版本
    2. 解壓縮後存放至selenium_server目錄

    Safari

    1. 開啟命令列並執行safaridriver --enable,輸入您的使用者密碼
    2. 開啟Safari,點選Safari > Preferences > Advanced以啟用Develop選單,勾選Show Develop Menu
    3. 點選Develop選單->Allow Remote Automation以啟用Remote Automation,.
  6. 開啟Recorder並點選右上方設定按鈕
  7. 啟用 Playback through WebDriver
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  8. WebDriver Settings中之Server URL欄位填入localhost,在Port欄位填入4444
  9. browerName欄位填入chromefirefoxMicrosoftEdgesafari,並在其他欄位留白
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  10. 開啟命令列並將路徑變更為selenium_server目錄,執行java -jar selenium-server-{version}.jar standalone
  11. 如果您使用的是 MAC 作業系統,請在selenium_server目錄下於命令列輸入以下指令來授予瀏覽器WebDriver權限:
  • 針對Chrome瀏覽器,請執行spctl --add --label 'Approved' chromedriver
  • 針對Firefox瀏覽器,請執行spctl --add --label 'Approved' geckodriver
  • 針對Edge瀏覽器,請執行spctl --add --label 'Approved' MicrosoftWebDriver
  • 針對Safari瀏覽器則無需做任何動作
  1. 播放測試案例。這些被設定的瀏覽器將會被Selenium Server所啟動並運行測試案例。

行動瀏覽器

底下為目前Rapi所支援的行動裝置平台

Android(Emulator)

第1到7步驟為建置Appium與Android Emulator,如果已有Appium與Android環境可跳到第8步驟

  1. 安裝 Appium
  2. 安裝 Java
  3. 下載 Android Studio,確認有裝 Android SDK Tools
    (Customize→All settings →Appearance&Behavior→System Settings→Android SDK→SDK Tools)
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  4. 使用Android Studio的 Android Virtual Device 功能來啟動一個虛擬機,並確認開啟USB debugging功能
  5. 下載 Chromedriver,請選擇符合行動裝置上瀏覽器版本
  6. 開啟Appium並點選Edit Configurations,於ANDROID_HOME輸入Android Studio的SDK Location,於JAVE_HOME輸入/path/to/JAVA/jrex.x.x_x。點選Save and Restart
  7. Appium切換至Advanced設定,捲動至Android並於Chromedriver Binary Path填入Chrome Driver檔案路徑,點選Start Server
  8. 開啟Rapi設定頁面,WebDriver Settings->Add New Service->AppiumServer URL填入localhostPort填入4723。點選Add New Browser,於browserNameplatfromNamedeviceNameautomationName欄位分別填入chromeandroid<YOUR_PHONE_NAME>UiAutomator2
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  9. Basic Setting中啟用Playback through WebDriver
  10. 播放測試案例

iOS(Simulator)

  1. 啟動iOS Simulator
  2. Appium切換至Advanced設定,捲動至iOS並於WebDriverAgent Port輸入8100,點選Start Server
  3. 開啟Rapi設定頁面,WebDriver Settings->Add New Service->AppiumServer URL填入localhostPort填入4723。點選Add New Browser,於browserNameplatfromNamedeviceNameautomationName欄位分別填入SafariiOS<YOUR_PHONE_NAME>XCUITest
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  4. Basic Setting中啟用Playback through WebDriver
  5. 播放測試案例