LoginSignup
2
0

More than 3 years have passed since last update.

Cypressのheadlessモードでlogを表示させる

Posted at

ローカルではうまく動くのにサーバに持っていったheadlessモードでうまく動かなくてなんで?と思いデバッグしようと思ってconsole.logcy.logを突っ込んでも何も出力してくれなくて困ったんですが、こうすればheadlessモードでもcy.logでログが表示されてウハウハです!

cypress/support/index.js と  cypress/plugins/index.jsの2つのファイルを触る必要があります。

cypress/support/index.js
Cypress.Commands.overwrite("log", (subject, message) =>
  cy.task("log", message)
);
cypress/plugins/index.js
module.exports = (on, config) => {}
  on("task", {
    log(message) {
      console.log(message);
      return null;
    },
  });
};

この2点を追加するだけで、cy.logでログがバリバリでてきます!

私はDockerから渡している環境変数がうまく渡せいないの原因でした。ログがなかったら発見するのにもっと時間がかかっていた思います。

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0