第 10 集:由華盛頓州貝爾維尤的 Sven Zheng 製作 (2020 年 1 月)
先前集數
Chrome 的測試策略主要仰賴自動化功能正確性測試和手動測試,但這兩者都無法可靠地找出 UI 的輕微回歸情形。使用像素測試自動測試電腦版瀏覽器 UI。
編寫像素測試時,請透過以下方式避免不穩定的情況:(1) 停用動畫、(2) 使用模擬資料,以及 (3) 測試最小可能的表面積。
以下是用於驗證 Omnibox 像素正確性的示例圖片:
驗證瀏覽器的程式碼如下圖所示:
IN_PROC_BROWSER_TEST_F(SkiaGoldDemoPixelTest, TestOmnibox) {
// Always disable animation for stability.
ui::ScopedAnimationDurationScaleMode disable_animation(
ui::ScopedAnimationDurationScaleMode::ZERO_DURATION);
GURL url("chrome://bookmarks");
AddTabAtIndex(0, url, ui::PageTransition::PAGE_TRANSITION_FIRST);
auto* const browser_view = BrowserView::GetBrowserViewForBrowser(browser());
// CompareScreenshot() takes a screenshot and compares it with the
// golden image, which was previously human-approved, is stored
// server-side, and is managed by Skia Gold. If any pixels differ, the
// test will fail and output a link for the author to triage the
// new image.
bool ret = GetPixelDiff().CompareScreenshot("omnibox",
browser_view->GetLocationBarView());
EXPECT_TRUE(ret);
}
此程式碼位於 chrome/test/pixel/demo/skia_gold_demo_pixeltest.cc。相關標頭為 skia_gold_pixel_diff.h
(單元測試) 和 browser_skia_gold_pixel_diff.h
(瀏覽器測試)。
像素差異和核准程序由 Skia Gold 提供支援。Skia Gold 像素測試提供視覺核准工作流程,讓開發人員透過核准多個金色圖片來接受小型異常。
目前測試套件是在 Windows FYI 機器人上執行。支援瀏覽器測試和 View 單元測試。