【问题标题】:running a command after install dependencies using npm install使用 npm install 安装依赖项后运行命令
【发布时间】:2015-12-11 15:38:26
【问题描述】:

我有一个这样的 package.json 文件

{
  "name": "E2E",
  "version": "1.0.0",
  "description": "AngularJS E2E testing",
  "main": "conf.js",
  "scripts": {
    "postinstall": "node_modules/protractor/bin/webdriver-manager update",
    "test": "echo \"Error: no test specified\" && exit 1"
  },  
  "license": "ISC",
  "devDependencies": {
    "protractor": "^2.2.0"
  }
}

在安装量角器后运行命令npm install时抛出错误

node_modules/protractor/bin/webdriver-manager update
'node_modules' is not recognized as an internal or external command, operable program or batch file

【问题讨论】:

  • 你能告诉我们你在安装依赖项后试图运行什么命令吗?
  • 在命令提示符下我输入 node_modules/protractor/bin/webdriver-manager update
  • 在执行命令webdriver-manager update之前必须先进入文件夹。基于此更新答案。
  • 您是否在 Windows 上运行此命令?如果是这样,check this out

标签: node.js protractor


【解决方案1】:

好的,找到了修复,我需要像这样作为节点命令运行它

"postinstall": "node node_modules/protractor/bin/webdriver-manager update",

【讨论】:

    【解决方案2】:

    尝试在可执行文件的路径前加上一个点,后跟一个斜杠:

     ./node_modules/protractor/bin/webdriver-manager update
    

    【讨论】:

      【解决方案3】:

      问题是在调用该命令之前,您需要位于安装该命令的文件夹中。假设您使用的是 Windows,这可以通过运行一个简单的批处理文件来解决:

      @echo off
      call npm install -g protractor
      call npm install
      cd C:/Users/%USERNAME%/AppData/Roaming/npm/node_modules/protractor/selenium/
      call webdriver-manage update
      

      您应该能够从任何地方运行批处理文件。事实上,整个 Protractor 测试过程可以通过批处理文件实现自动化。您只需将 Grunt、load-grunt-tasks、grunt-protractor-runner、jasime 和 protractor-jasmine2-html-reporter 添加到您的 package.json 中:

      {
          "name": "yourproject",
          "version": "0.0.1",
          "dependencies": { },
          "devDependencies": {
              "grunt": "~0.4.1",
              "load-grunt-tasks": "~1.0.0",
              "grunt-protractor-runner": "~2.1.0",
              "jasmine": "~2.3",
              "protractor-jasmine2-html-reporter": "~0.0.5"
          },
        "engines": {
            "node": ">=0.12.0"
        }
      }
      

      配置 Protractor 并编写一些测试后,您可以使用一个简单的批处理文件调用整个过程:

      @echo off
      cd %CD%
      @echo running tests
      call grunt
      @echo Opening test results in browser
      start "" %CD%\tests\reports\index.html
      

      【讨论】:

        猜你喜欢
        • 2016-03-09
        • 1970-01-01
        • 2016-01-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-12-28
        相关资源
        最近更新 更多