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

问题描述 投票:1回答:2

将浏览器添加到UI自动化框架/包装器的可用浏览器列表中以通过适当的浏览器成功运行自动测试需要什么?例如,我想添加使用Chromium核心的浏览器“Sputnik”。

selenium selenium-webdriver selenium-chromedriver ui-automation chromium
2个回答
0
投票

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

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

Documentation how to use Codeception with ChromeDriver.

如果你不能使它工作,你可能需要在代码中做一些更改,所以fork chromedriver并修改它工作。

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


0
投票

TL; DR:使用Selenium + Codeception(或任何其他支持chrome的框架),为“无效”浏览器添加一个特殊的环境作为Sputnik,其中二进制路径等同于你的chrome-binary。在删除了一个不必要的检查浏览器版本的条件后,从chrome-project重新编译chromedriver,预安装以下软件包:Visual Studio(С++,wdk + sdk + mfc + atl),depot_tools,Perl,Python2 + Pywin32之后需要在Windows Kits源代码中修复其中一个障碍,因此没有可能通过忍者编译项目。

有用的材料:

[英文]: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。

下载最新版本的原始Chromedriver并放入C:/ Windows):https://chromedriver.storage.googleapis.com/index.html - 用于调试在无效/有效浏览器中运行自动测试时可能出现的非显而易见的问题

您必须只使用标准命令行(cmd),否则您将遇到许多不明显的错误,如“%filename%:没有这样的文件或目录”。

添加设置到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),最好使用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,在没有与Chromedriver冲突的情况下,自动测试在Chrome中真正成功执行。例如,Chromedriver 2.41支持Chrome v67-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]未知错误:未处理的检查错误:{“code”: - 32601,“message”:“找不到'Browser.getWindowForTarget'”}。不要尝试根据Sputnik版​​本中的Chrome覆盖产品信息,因为在这种情况下,可执行文件将变为无效,当尝试启动时,您将看到错误“无法启动应用程序,因为其并行配置不正确”,当您运行自动测试时,我们将遇到错误:[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:\铬\ SRC \出\默认\ chromedriver.exe

检查使用此编译版的chromedriver,在将更新的chromedriver.exe放入C:/ Windows后,自动测试在Chrome浏览器中真正成功执行。

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

return error;

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

return Status(kOk);

删除默认文件夹的内容后,再次编译Chromedriver。并且在编译期间出现错误时,您应该在下一次编译之前清除该文件夹,否则编译版本很可能会被破坏。

如果编译成功,则将更新的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引擎上的任何浏览器一起使用。

© www.soinside.com 2019 - 2024. All rights reserved.