Сhromedriver:如何添加对基于 Chromium 的浏览器的支持

Сhromedriver: how to add support of Chromium-based browsers

需要什么才能将浏览器添加到可用浏览器列表,以便 UI-自动化 frameworks/wrappers 通过适当的浏览器成功 运行 自动测试?例如,我想添加使用 Chromium 内核的浏览器 "Sputnik"。

使您的浏览器受 Selenium 支持,它将适用于所有框架。 Selenium 使用特定于浏览器的驱动程序。

由于您的浏览器是基于 Chromium 的,因此 ChromeDriver 很有可能开箱即用。

Documentation how to use Codeception with ChromeDriver.

如果您无法使其正常工作,您可能需要对代码进行一些更改,以便分叉 chromedriver 并对其进行修改以使其正常工作。

如果你有一个全新的浏览器,你将不得不实施 WebDriver 协议,但我认为这对你的情况没有必要

TL;DR: Use Selenium + Codeception (or any other chrome-supported framework), add to configuration a special enviroment for "non-valid" browser as Sputnik, wherein path to binary is equivalent to your chrome-binary. Recompile chromedriver from chromium-project after removing one of unnecessary for us condition of checking the browser version, pre-install the following software kits: Visual Studio (С++, wdk+sdk+mfc+atl), depot_tools, Perl, Python2+Pywin32 and after this need to fix one of snag in Windows Kits source code, because of which there is no possibility to compile the project via ninja.

有用资料:

[英文]: http://www.chromium.org/developers/how-tos/get-the-code http://commondatastorage.googleapis.com/chrome-infra-docs/flat/depot_tools/docs/html/depot_tools_tutorial.html#_setting_up

[俄语]: https://gist.github.com/oshatrk/0d454018e720b44b45d3e9679da6a98a https://habr.com/company/jugru/blog/347024/

此指令是为Windows 10.

提供的

下载最新版本的原Chrome驱动并放入C:/Windows): https://chromedriver.storage.googleapis.com/index.html — 用于调试[=时可能出现的不明显问题139=]在无效/有效浏览器中自动测试

You must use only the standard command line (cmd), otherwise you will encounter a number of unobvious errors like as "% filename%: no such file or directory."

将设置添加到 git:

$ git config --global user.name "%USERNAME%"
$ git config --global user.email "%EMAIL%"
$ git config --global core.autocrlf false
$ git config --global core.filemode false
$ git config --global branch.autosetuprebase always 

安装Visual Studio(适用于 C++)、select 最新的 SDK 包、MFC- 和 ATL- 支持包、Windows 的调试工具、Windows 驱动程序包(WDK) 和 depot 工具。

从 repo https://github.com/chromium/chromium 下载 Chromium 并准备编译项目:

To save space (~ 10GB), it is better to execute the first line with flag: fetch --no-history chromium.

d:\chromium> fetch chromium
d:\chromium> mkdir src
d:\chromium> cd src
d:\chromium\src> gclient sync
d:\chromium\src> gn gen out/Default

如果你在执行gn-commands的过程中会遇到类似的错误:

ninja: error: loading 'build.ninja': no such file or directory
ninja: error: loading 'build.ninja': ═х єфрхЄё эрщЄш єърчрээ√щ Їрщы.

— 很可能是 Win10 SDK 安装版本冲突或缺少 Windows 的 WDK/调试工具导致的问题。

正在尝试自动测试执行。一开始,检查一堆 Selenium + Codeception,在没有与 Chrome 驱动程序冲突的情况下,自动测试确实在 Chrome 中成功执行。例如Chromedriver 2.41支持Chromev67-69,最终将能够支持Sputnik v3.5.2152.0 gostssl。

一旦我们确信初始工作能力设置 Sputnik 浏览器调用(到目前为止自动测试代码执行不稳定):在 yml-config 中创建 env-section 或写入标准配置部分 Chrome 将路径设置为 Sputnik:

 modules:
  enabled: [WebDriver, WebHelper, Asserts]
  config:
    WebDriver:
      browser: chrome
      capabilities:
      chromeOptions:
        args: [--remote-debugging-port=9222]
        binary: 'C:/Program Files (x86)/Sputnik/Sputnik/Application/browser.exe'
    #window_size: 1200x768 is not supported for Sputnik

需要声明标志 --remote-debugging-port=9222 以避免错误 [Facebook\WebDriver\Exception\UnknownServerException] 未知错误:Devtools 端口号文件内容 \<50250> 的格式不正确。 我提前警告你不要使用 window_size 参数,因为 Chromium 不支持它,否则我们会遇到错误:[Facebook\WebDriver\Exception\UnknownServerException] unknown error: unhandled inspector error : {"code":-32601,"message":"'Browser.getWindowForTarget' 未找到"}。不要尝试按照Sputnik版​​本中的Chrome覆盖产品信息,因为在这种情况下可执行文件将失效,尝试启动时会看到错误"Could not start the application because its parallel configuration is incorrect" ,当你 运行 自动测试时,我们会遇到错误: [Facebook\WebDriver\Exception\UnknownServerException] 未知错误:无法创建 Chrome 进程。 当 运行 在当前指令步骤上通过 Sputnik 自动测试时应该会看到此错误:[Facebook\WebDriver\Exception\UnknownServerException] 未知错误:无法识别 Chrome 版本:SputnikBrowser / 3.5.2152.0 (GOST). — 在删除浏览器版本检查后,通过重新编译 Chrome 驱动程序解决。

检查您是否真的可以从源代码编译 Chrome驱动程序:

d:\chromium\src> ninja -C out/Default chromedriver

如果一切正常,则文件将位于此处:

d:\chromium\src\out\Default\chromedriver.exe

检查 chrome 驱动程序的编译版本,在将更新的 chromedriver.exe 放入 C:/[=119 后,AutoTests 在 Chrome 浏览器中确实成功执行=].

在文件chromedriver\chrome\browser_info.cc编辑行:128,忽略浏览器版本不匹配:

return error;

将错误状态替换为成功状态:(不要告诉任何人我给了你这个解决方案):

return Status(kOk);

删除 Default 文件夹的内容后,再次编译 Chrome 驱动程序。并且如果在编译过程中出现错误,请在下次编译前清除该文件夹,否则编译后的版本很可能会被破坏。

如果编译成功,则将更新后的chromedriver.exe放入C:/Windows,首先验证autotests是否仍然在Chrome浏览器中成功执行:成功后执行检查人造卫星中的操作。

如果在编译过程中遇到如下错误日志:

[3281/4416] CXX obj/ui/gfx/gfx/font_fallback_win.obj
FAILED: obj/ui/gfx/gfx/font_fallback_win.obj
../../third_party/llvm-build/Release+Asserts/bin/clang-cl.exe /nologo /showIncludes "-imsvc..\..\..\..\..\..\..\Program Files (x86)\Microsoft Visual Studio17\Enterprise\VC\Tools\MSVC.15.26726\ATLMFC\include" "-imsvc..\..\..\..\..\..\..\Program Files (x86)\Microsoft Visual Studio17\Enterprise\VC\Tools\MSVC.15.26726\include" "-imsvc..\..\..\..\..\..\..\Program Files (x86)\Windows Kits\include.0.17134.0\ucrt" "-imsvc..\..\..\..\..\..\..\Program Files (x86)\Windows Kits\include.0.17134.0\shared" "-imsvc..\..\..\..\..\..\..\Program Files (x86)\Windows Kits\include.0.17134.0\um" "-imsvc..\..\..\..\..\..\..\Program Files (x86)\Windows Kits\include.0.17134.0\winrt" "-imsvc..\..\..\..\..\..\..\Program Files (x86)\Windows Kits\include.0.17134.0\cppwinrt" -DGFX_IMPLEMENTATION -DV8_DEPRECATION_WARNINGS -DUSE_AURA=1 -DNO_TCMALLOC -DFULL_SAFE_BROWSING -DSAFE_BROWSING_CSD -DSAFE_BROWSING_DB_LOCAL -DOFFICIAL_BUILD -DCHROMIUM_BUILD -DFIELDTRIAL_TESTING_ENABLED "-DCR_CLANG_REVISION=\"338452-2\"" -D_HAS_NODISCARD -D_HAS_EXCEPTIONS=0 -D__STD_C -D_CRT_RAND_S -D_CRT_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_DEPRECATE -D_ATL_NO_OPENGL -D_WINDOWS -DCERT_CHAIN_PARA_HAS_EXTRA_FIELDS -DPSAPI_VERSION=1 -DWIN32 -D_SECURE_ATL -D_USING_V110_SDK71_ -DWINAPI_FAMILY=WINAPI_FAMILY_DESKTOP_APP -DWIN32_LEAN_AND_MEAN -DNOMINMAX -D_UNICODE -DUNICODE -DNTDDI_VERSION=0x0A000002 -D_WIN32_WINNT=0x0A00 -DWINVER=0x0A00 -DNDEBUG -DNVALGRIND -DDYNAMIC_ANNOTATIONS_ENABLED=0 -DWEBP_EXTERN=extern -DSK_IGNORE_LINEONLY_AA_CONVEX_PATH_OPTS -DSK_HAS_PNG_LIBRARY -DSK_HAS_WEBP_LIBRARY -DSK_HAS_JPEG_LIBRARY -DSK_SUPPORT_GPU=1 "-DSK_GPU_WORKAROUNDS_HEADER=\"gpu/config/gpu_driver_bug_workaround_autogen.h\"" -DGR_GL_FUNCTION_TYPE=__stdcall -DU_USING_ICU_NAMESPACE=0 -DU_ENABLE_DYLOAD=0 -DU_STATIC_IMPLEMENTATION -DICU_UTIL_DATA_IMPL=ICU_UTIL_DATA_FILE -DUCHAR_TYPE=wchar_t "-DFT_CONFIG_CONFIG_H=\"freetype-custom-config/ftconfig.h\"" "-DFT_CONFIG_MODULES_H=\"freetype-custom-config/ftmodule.h\"" "-DFT_CONFIG_OPTIONS_H=\"freetype-custom-config/ftoption.h\"" -DPDFIUM_REQUIRED_MODULES -DCHROMIUM_RESTRICT_VISIBILITY -I../.. -Igen -I../../third_party/libwebp/src -I../../skia/config -I../../skia/ext -I../../third_party/skia/include/c -I../../third_party/skia/include/config -I../../third_party/skia/include/core -I../../third_party/skia/include/effects -I../../third_party/skia/include/encode -I../../third_party/skia/include/gpu -I../../third_party/skia/include/images -I../../third_party/skia/include/lazy -I../../third_party/skia/include/pathops -I../../third_party/skia/include/pdf -I../../third_party/skia/include/pipe -I../../third_party/skia/include/ports -I../../third_party/skia/include/utils -I../../third_party/skia/src/gpu -I../../third_party/skia/src/sksl -I../../third_party/skia/modules/skottie/include -I../../third_party/icu/source/common -I../../third_party/icu/source/i18n -I../../third_party/ced/src -I../../third_party/zlib -I../../third_party/freetype/include -I../../third_party/freetype/src/include -I../../third_party/harfbuzz-ng/src/src /utf-8 /X -fcolor-diagnostics -fmerge-all-constants -Xclang -mllvm -Xclang -instcombine-lower-dbg-declare=0 -no-canonical-prefixes -fcomplete-member-pointers /Gy /FS /bigobj /d2FastFail /Zc:sizedDealloc- -fmsc-version=1911 -m64 /Brepro /W4 -Wimplicit-fallthrough -Wthread-safety /WX /wd4091 /wd4127 /wd4251 /wd4275 /wd4312 /wd4324 /wd4351 /wd4355 /wd4503 /wd4589 /wd4611 /wd4100 /wd4121 /wd4244 /wd4505 /wd4510 /wd4512 /wd4610 /wd4838 /wd4995 /wd4996 /wd4456 /wd4457 /wd4458 /wd4459 /wd4200 /wd4201 /wd4204 /wd4221 /wd4245 /wd4267 /wd4305 /wd4389 /wd4702 /wd4701 /wd4703 /wd4661 /wd4706 /wd4715 /wd4702 -Wno-missing-field-initializers -Wno-unused-parameter -Wno-c++11-narrowing -Wno-covered-switch-default -Wno-unneeded-internal-declaration -Wno-undefined-var-template -Wno-nonportable-include-path -Wno-user-defined-warnings -Wno-unused-lambda-capture -Wno-null-pointer-arithmetic -Wno-enum-compare-switch -Wno-ignored-pragma-optimize /O1 /Ob2 /Oy- /Zc:inline /Gw /Oi /Z7 -fno-standalone-debug /MT -Xclang -add-plugin -Xclang find-bad-constructs -Xclang -plugin-arg-find-bad-constructs -Xclang enforce-in-thirdparty-webkit -Xclang -plugin-arg-find-bad-constructs -Xclang check-enum-max-value -Wheader-hygiene -Wstring-conversion -Wtautological-overlap-compare /wd4267 /TP /wd4577 /GR- /c ../../ui/gfx/font_fallback_win.cc /Foobj/ui/gfx/gfx/font_fallback_win.obj /Fd"obj/ui/gfx/gfx_cc.pdb"
In file included from ../../ui/gfx/font_fallback_win.cc:9:
In file included from ..\..\..\..\..\..\..\Program Files (x86)\Windows Kits\include.0.17134.0\winrt\wrl.h:18:
..\..\..\..\..\..\..\Program Files (x86)\Windows Kits\include.0.17134.0\um\wrl\event.h(228,112): error: use of undeclared identifier 'DefaultDelegateCheckMode'

在文件中C:\Program Files (x86)\Windows Kits\include.0.17134.0\um\wrl\event.h

编辑第228行和第1199行(这不好,但别无选择)。

第 228 行而不是:

template<typename TDelegateInterface, typename TCallback, unsigned int argCount, DelegateCheckMode checkMode = DefaultDelegateCheckMode>

指定:

template<typename TDelegateInterface, typename TCallback, unsigned int argCount, DelegateCheckMode checkMode>

第 1199 行而不是:

extern __declspec(selectany) const DelegateCheckMode DefaultDelegateCheckMode = NoCheck;

指定:

extern __declspec(selectany) const DelegateCheckMode;

— 删除当前失败的 chrome 驱动程序集并重新编译。

如果编译成功,则将更新后的chromedriver.exe放入C:/Windows,并首先验证Chrome中的自动测试是否仍然成功执行——以防万一成功检查 Sputnik 中的操作。

I assume that the currently updated Chromedriver will work with any browser on the Chromium engine.