1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Cypressを触ってみる

1
Last updated at Posted at 2021-06-28

Cypressとは?

Webサービスのテスト用に構築されたJavaScriptライブラリです。

JavaScriptライブラリなので、JavaScriptでテストスクリプトを記述して使用する
オープンソースなので、無料で使える
GoogleChromeのみ対応している
動作が軽い
単体テストからE2Eテストまで広く使える
コマンドごとに画面のスナップショットを見返せる
各種CIとの連携が可能である

環境構築

JavaScriptなので、node.jsを事前にインストールしておきます

Cypressのインストール

Cypressはプロジェクト毎にインストールする必要があるので、インストールしたいディレクトリに移動します。
npm installを実行します。

npm install cypress

Cypressの起動

Cypressの本体はnode_modulesのbinファイルにいるので、それをopenします。

./node_modules/.bin/cypress open

するとCypressの管理画面が起動します。

スクリーンショット 2021-06-28 11.10.42.png

あらかじめいくつかテストスクリプトが用意されているので、
試しに"action.spec.js"を起動します。

別ウインドウでGoogle Chromeが起動し、テストスクリプトが実行されます。

ファイル構成

スクリーンショット 2021-06-28 11.13.41.png

integrationテストのスクリプトはintegrationの中に入っているので、試しにテストスクリプトを書いた"HelloWorld.js"を"integration"内に配置します。

Seleniumとの違いは下記の記事が参考になりました。

1
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?