w-puppeteer-uitest

w-puppeteer-uitest

new w-puppeteer-uitest()

Source:

Methods

(async, static) build(fd_html, fd_action, fd_out, optExpopt) → {Promise}

Description:
  • 批次建置測試範例之正確版快照(screenshot)

Source:
Parameters:
Name Type Attributes Default Description
fd_html String

輸入html檔案所在資料夾字串

fd_action String | function

輸入html檔案所需測試動作json檔案所在資料夾字串,為函數時將於產生items時呼叫,針對各item需回傳操作actions物件陣列

fd_out String

輸入快照資料儲存之資料夾字串

optExp Object <optional>
{}

輸入設定物件,預設為{}

Properties
Name Type Attributes Default Description
htmlFilter function <optional>
null

輸入讀取html檔案過濾函數,可再用以過濾讀取fd_html內html檔案,預設為null

headless Boolean <optional>
true

輸入是否以無頭方式開啟網頁,預設為true

viewport Object <optional>
{ width: 800, height: 600 }

輸入網頁開啟後之viewport,預設為{ width: 800, height: 600 }

num_web Number <optional>
10

輸入平行啟動瀏覽器之數量,預設為10

Returns:

回傳Promise,resolve為建置成功,reject為建置失敗item名稱

Type
Promise

(async, static) compareB64(b64_a, b64_b) → {Promise}

Description:
  • 2張圖片base64比對

Source:
Parameters:
Name Type Description
b64_a String

輸入圖片a的base64格式字串

b64_b String

輸入圖片b的base64格式字串

Returns:

回傳Promise,resolve為相似度0~1,reject為處理失敗

Type
Promise

(async, static) expBuild(items, optExpopt) → {Promise}

Description:
  • 建置測試範例之正確版快照(screenshot)

Source:
Parameters:
Name Type Attributes Default Description
items Array

輸入html範例所在之資料夾字串

item.name String

輸入item名稱字串

item.url String

輸入item所需瀏覽範例位置字串

item.actions Array

輸入item所需執行自動化操作動作陣列

item.fn_png String

輸入item儲存png圖之路徑字串

item.fn_base64 String

輸入item儲存圖base64資料之路徑字串

optExp Object <optional>
{}

輸入設定物件,預設為{}

Properties
Name Type Attributes Default Description
headless Boolean <optional>
true

輸入是否以無頭方式開啟網頁,預設為true

viewport Object <optional>
{ width: 800, height: 600 }

輸入網頁開啟後之viewport,預設為{ width: 800, height: 600 }

num_web Number <optional>
10

輸入平行啟動瀏覽器之數量,預設為10

Returns:

回傳Promise,resolve為建置成功,reject為建置失敗item名稱

Type
Promise

(async, static) expTest(items, optExpopt) → {Promise}

Description:
  • 測試範例之快照(screenshot)是否與正確版相同

Source:
Parameters:
Name Type Attributes Default Description
items Array

輸入html範例所在之資料夾字串

item.name String

輸入item名稱字串

item.url String

輸入item所需瀏覽範例位置字串

item.actions Array

輸入item所需執行自動化操作動作陣列

item.fn_base64 String

輸入item儲存圖base64資料之路徑字串

optExp Object <optional>
{}

輸入設定物件,預設為{}

Properties
Name Type Attributes Default Description
headless Boolean <optional>
true

輸入是否以無頭方式開啟網頁,預設為true

viewport Object <optional>
{ width: 800, height: 600 }

輸入網頁開啟後之viewport,預設為{ width: 800, height: 600 }

num_web Number <optional>
10

輸入平行啟動瀏覽器之數量,預設為10

ratio_similar Number <optional>
1

輸入偵測圖片相近度,預設為1,也就是完全相似

Returns:

回傳Promise,resolve為建置成功,reject為建置失敗item名稱

Type
Promise

(async, static) getB64(url, optopt) → {String}

Description:
  • 瀏覽網址並用screenshot取得圖片base64資料

Source:
Parameters:
Name Type Attributes Default Description
url String

輸入瀏覽網址,可為本機檔案絕對或相對位置

opt Object <optional>
{}

輸入設定檔,預設為{}

Properties
Name Type Attributes Default Description
headless Boolean <optional>
true

輸入是否以無頭方式開啟網頁,預設為true

viewport Object <optional>
{ width: 800, height: 600 }

輸入網頁開啟後之viewport,預設為{ width: 800, height: 600 }

actions Array <optional>
[]

輸入網頁開啟後之操作動作,預設為[]

action Object

輸入action動作物件

Properties
Name Type Description
mode Object

動作模式字串,可選'wait','move','elemove','elehover',drag','eledrag','click','eleclick','dbclick','eledbclick','type','eletype'

action Object

若action.mode使用'wait',需再輸入{time},單位為毫秒

action Object

若action.mode使用'resize',需再輸入{width,height},為網頁可視區域(viewport)的長寬,單位為整數

action Object

若action.mode使用'move',需再輸入{x1,y1},為相對網頁內容左上角位置,單位為px

action Object

若action.mode使用'elemove',需再輸入{selector,nth(可選)},selector為css選擇器,nth為陣列結果取第nth個dom元素,預設為0,負值代表由最末往前選(-nth)個dom元素

action Object

若action.mode使用'elehover',需再輸入{selector},selector為css選擇器,若有超過1個結果則取第1個dom元素

action Object

若action.mode使用'drag',需再輸入{x1,y1,x2,y2},由(x1,y1)拖曳至(x2,y2),為相對網頁內容左上角位置,單位為px

action Object

若action.mode使用'eledrag',需再輸入{selector,nth(可選),shiftx,shifty},由元素中心拖曳平移(shiftx,shifty),selector為css選擇器,nth為陣列結果取第nth個dom元素,預設為0,負值代表由最末往前選(-nth)個dom元素,shiftx,shifty單位為px

action Object

若action.mode使用'click',需再輸入{x1,y1},為相對網頁內容左上角位置,單位為px

action Object

若action.mode使用'eleclick',需再輸入{selector,nth(可選)},selector為css選擇器,nth為陣列結果取第nth個dom元素,預設為0,負值代表由最末往前選(-nth)個dom元素

action Object

若action.mode使用'dbclick',需再輸入{x1,y1},為相對網頁內容左上角位置,單位為px

action Object

若action.mode使用'eledbclick',需再輸入{selector,nth(可選)},selector為css選擇器,nth為陣列結果取第nth個dom元素,預設為0,負值代表由最末往前選(-nth)個dom元素

action Object

若action.mode使用'type',需再輸入{str,noEnter(可選)},為由當前焦點輸入文字str,noEnter為輸入文字結尾不再輸入enter,預設為true

action Object

若action.mode使用'eletype',需再輸入{selector,nth(可選),str,noEnter(可選)},selector為css選擇器,nth為陣列結果取第nth個dom元素,預設為0,負值代表由最末往前選(-nth)個dom元素,通過click該dom元素作為焦點輸入文字str,noEnter為輸入文字結尾不再輸入enter,預設為true

action Object

若action.mode使用'keypress',需再輸入{key,count(可選)},為由當前焦點輸入鍵盤key值,key可用'Backspace', 'ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown'或其他keycode,count為觸發次數,預設為1次,keypress可用key詳見[https://github.com/GoogleChrome/puppeteer/blob/v1.19.0/lib/USKeyboardLayout.js]

action Object

若action.mode使用'elefocus',需再輸入{selector,nth(可選),str},selector為css選擇器,nth為陣列結果取第nth個dom元素,預設為0,負值代表由最末往前選(-nth)個dom元素,設定dom元素為當前焦點 keypress

waitsec Integer <optional>
5

輸入開啟網頁後之等待時間,單位為秒,預設為5

Returns:

回傳screenshot圖片轉base64資料

Type
String

(async, static) getFiles(fd) → {Array}

Description:
  • 取得資料夾內檔案,可使用havsStr過濾檔名含有之字串

Source:
Parameters:
Name Type Description
fd String
Returns:

回傳檔案名稱字串陣列

Type
Array

(static) readJson(fn) → {*}

Description:
  • 讀取json檔數據

Source:
Parameters:
Name Type Description
fn String

輸入json檔案路徑字串

Returns:

回傳數據

Type
*

(async, static) test(fd_html, fd_action, fd_base64, optExpopt) → {Promise}

Description:
  • 批次測試範例之快照(screenshot)是否與正確版相同

Source:
Parameters:
Name Type Attributes Default Description
fd_html String

輸入html檔案所在資料夾字串

fd_action String | function

輸入html檔案所需測試動作json檔案所在資料夾字串,為函數時將於產生items時呼叫,針對各item需回傳操作actions物件陣列

fd_base64 String

輸入快照資料儲存之資料夾字串

optExp Object <optional>
{}

輸入設定物件,預設為{}

Properties
Name Type Attributes Default Description
htmlFilter function <optional>
null

輸入讀取html檔案過濾函數,可再用以過濾讀取fd_html內html檔案,預設為null

headless Boolean <optional>
true

輸入是否以無頭方式開啟網頁,預設為true

viewport Object <optional>
{ width: 800, height: 600 }

輸入網頁開啟後之viewport,預設為{ width: 800, height: 600 }

num_web Number <optional>
10

輸入平行啟動瀏覽器之數量,預設為10

ratio_similar Number <optional>
1

輸入偵測圖片相近度,預設為1,也就是完全相似

Returns:

回傳Promise,resolve為建置成功,reject為建置失敗item名稱

Type
Promise