google-app-engine - Google App Engine标准环境上的 Nightmare 调试

标签 google-app-engine google-cloud-platform nightmare

我正在Google App引擎上做 Nightmare 。我猜这是行不通的。
因此И想添加DEBUG=nightmare,但启动失败。
这是我的package.json

"scripts": {
    "preinstall": "apt-get update && apt-get install -y libfontconfig1 libgtk2.0-0 libgconf-2-4 libasound2 libxtst6 libxss1 libnss3 xvfb && npm install nightmare",
    "deploy": "gcloud app deploy",
    "start": "xvfb-run -a node app.js",
    "lint": "samples lint",
    "pretest": "npm run lint",
    "system-test": "samples test app",
    "test": "npm run system-test",
    "e2e-test": "samples test deploy"
  },
  "dependencies": {
    "express": "4.15.4",
    "nightmare": "2.10.0"
  }
这是错误

Application startup error:

appengine-hello-world@0.0.1 start /app

xvfb-run -a DEBUG=nightmare node app.js
/usr/bin/xvfb-run: 183: /usr/bin/xvfb-run: DEBUG=nightmare: not found npm ERR! file sh

最佳答案

AppEngine标准不支持Node.js。因此,您可能正在Flex环境上运行。
我从[1]开始。请参阅package.json的差异。
我修改了package.json以匹配您的情况,并在app.js中尝试了 Nightmare 。

我可以通过替换来重现您的情况
“start”:“xvfb-run -a node app.js”,
在package.json上通过:

xvfb-run -a DEBUG=nightmare node app.js 

上一个命令的帮助页面显示:
-a        --auto-servernum          try to get a free server number, starting at
                                --server-num
-e FILE   --error-file=FILE         file used to store xauth errors and Xvfb
                                output (default: /dev/null)
-f FILE   --auth-file=FILE          file used to store auth cookie
                                (default: ./.Xauthority)
-h        --help                    display this usage message and exit
-n NUM    --server-num=NUM          server number to use (default: 99)
-l        --listen-tcp              enable TCP port listening in the X server
-p PROTO  --xauth-protocol=PROTO    X authority protocol name to use
                                (default: xauth command's default)
-s ARGS   --server-args=ARGS        arguments (other than server number and
                                "-nolisten tcp") to pass to the Xvfb server
                                (default: "-screen 0 640x480x8")

我看不到有关调试的任何信息...
因此,您可能需要执行以下操作:
xvfb-run -e error.log  -a node app.js 

要保存错误,但我不确定。

我将分享我的配置。

在运行“sudo npm install”之前和之后,我与您分享了此信息:

我补充说:
"preinstall": "apt-get update && apt-get install -y libfontconfig1 libgtk2.0-0 libgconf-2-4 libasound2 libxtst6 libxss1 libnss3 xvfb && npm install nightmare",

并修改:
“start”:“节点app.js”,
到:
“start”:“xvfb-run -a节点app.js”,
before:
{
  "name": "appengine-hello-world",
  "description": "Simple Hello World Node.js sample for Google App Engine Flexible Environment.",
  "version": "0.0.1",
  "private": true,
  "license": "Apache-2.0",
  "author": "Google Inc.",
  "repository": {
    "type": "git",
    "url": "https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git"
  },
  "engines": {
    "node": ">=4.3.2"
  },
  "scripts": {
    "preinstall": "apt-get update && apt-get install -y libfontconfig1 libgtk2.0-0 libgconf-2-4 libasound2 libxtst6 libxss1 libnss3 xvfb && npm install nightmare",
    "deploy": "gcloud app deploy",
    "start": "xvfb-run -a node app.js",
    "lint": "samples lint",
    "pretest": "npm run lint",
    "system-test": "samples test app",
    "test": "npm run system-test",
    "e2e-test": "samples test deploy"
  },
  "dependencies": {
    "express": "4.15.4"
  },
  "devDependencies": {
    "@google-cloud/nodejs-repo-tools": "1.4.17"
  },
  "cloud-repo-tools": {
    "test": {
      "app": {
        "msg": "Hello, world!"
      }
    },
    "requiresKeyFile": true,
    "requiresProjectId": true
  }
}

“npm install”安装后,文件自动更新为:
{
  "name": "appengine-hello-world",
  "description": "Simple Hello World Node.js sample for Google App Engine Flexible Environment.",
  "version": "0.0.1",
  "private": true,
  "license": "Apache-2.0",
  "author": "Google Inc.",
  "repository": {
    "type": "git",
    "url": "https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git"
  },
  "engines": {
    "node": ">=4.3.2"
  },
  "scripts": {
    "preinstall": "apt-get update && apt-get install -y libfontconfig1 libgtk2.0-0 libgconf-2-4 libasound2 libxtst6 libxss1 libnss3 xvfb && npm install nightmare",
    "deploy": "gcloud app deploy",
    "start": "xvfb-run -a node app.js",
    "lint": "samples lint",
    "pretest": "npm run lint",
    "system-test": "samples test app",
    "test": "npm run system-test",
    "e2e-test": "samples test deploy"
  },
  "dependencies": {
    "express": "4.15.4",
    "nightmare": "^2.10.0"
  },
  "devDependencies": {
    "@google-cloud/nodejs-repo-tools": "1.4.17"
  },
  "cloud-repo-tools": {
    "test": {
     "app": {
        "msg": "Hello, world!"
      }
    },
    "requiresKeyFile": true,
    "requiresProjectId": true
  }
}

我正在与 Nightmare 分享一个片段js:
'use strict';
// [START app]
const express = require('express');
const app = express();
const Nightmare = require('nightmare')
app.get('/', (req, res) => {
  Nightmare({show: false})
  .goto('https://google.com')
  .wait('body')
  .insert('input[aria-label="Search"]', 'node-nightmare github.com')
  .click('input[type="submit"]')
  .wait(1000)
  .wait('body')
  .evaluate(function() {
     // return $('a:contains("node-nightmare")').text();
     // res.status(200).send($('a:contains("node-
nightmare")').text()).end();
     console.log('EVALUATE');
  })
  .then(function(ret) {
     console.log('THEN');
     console.log(ret)
  });
  res.status(200).send('Hello, world!!!!!').end();
});
// Start the server
const PORT = process.env.PORT || 8080;
app.listen(PORT, () => {
  console.log(`App listening on port ${PORT}`);
  console.log('Press Ctrl+C to quit.'); 
});
// [END app]

您可以使用以下命令在本地服务器上运行:
npm开始
或通过以下方式部署到App Engine
gcloud应用部署

希望能帮助到你!

[1] https://cloud.google.com/appengine/docs/flexible/nodejs/quickstart

关于google-app-engine - Google App Engine标准环境上的 Nightmare 调试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47913445/

相关文章:

python - Python 2.5 中的类装饰器?

node.js - Google 存储桶文件上传在生产环境中不起作用

通过 Airflow 创建的 Kubernetes pod 保持运行状态

java - 如何使用 Java 检查 Google Cloud Storage 中是否存在文件夹?

javascript - nightmare.js 如何实现类似window.callPhantom() 函数的功能?

node.js - Nightmare 循环

python - Django 1.1 和 Google 应用引擎有稳定的集成程序/插件吗?

google-app-engine - Google Cloud 任务和 Google App Engine Python 3

node.js - 我可以指示nightmare.js转到本地主机上的快速路由吗?

java.security.AccessControlException : access denied ("java.lang.RuntimePermission" "accessClassInPackage.sun.reflect.annotation") Spring