Amazon web services TestCafe与SAM Local一起工作,但在SAM部署后不工作

Amazon web services TestCafe与SAM Local一起工作,但在SAM部署后不工作,amazon-web-services,testing,aws-lambda,puppeteer,testcafe,Amazon Web Services,Testing,Aws Lambda,Puppeteer,Testcafe,我目前正在尝试设置一个AWS Lambda(nodejs10.x)函数,该函数应该执行一个简单的TestCafe测试 如果我在本地运行Lambda时使用sam local invoke--no event它执行得很好: 2019-12-03T13:39:46.345Z 7b906b79-d7e5-1aa6-edb7-3e749d4e4b08 信息你好世界✓ 我的第一次测试1通过(1s) 2019-12-03T13:39:46.578Z 7b906b79-d7e5-1aa6-edb7-3e749d

我目前正在尝试设置一个AWS Lambda(nodejs10.x)函数,该函数应该执行一个简单的TestCafe测试

如果我在本地运行Lambda时使用
sam local invoke--no event
它执行得很好:

2019-12-03T13:39:46.345Z 7b906b79-d7e5-1aa6-edb7-3e749d4e4b08
信息你好世界✓ 我的第一次测试1通过(1s) 2019-12-03T13:39:46.578Z 7b906b79-d7e5-1aa6-edb7-3e749d4e4b08
信息测试失败:0

在我使用
sam build
sam deploy
部署它之后,它停止工作。它只是在AWS中抛出以下错误:

{
  "errorType": "Runtime.UnhandledPromiseRejection",
  "errorMessage": "Error: Page crashed!",
  "trace": [
    "Runtime.UnhandledPromiseRejection: Error: Page crashed!",
    "    at process.on (/var/runtime/index.js:37:15)",
    "    at process.emit (events.js:203:15)",
    "    at process.EventEmitter.emit (domain.js:448:20)",
    "    at emitPromiseRejectionWarnings (internal/process/promises.js:140:18)",
    "    at process._tickCallback (internal/process/next_tick.js:69:34)"
  ]
}
我的lambda处理器如下所示:

const createTestCafe = require("testcafe");
const chromium = require("chrome-aws-lambda");
let testcafe = null;

exports.lambdaHandler = async (event, context) => {
  const executablePath = await chromium.executablePath;

  await createTestCafe()
    .then(tc => {
      testcafe = tc;
      const runner = testcafe.createRunner();

      return runner
        .src("sample-fixture.js")
        .browsers(
          "puppeteer-core:launch?arg=--no-sandbox&arg=--disable-gpu&arg=--disable-setuid-sandbox&path=" + executablePath
        )
        .run({
          skipJsErrors: true,
          selectorTimeout: 50000
        });
    })
    .then(failedCount => {
      console.log("Tests failed: " + failedCount);
      testcafe.close();
    });

  return {
    statusCode: 200
  };
};
fixture `Getting Started`
    .page `http://devexpress.github.io/testcafe/example`;

test('My first test', async t => {
  console.log('hello world');
});
我的sample-fixture.js如下所示:

const createTestCafe = require("testcafe");
const chromium = require("chrome-aws-lambda");
let testcafe = null;

exports.lambdaHandler = async (event, context) => {
  const executablePath = await chromium.executablePath;

  await createTestCafe()
    .then(tc => {
      testcafe = tc;
      const runner = testcafe.createRunner();

      return runner
        .src("sample-fixture.js")
        .browsers(
          "puppeteer-core:launch?arg=--no-sandbox&arg=--disable-gpu&arg=--disable-setuid-sandbox&path=" + executablePath
        )
        .run({
          skipJsErrors: true,
          selectorTimeout: 50000
        });
    })
    .then(failedCount => {
      console.log("Tests failed: " + failedCount);
      testcafe.close();
    });

  return {
    statusCode: 200
  };
};
fixture `Getting Started`
    .page `http://devexpress.github.io/testcafe/example`;

test('My first test', async t => {
  console.log('hello world');
});
我正在使用以下依赖项:

  • “testcafe”:“^1.7.0”

  • “chrome aws lambda”:“^2.0.1”

  • testcafe浏览器提供程序Puppeter core“^1.1.0”


有人知道为什么我的Lambda函数在我的机器上本地工作,而在AWS上不工作吗?

仅根据这些信息,我目前无法准确地说出来。 我建议您尝试以下方法:

  • 检查数据包部署大小是否小于50 Mb()
  • 检查testcafe浏览器提供程序Puppeter core是否可以在AWS Labmda上运行

因此我能够在AWS lambda中运行testcafe。对我来说,关键是利用Lambda层。()

testcafe it的问题是它是一个巨大的包,它和chrome aws lambda都应该分层部署,因为您可能会超过包大小限制

此外,当testcafe在babel中编译文件时,您可能会在Lambda上遇到速度问题。如果您的文件已编译,则可能会为您的执行增加额外的不必要的时间

希望这有帮助