【问题标题】:How to write into an Excel file in Protractor如何在 Protractor 中写入 Excel 文件
【发布时间】:2018-07-20 11:59:44
【问题描述】:

我正在使用量角器 5.2.2。我有一个要求 - 将数据写入 excel 文件(我需要将动态变量传递给同一个 excel 文件。也就是说,当我每次运行时,应该将不同的数据集输入到 excel 中,所以我使用了编辑-xlsx)。我为此使用了以下代码。

var EditXlsx = require('edit-xlsx');
var xlsx = new EditXlsx('../files/exl.xlsx');
var sheet = xlsx.sheet(0);
var data = {
title: 'AKIRA'}
sheet.update('A1', 'Title');

但是当我运行量角器脚本时,它显示“错误:找不到模块 'edit-xlsx'”。当我通过命令 'npm install edit-xlsx' 安装了 edit-xlsx 时,它会给出错误并给出下面(我也成功安装了python 2.7)。

F:\frx-automation>npm install edit-xlsx

> libxmljs@0.9.0 install F:\frx-automation\node_modules\libxmljs
> node-gyp rebuild


F:\frx-automation\node_modules\libxmljs>if not defined npm_config_node_gyp (node
"C:\Program Files\nodejs\node_modules\npm\bin\node-gyp- 
bin\\..\..\node_modules\
node-gyp\bin\node-gyp.js" rebuild )  else (node "" rebuild )
gyp ERR! configure error
gyp ERR! stack Error: Can't find Python executable "C:\Program Files 
(x86)\Python37-32\python.EXE", you can set the PYTHON env variable.
gyp ERR! stack     at PythonFinder.failNoPython (C:\Program 
Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\configure.js:483:19)
gyp ERR! stack     at PythonFinder.<anonymous> (C:\Program 
Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\configure.js:508:16)
gyp ERR! stack     at C:\Program 
Files\nodejs\node_modules\npm\node_modules\graceful-fs\polyfills.js:284:29
gyp ERR! stack     at FSReqWrap.oncomplete (fs.js:152:21)
gyp ERR! System Windows_NT 6.3.9600
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Program 
Files\\nodej
s\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd F:\frx-automation\node_modules\libxmljs
gyp ERR! node -v v8.9.3
gyp ERR! node-gyp -v v3.6.2
gyp ERR! not ok
npm WARN protractor-multiple-cucumber-html-reporter-plugin@1.7.0 requires a 
peer of protractor@>= 4.0.0 but none is installed. You must install peer 
dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.4 
(node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for 
fsevents@
1.2.4: wanted {"os":"darwin","arch":"any"} 
(current{"os":"win32","arch":"x64"})

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! libxmljs@0.9.0 install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the libxmljs@0.9.0 install script.
npm ERR! This is probably not a problem with npm. There is likely additional 
logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\CS1027C\AppData\Roaming\npm-cache\_logs\2018- 
020T03_43_13_721Z-debug.log

我错了吗?提前谢谢

【问题讨论】:

  • 所以,请显示错误。未安装此模块 edit-xlsx。您可以在node_modules 文件夹中查看它
  • npm i edit-xlsx 再试一次,可能是间歇性问题。我使用相同的命令并安装了软件包。如果您使用的是 vpn,请尝试使用您自己的代理连接。
  • 我已经尝试过命令“npm i edit-xlsx”,但我没有使用 vpn。我仍然无法安装 npm i edit-xlsx。我在问题中添加了上述错误。

标签: protractor


【解决方案1】:

edit-xlsx 需要 2.5 到 3.0 之间的 python 版本

如果未安装,请使用以下命令将 npm 设置为指向 2.7 版本,然后请从 here 安装正确的版本

npm install --python=python2.7

然后使用

安装edit-xlsx
npm install edit-xlsx

【讨论】:

  • 我已经安装了python2.7,然后是edit-xlsx,但是我仍然得到错误(我在问题中添加了上面的错误)。
  • 你的python环境变量设置为2.7 python exe?检查您是否能够从任何目录运行 python --version 以及输出是什么
  • @Devleena - 我还建议你可以尝试一个新的 xls 插件,它对我有用 用法可以在这里看到 - npmjs.com/package/xlsx C:\>npm install xlsx C:\ npm install xlsx @987654325 @-- printj@1.1.2 +-- cfb@1.0.8 +-- 代码页@1.14.0 | -- commander@2.14.1 +-- commander@2.15.1 +-- crc-32@1.2.0 +-- exit-on-epipe@1.0.1 -- ssf@0.10.2 `-- frac@1.1.2 npm WARN enoent ENOENT: 没有这样的文件或目录,打开 'C:\package.json' npm WARN !invalid#1 没有描述 npm WARN !invalid #1 没有许可证字段。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-08-30
  • 2013-10-14
  • 1970-01-01
  • 2012-01-07
  • 2019-04-12
  • 2011-03-09
  • 1970-01-01
相关资源
最近更新 更多