TL;DR:使用 Selenium + Codeception(或任何其他 chrome 支持的
框架),为配置添加“无效”的特殊环境
浏览器为 Sputnik,其中二进制文件的路径等同于您的
铬二进制。之后从 chromium-project 重新编译 chromedriver
删除我们不必要的检查浏览器的条件之一
版本,预安装以下软件包:Visual Studio (С++,
wdk+sdk+mfc+atl)、depot_tools、Perl、Python2+Pywin32 及之后
需要修复 Windows Kits 源代码中的一个障碍,因此
无法通过 ninja 编译项目。
有用的材料:
[英文]:http://www.chromium.org/developers/how-tos/get-the-codehttp://commondatastorage.googleapis.com/chrome-infra-docs/flat/depot_tools/docs/html/depot_tools_tutorial.html#_setting_up
[俄语]:https://gist.github.com/oshatrk/0d454018e720b44b45d3e9679da6a98ahttps://habr.com/company/jugru/blog/347024/
此说明适用于 Windows 10。
下载最新版本的原始 Chrome 驱动程序并放入 C:/Windows):https://chromedriver.storage.googleapis.com/index.html — 可用于调试在无效/有效浏览器中运行自动测试时可能出现的非显而易见的问题
您必须只使用标准命令行 (cmd),否则您将
遇到许多不明显的错误,例如“% filename%: no such
文件或目录。”
将设置添加到 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++),选择最新的 SDK 包、MFC 和 ATL 支持包、Windows 调试工具、Windows 驱动程序工具包 (WDK) 和软件仓库工具。
从 repo https://github.com/chromium/chromium 下载 Chromium 并准备项目进行编译:
为了节省空间(~ 10GB),最好执行第一行
标志: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 版本冲突,或者由于缺少 WDK/Windows 调试工具造成的问题。
尝试自动测试执行。一开始,检查一堆 Selenium + Codeception,在没有与 Chromedriver 冲突的情况下,自动测试确实在 Chrome 中成功执行。例如,Chromedriver 2.41 支持 Chrome v67-69,最终将能够支持 Sputnik v3.5.2152.0 gostssl。
一旦我们确信初始工作能力设置 Sputnik 浏览器调用(到目前为止,自动测试代码执行不稳定):在 yml-config 中创建 env-section 或将设置为的 Chrome 写入标准配置部分通往人造卫星的路径:
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 端口号文件内容\ 采用意外格式。
提前警告大家不要使用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不正确”,当您运行自动测试时,我们会遇到错误:
[Facebook\WebDriver\Exception\UnknownServerException] 未知错误:无法创建 Chrome 进程。
在当前指令步骤中通过 Sputnik 运行自动测试时,应看到此错误:[Facebook \ WebDriver \ Exception \ UnknownServerException] 未知错误:无法识别的 Chrome 版本:SputnikBrowser / 3.5.2152.0 (GOST)。
— 可以通过重新编译 Chromedriver 来解决,去掉对浏览器版本的检查。
检查您是否可以从源代码编译 Chromedriver:
d:\chromium\src> ninja -C out/Default chromedriver
如果一切正常,则文件将位于此处:
d:\chromium\src\out\Default\chromedriver.exe
检查使用此编译版本的 chromedriver,在将更新后的 chromedriver.exe 放入 C:/Windows 后,自动测试在 Chrome 浏览器中确实成功执行。
在文件chromedriver\chrome\browser_info.cc中编辑行:128,用于忽略浏览器版本的不匹配:
return error;
将错误状态替换为成功状态:(不要告诉任何人我给了你这个解决方案):
return Status(kOk);
在删除默认文件夹的内容后,再次编译 Chrome 驱动程序。并且如果编译过程中出现错误,请在下次编译之前清除文件夹,否则编译后的版本很可能会损坏。
如果编译成功,则将更新后的 chromedriver.exe 放到 C:/Windows 中,首先在 Chrome 浏览器中验证自动测试是否仍然成功执行:成功执行后检查 Sputnik 中的操作。
如果在编译过程中遇到如下错误日志:
[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 Studio\2017\Enterprise\VC\Tools\MSVC\14.15.26726\ATLMFC\include" "-imsvc..\..\..\..\..\..\..\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.15.26726\include" "-imsvc..\..\..\..\..\..\..\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\ucrt" "-imsvc..\..\..\..\..\..\..\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\shared" "-imsvc..\..\..\..\..\..\..\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\um" "-imsvc..\..\..\..\..\..\..\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\winrt" "-imsvc..\..\..\..\..\..\..\Program Files (x86)\Windows Kits\10\include\10.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\10\include\10.0.17134.0\winrt\wrl.h:18:
..\..\..\..\..\..\..\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\um\wrl\event.h(228,112): error: use of undeclared identifier 'DefaultDelegateCheckMode'
在文件C:\Program Files (x86)\Windows Kits\10\include\10.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;
——在此之后删除当前失败的 chromedriver 程序集并重新编译。
如果编译成功,则将更新后的 chromedriver.exe 放入 C:/Windows 中,首先验证自动测试是否仍然在 Chrome 中成功执行 - 如果成功,请检查 Sputnik 中的操作。
我假设当前更新的 Chromedriver 可以与任何
Chromium 引擎上的浏览器。