这个问题的出发点是这个
https://github.com/alibaba/macaca/issues/266 该问题已在群里多人反应了。
简单的讲就是 win10 或 ubuntu16.04 系统当把 chrome 浏览器升级到最新版本 54.0.2840.71 后会导致脚本里如果用的是 browserName: 'chrome'的话,会导致之前成功的 pc web 浏览器脚本执行失败,失败的具体错误就是 macaca server 不断的循环报错。然后自行崩溃退出 macaca server。
最后,官方给出的原因如下:
默认携带 2.20 版本 chromedriver,移动端 chrome 内核更新滞后不能用新版
PC 端已有用户更新了 chrome54 高版本,需要下载更高版本 chromedriver 支持
$CHROMEDRIVER_VERSION=2.25 cnpm i macaca-chrome -g
也就是需要安装 macaca-chrome 的时候,指定安装 2.25 版本的 chromedriver 便可解决该问题。
该命令可在 ubuntu 和 mac 类 linux 系统下执行成功。实际是 (CHROMEDRIVER_VERSION=2.25 npm i macaca-chrome -g 作者可能多打了个或拷贝了个 $ 符)
但是在 win 环境下,我尝试了如下安装命令 都失败了。关键是不知道 cmd 命令行环境下,如何给 npm 传参,也参考了一些
https://sites.google.com/a/chromium.org/chromedriver/downloads
https://www.npmjs.com/package/selenium-standalone
https://www.npmjs.com/package/chromedriver
但最终都是不行的。如以下都是还是安装的 2.20 默认版本的:
CHROMEDRIVER_VERSION=2.25 npm i macaca-chrome -g
npm i macaca-chrome -g CHROMEDRIVER_VERSION=2.25
npm i macaca-chrome -g --CHROMEDRIVER_VERSION=2.25
npm install macaca-chrome -g --CHROMEDRIVER_VERSION=2.25 --CHROMEDRIVER_CDNURL=http://chromedriver.storage.googleapis.com/2.25/chromedriver_win32.zip
npm install macaca-chrome -g --CHROMEDRIVER_CDNURL=https://npm.taobao.org/mirrors/chromedriver/2.25/chromedriver_win32.zip
那这一问题就先暂时记着,如何在 win 环境的 cmd 命令行下给 npm i 传递参数的问题。这个问题等我找到解决方法的,解决 win10 安装传参问题。
CHROMEDRIVER_VERSION=2.25 npm i macaca-chrome -g 是这句,可没少折腾我最后看了这里
https://github.com/macacajs/macaca-chromedriver
https://www.npmjs.com/package/macaca-chromedriver
得到了启发,稍微改了下就可以了.我可是试了有 N 条 (https://github.com/alibaba/macaca/issues/266) 哎....开源有风险,且行且珍惜.
看执行安装日志 我们看到 >> chromedriver cdn url: http://chromedriver.storage.googleapis.com/2.25/chromedriver_linux64.zip 说明指定版本 2.25 成功!!!
cmd@TR:~$ CHROMEDRIVER_VERSION=2.25 npm i macaca-chrome -g
npm WARN deprecated tough-cookie@2.2.2: ReDoS vulnerability parsing Set-Cookie https://nodesecurity.io/advisories/130
> macaca-chromedriver@1.0.26 install /opt/nodejs/lib/node_modules/macaca-chrome/node_modules/macaca-chromedriver
> node ./bin/macaca-chromedriver install
>> chromedriver cdn url: http://chromedriver.storage.googleapis.com/2.25/chromedriver_linux64.zip
>> chromedriver local in /opt/nodejs/lib/node_modules/macaca-chrome/node_modules/macaca-chromedriver/exec/chromedriver
/opt/nodejs/lib
└─┬ macaca-chrome@1.0.4
├─┬ driver-base@0.1.1
│ └── webdriver-dfn-error-code@1.0.4
├─┬ macaca-chromedriver@1.0.26
│ ├── adm-zip@0.4.7
│ ├─┬ commander@2.9.0
│ │ └── graceful-readlink@1.0.1
│ ├─┬ detect-port@1.0.1
│ │ └── commander@2.8.1
│ └─┬ request@2.69.0
│ ├── aws-sign2@0.6.0
│ ├── aws4@1.5.0
│ ├─┬ bl@1.0.3
│ │ └─┬ readable-stream@2.0.6
│ │ ├── core-util-is@1.0.2
│ │ ├── inherits@2.0.3
│ │ ├── isarray@1.0.0
│ │ ├── process-nextick-args@1.0.7
│ │ ├── string_decoder@0.10.31
│ │ └── util-deprecate@1.0.2
│ ├── caseless@0.11.0
│ ├─┬ combined-stream@1.0.5
│ │ └── delayed-stream@1.0.0
│ ├── extend@3.0.0
│ ├── forever-agent@0.6.1
│ ├─┬ form-data@1.0.1
│ │ └─┬ async@2.1.2
│ │ └── lodash@4.16.4
│ ├─┬ har-validator@2.0.6
│ │ ├─┬ is-my-json-valid@2.15.0
│ │ │ ├── generate-function@2.0.0
│ │ │ ├─┬ generate-object-property@1.2.0
│ │ │ │ └── is-property@1.0.2
│ │ │ ├── jsonpointer@4.0.0
│ │ │ └── xtend@4.0.1
│ │ └─┬ pinkie-promise@2.0.1
│ │ └── pinkie@2.0.4
│ ├─┬ hawk@3.1.3
│ │ ├── boom@2.10.1
│ │ ├── cryptiles@2.0.5
│ │ ├── hoek@2.16.3
│ │ └── sntp@1.0.9
│ ├─┬ http-signature@1.1.1
│ │ ├── assert-plus@0.2.0
│ │ ├─┬ jsprim@1.3.1
│ │ │ ├── extsprintf@1.0.2
│ │ │ ├── json-schema@0.2.3
│ │ │ └── verror@1.3.6
│ │ └─┬ sshpk@1.10.1
│ │ ├── asn1@0.2.3
│ │ ├── assert-plus@1.0.0
│ │ ├── bcrypt-pbkdf@1.0.0
│ │ ├─┬ dashdash@1.14.0
│ │ │ └── assert-plus@1.0.0
│ │ ├── ecc-jsbn@0.1.1
│ │ ├─┬ getpass@0.1.6
│ │ │ └── assert-plus@1.0.0
│ │ ├── jodid25519@1.0.2
│ │ ├── jsbn@0.1.0
│ │ └── tweetnacl@0.14.3
│ ├── is-typedarray@1.0.0
│ ├── isstream@0.1.2
│ ├── json-stringify-safe@5.0.1
│ ├─┬ mime-types@2.1.12
│ │ └── mime-db@1.24.0
│ ├── node-uuid@1.4.7
│ ├── oauth-sign@0.8.2
│ ├── qs@6.0.2
│ ├── stringstream@0.0.5
│ ├── tough-cookie@2.2.2
│ └── tunnel-agent@0.4.3
├─┬ macaca-utils@0.1.9
│ └─┬ xutil@1.0.2
│ ├── ipv4@0.0.4
│ ├── lodash@3.10.1
│ ├─┬ mkdirp@0.5.1
│ │ └── minimist@0.0.8
│ ├── moment@2.10.6
│ └─┬ rimraf@2.5.4
│ └─┬ glob@7.1.1
│ ├── fs.realpath@1.0.0
│ ├─┬ inflight@1.0.6
│ │ └── wrappy@1.0.2
│ ├─┬ minimatch@3.0.3
│ │ └─┬ brace-expansion@1.1.6
│ │ ├── balanced-match@0.4.2
│ │ └── concat-map@0.0.1
│ ├── once@1.4.0
│ └── path-is-absolute@1.0.1
└─┬ xlogger@1.0.5
└─┬ chalk@1.1.3
├── ansi-styles@2.2.1
├── escape-string-regexp@1.0.5
├─┬ has-ansi@2.0.0
│ └── ansi-regex@2.0.0
├── strip-ansi@3.0.1
└── supports-color@2.0.0
既然安装指定版本的 chromedriver=2.25 的 macaca-chrome 驱动成功,那么赶紧来试验下是否真正支持 chrome web 浏览器网页测试了呢.
大家看到 改为 porps.put("browserName", "chrome"); 后就 OK 啦. 我运行的是 java 版本.
那这个问题就没有解决方案,无法执行跑 web 浏览器类型的脚本了吗?
询问官方作者后,建议使用 electron 也就是
nodejs 里 改为 browserName: 'electron'
或 java 里 改为 porps.put("browserName", "electron");
那什么是 electron? electron 基于 chromium 的,提供了一个实时构建桌面应用的纯 JavaScript 环境。
好像看些资料搞 nodejs 环境的开发人士,会大量使用 electron 来进行开发。
然后这里又有坑了,既然官方说 win 环境下 electron 的样例是可以执行成功的,那为何我 down 下来的样例,改为 electron 是失败的呢?
这才是我当初改为 chrome 的原因。
折腾来折腾去,就是执行报错。没办法,老方法,卸载掉再重新安装一次。
D:\macaca\macaca-test-sample-master>npm uninstall macaca-electron -g
D:\macaca\macaca-test-sample-master>npm i macaca-electron -g
> electron-prebuilt@0.37.8 postinstall D:\nodejs\node-global\node_modules\macaca-electron\node_modules\electron-prebuilt
> node install.js
Downloading electron-v0.37.8-win32-x64.zip
[=======================> ] 55.1% of 49.65 MB (33.5 kB/s)
Downloading electron-v0.37.8-win32-x64.zip
[============================================>] 100.0% of 49.65 MB (28.73 kB/s)
D:\nodejs\node-global
`-- macaca-electron@1.1.4
+-- co@4.6.0
+-- driver-base@0.1.1
+-- electron-prebuilt@0.37.8
| +-- electron-download@2.2.1
| | +-- debug@2.2.0
| | | `-- ms@0.7.1
| | +-- home-path@1.0.3
| | +-- minimist@1.2.0
| | +-- mkdirp@0.5.1
| | | `-- minimist@0.0.8
| | +-- mv@2.1.1
| | | +-- ncp@2.0.0
| | | `-- rimraf@2.4.5
| | | `-- glob@6.0.4
| | +-- nugget@1.6.2
| | | +-- pretty-bytes@1.0.4
| | | | +-- get-stdin@4.0.1
| | | | `-- meow@3.7.0
| | | | +-- camelcase-keys@2.1.0
| | | | | `-- camelcase@2.1.1
| | | | +-- decamelize@1.2.0
| | | | +-- loud-rejection@1.6.0
| | | | | +-- currently-unhandled@0.4.1
| | | | | | `-- array-find-index@1.0.2
| | | | | `-- signal-exit@3.0.1
| | | | +-- map-obj@1.0.1
| | | | +-- normalize-package-data@2.3.5
| | | | | +-- hosted-git-info@2.1.5
| | | | | +-- is-builtin-module@1.0.0
| | | | | | `-- builtin-modules@1.1.1
| | | | | +-- semver@5.3.0
| | | | | `-- validate-npm-package-license@3.0.1
| | | | | +-- spdx-correct@1.0.2
| | | | | | `-- spdx-license-ids@1.2.2
| | | | | `-- spdx-expression-parse@1.0.4
| | | | +-- object-assign@4.1.0
| | | | +-- read-pkg-up@1.0.1
| | | | | +-- find-up@1.1.2
| | | | | | `-- path-exists@2.1.0
| | | | | `-- read-pkg@1.1.0
| | | | | +-- load-json-file@1.1.0
| | | | | | +-- graceful-fs@4.1.9
| | | | | | +-- parse-json@2.2.0
| | | | | | | `-- error-ex@1.3.0
| | | | | | | `-- is-arrayish@0.2.1
| | | | | | +-- pify@2.3.0
| | | | | | `-- strip-bom@2.0.0
| | | | | | `-- is-utf8@0.2.1
| | | | | `-- path-type@1.1.0
| | | | +-- redent@1.0.0
| | | | | +-- indent-string@2.1.0
| | | | | | `-- repeating@2.0.1
| | | | | | `-- is-finite@1.0.2
| | | | | | `-- number-is-nan@1.0.1
| | | | | `-- strip-indent@1.0.1
| | | | `-- trim-newlines@1.0.0
| | | +-- progress-stream@1.2.0
| | | | +-- speedometer@0.1.4
| | | | `-- through2@0.2.3
| | | | +-- readable-stream@1.1.14
| | | | | `-- isarray@0.0.1
| | | | `-- xtend@2.1.2
| | | | `-- object-keys@0.4.0
| | | +-- request@2.76.0
| | | | +-- aws-sign2@0.6.0
| | | | +-- aws4@1.5.0
| | | | +-- caseless@0.11.0
| | | | +-- combined-stream@1.0.5
| | | | | `-- delayed-stream@1.0.0
| | | | +-- extend@3.0.0
| | | | +-- forever-agent@0.6.1
| | | | +-- form-data@2.1.1
| | | | | `-- asynckit@0.4.0
| | | | +-- har-validator@2.0.6
| | | | | +-- commander@2.9.0
| | | | | | `-- graceful-readlink@1.0.1
| | | | | +-- is-my-json-valid@2.15.0
| | | | | | +-- generate-function@2.0.0
| | | | | | +-- generate-object-property@1.2.0
| | | | | | | `-- is-property@1.0.2
| | | | | | +-- jsonpointer@4.0.0
| | | | | | `-- xtend@4.0.1
| | | | | `-- pinkie-promise@2.0.1
| | | | | `-- pinkie@2.0.4
| | | | +-- hawk@3.1.3
| | | | | +-- boom@2.10.1
| | | | | +-- cryptiles@2.0.5
| | | | | +-- hoek@2.16.3
| | | | | `-- sntp@1.0.9
| | | | +-- http-signature@1.1.1
| | | | | +-- assert-plus@0.2.0
| | | | | +-- jsprim@1.3.1
| | | | | | +-- extsprintf@1.0.2
| | | | | | +-- json-schema@0.2.3
| | | | | | `-- verror@1.3.6
| | | | | `-- sshpk@1.10.1
| | | | | +-- asn1@0.2.3
| | | | | +-- assert-plus@1.0.0
| | | | | +-- bcrypt-pbkdf@1.0.0
| | | | | +-- dashdash@1.14.0
| | | | | | `-- assert-plus@1.0.0
| | | | | +-- ecc-jsbn@0.1.1
| | | | | +-- getpass@0.1.6
| | | | | | `-- assert-plus@1.0.0
| | | | | +-- jodid25519@1.0.2
| | | | | +-- jsbn@0.1.0
| | | | | `-- tweetnacl@0.14.3
| | | | +-- is-typedarray@1.0.0
| | | | +-- isstream@0.1.2
| | | | +-- json-stringify-safe@5.0.1
| | | | +-- mime-types@2.1.12
| | | | | `-- mime-db@1.24.0
| | | | +-- oauth-sign@0.8.2
| | | | +-- qs@6.3.0
| | | | +-- stringstream@0.0.5
| | | | +-- tough-cookie@2.3.2
| | | | | `-- punycode@1.4.1
| | | | `-- tunnel-agent@0.4.3
| | | +-- single-line-log@0.4.1
| | | `-- throttleit@0.0.2
| | +-- path-exists@1.0.0
| | `-- rc@1.1.6
| | +-- deep-extend@0.4.1
| | +-- ini@1.3.4
| | `-- strip-json-comments@1.0.4
| `-- extract-zip@1.5.0
| +-- concat-stream@1.5.0
| | +-- inherits@2.0.3
| | +-- readable-stream@2.0.6
| | | +-- core-util-is@1.0.2
| | | +-- isarray@1.0.0
| | | +-- process-nextick-args@1.0.7
| | | +-- string_decoder@0.10.31
| | | `-- util-deprecate@1.0.2
| | `-- typedarray@0.0.6
| +-- debug@0.7.4
| +-- mkdirp@0.5.0
| | `-- minimist@0.0.8
| `-- yauzl@2.4.1
| `-- fd-slicer@1.0.1
| `-- pend@1.2.0
+-- macaca-utils@0.1.9
| `-- xutil@1.0.2
| +-- ipv4@0.0.4
| +-- lodash@3.10.1
| +-- moment@2.10.6
| +-- node-uuid@1.4.7
| `-- rimraf@2.5.4
| `-- glob@7.1.1
| +-- fs.realpath@1.0.0
| +-- inflight@1.0.6
| | `-- wrappy@1.0.2
| +-- minimatch@3.0.3
| | `-- brace-expansion@1.1.6
| | +-- balanced-match@0.4.2
| | `-- concat-map@0.0.1
| +-- once@1.4.0
| `-- path-is-absolute@1.0.1
+-- selenium-atoms@1.0.2
+-- webdriver-dfn-error-code@1.0.4
`-- xlogger@1.0.5
`-- chalk@1.1.3
+-- ansi-styles@2.2.1
+-- escape-string-regexp@1.0.5
+-- has-ansi@2.0.0
| `-- ansi-regex@2.0.0
+-- strip-ansi@3.0.1
`-- supports-color@2.0.0
咨询作者,原来是这个东西当初在安装的时候应该是 electron-v0.37.8-win32-x64.zip 下载失败的,但是又假性提示安装成功,以及 macaca doctor 都显示正常。
所以,无论你怎样执行,脚本就是报错。真是 macaca 的经典大坑了,“假性安装成功 “我将它命名为这个!!!,大家再遇到莫名的问题,就一定保证安装正常吧,卸载重装 *** 大法好!!!
SO,建议大家可以改用 electron 来测试 web 浏览器网页项目了。官方也建议用 electron。
然后换为自家的项目,nodejs 和 java 版本的都可以执行通过了
PS:补充
chromedriver 与 chrome 的版本也是要相互适宜的,对应关系如下:
chromedriver 版本 支持的 Chrome 版本
所有 chromedriver 均可在下面链接中下载到:
http://chromedriver.storage.googleapis.com/index.html
加上--verbose 看他报错的说的 chrome driver 的路径在哪,然后从上面这个链接下载最新的 chrome driver 的版本,把他替换到你电脑上那个路径的目录下.