跳到主要內容

自己的 UI 自己測,proctractor for your UI testing

自己的 UI 自己測,proctractor for your UI testing



測試對於開發來說已經是一個基本的概念,只要提到測試基本架構 TDD, BDD 大家都已經耳熟能詳基本上我們也不用太多做介紹。

但是對於 UI 來說,很多都不知道怎麼下手,也不知道怎麼進行,我們就來看看怎麼進行吧!

準備

這邊以 protractor 為執行框架,protractor 目前已經是 angular UI testing 標準流程之一,也是 Google 正在維護的專案之一 ,同時因為 protractor 已經將 web driver 進行整合,同時也把 selenium 包裝進去。

另外比較多的部份就是他已經把 angular framework 預設嵌入,因此可以透過 protractor 來進行 angular web application 的前端測試,測試 model, service, directive 的完整性。

使用方法

npm install -g proctracor
在這之前需要準備 java ,讓 selenium 可以執行,前面有提到 protractor 已經將 web driver 預設進去,因此可以透過安裝好 protractor 之後,就會有 web driver,可以執行更新
web-driver update
接著就會進行 web driver 核心及元件更新,接下來將會以 chrome core 運行,讓 web driver 去調用 chrome browser。

運作

首先在專案底下你要設定 config.js ,設定 protractor 的設定檔案,包含 test config, 運作瀏覽器環境,以及需要去執行的 url end point 等資訊。
範例可以參考 protractor config example,
// An example configuration file.
exports.config = {
  directConnect: true,

  // Capabilities to be passed to the webdriver instance.
  capabilities: {
    'browserName': 'chrome'
  },

  // Spec patterns are relative to the current working directly when
  // protractor is called.
  specs: ['example_spec.js'],

  // Options to be passed to Jasmine-node.
  jasmineNodeOpts: {
    showColors: true,
    defaultTimeoutInterval: 30000
  }
};
接著輸入以下指令進行 protractor 運作
protractor conf.js
接著就會去執行 example_spec.js 這個檔案裡面的行為,你也會看到瀏覽器開始會自動跳啊跳的,好快樂,開始像是以前用鍵盤精靈的感覺。

事實上 UI 測試也就是如此的精神,讓多次重複的動作,可以自動化完成,達到測試階段。

後記

目前已經把 UI testing 加入到專案測試的環節當中,雖然對於 UI 是一種經常性變動的開發環節,不過對於一致性的模組,共用性的標準其實還是可以進行 mini function test ,就像是 API 一樣,當有了最小的測試循環之後,我們就可以確保執行可行性,讓每次運作都可以正常執行。

另外如果你跟我一樣是透過 mocha 進行 test 的話,可以參考 protractor 如何搭配 mocha 這篇文章進行整合。

其他參考資料

留言

這個網誌中的熱門文章

[CSS] z-index 在不同瀏覽器繼承問題

今天會討論到這個課題,是因為要實做一個Popup dialog,所以我們希望的結果如下圖。 可是在IE7 卻發生了這樣的情況。 Popup不論怎麼設定z-index都無法浮在最上層,我們看一下html架構發生什麼事情。

[教學] 快快樂樂刪除CodeIgniter index.php

預設的CI網址預設都設定為index.php同一層級,因此所有的程式都必須指定index.php導向才能開始,例如 http://localhost/ci/index.php/welcome/test http://localhost/ci/welcome/test 本文將說明如何將惱人的index.php消除,還你一個漂亮的URL。 設定開始: 接下來說明如何使用rewrite方式將惱人的index.php去除。 rewrite不清楚的人,煩請先自行google 首先要先確定Apache的 mod_rewrite 有 開啟 ,如果沒有開啟請設定好之後重新啟動apache。 接著,在根目錄底下建立一個新檔案,檔名為 .htaccess ,裡面程式碼如下: <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php/$1 [L] </IfModule> 接著到 application/config/config.php ,開啟檔案修改 $config['index_page'] = ""; 注意: /index.php/$1 要根據你目錄,例如 http://localhost/index.php ,網站根目錄為 /ci/index.php 則要寫成 /ci/index.php/$1 接著至CI目錄下,尋找 config\config.php , 修改一下裡面的檔案,修改如下: $config['index_page'] = ""; 存檔後,如此一來大功告成。 參考資料 官方網站說明

AI-Native Agent 時代的 2026 年身為管理者應該知道的事情

AI-Native Agent 時代的 AI-Native Engineering 從 Andrew Ng 的 AI Engineering Skills Map,到 2026 年 9 月真正正在成形的 Agent-first Software Development 2026 年 9 月 4 日,Andrew Ng 發表了 AI Engineering Skills Map 系列中關於 Using Coding Agents 的文章,同時期 Claude, Cursor, OpenAI 也發表了許多架構,經驗談,以及商業上的應用,此時將眾家以及自己在正美科技所進行的事情進行彙整,讓大家可以少走些彎路,少踩些坑。 以下這些文章,有點長度,但他對於技術人,對於商業人,對於想要 AI 導入到自己公司的人都會有所幫助,不論你想要自己 vibe coding 或者是你是想要更近一步的 AI 自媒體老師,都應該完整閱讀這篇文章 同時我也希望你可以給我更多回饋,或者加入社團討論 「AI for Developer LINE 社群連結」 本文開始 如果把整篇文章和 2026 年正在發生的事情放在一起看,以及結合自己在開發 cymkube & cympack 的經驗來說,將整個 ai 智能製造 (ai manufacturing) 的過程來說,回歸到軟體工程,可以歸納成一段話。 軟體工程正在從「Human 寫 Code,AI 幫忙」轉向「Human 定義 Intent、Architecture、Constraints 與 Acceptance Criteria,Agent 負責 Execution,而系統負責 Verification」。 回歸過去就是: 2024 Human writes code AI assists ↓ 2025 Human prompts Agent edits code ↓ 2026 Human specifies intent Agents execute in parallel Verifiers inspect output Humans make judgment ↓ Next Human manages an engineering system ...