Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
TestCaféでE2Eテスト!
Search
Azusa Okamoto
May 28, 2022
Programming
0
110
TestCaféでE2Eテスト!
Azusa Okamoto
May 28, 2022
Tweet
Share
More Decks by Azusa Okamoto
See All by Azusa Okamoto
Go初心者が開発やってみた!
azunyan
1
480
デブサミウーマン2023 アウトプットって何が良いの?
azunyan
0
890
TECH WOMAN KANSAIオンラインもくもく会の流れ
azunyan
0
43
個人的に楽しかった実装2022
azunyan
0
92
vanilla-extractを使ってみた!with React
azunyan
1
710
Next.js・microCMSで ポートフォリオサイトを作りかえて学んだこと
azunyan
0
1.9k
VisualStudioCodeの拡張機能を作ってみた!
azunyan
0
36
Other Decks in Programming
See All in Programming
Vue SFCのtemplateでTypeScriptの型を活用しよう
tsukkee
3
230
ポケモンで考えるコミュニケーション / Communication Lessons from Pokémon
mackey0225
5
220
Kubernetes上でOracle_Databaseの運用を楽にするOraOperatorの紹介
nnaka2992
0
170
sqlcを利用してsqlに型付けを
kamiyam
0
250
ML-прайсинг_на_Lamoda__вошли_и_вышли__приключение_на_20_минут__Слава_Цыганков.pdf
lamodatech
0
380
Новый уровень ML-персонализации Lamoda: Как мы усилили ее в каталоге и перенесли на другие продукты
lamodatech
0
380
Subclassing, Composition, Python, and You
hynek
3
190
学生の時に開催したPerl入学式をきっかけにエンジニアが組織に馴染むために勉強会を主催や仲間と参加して職能間の境界を越えていく
ohmori_yusuke
2
320
個人開発で使ってるやつを紹介する回
yohfee
1
730
20241004 モノタロウ式~ドメインモデリングとリアーキテクチャ
monotaro
PRO
2
650
The Efficiency Paradox and How to Save Yourself and the World
hollycummins
0
220
Mercari AI/LLM Hackathon TeamBの発表資料
imaikosuke
0
180
Featured
See All Featured
Build your cross-platform service in a week with App Engine
jlugia
229
18k
Gamification - CAS2011
davidbonilla
80
5k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
92
16k
Adopting Sorbet at Scale
ufuk
73
9k
Docker and Python
trallard
40
3k
Navigating Team Friction
lara
183
14k
Scaling GitHub
holman
458
140k
Code Reviewing Like a Champion
maltzj
519
39k
Making the Leap to Tech Lead
cromwellryan
131
8.9k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
27
1.9k
The Art of Programming - Codeland 2020
erikaheidi
51
13k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
13
1.8k
Transcript
TestCaféでE2Eテスト! あずにゃん 20220528_とにかくほめる!マウントなしのLT会
自己紹介 ・フロントエンドエンジニア ・気づけば、2年目... 【言語】 JavaScript, TypeScript 【FW・ライブラリ】 React, Vue.js @azunyan_eng
今日お話しすること 1. E2Eテストとは? 2. TestCaféとは? 3. 主な使い方 4. 実践! 5.
感想や学び 6. 参考資料
1. E2Eテストとは? 2. TestCaféとは? 3. 主な使い方 4. 実践! 5. 感想や学び
6. 参考資料
E2Eテストとは? システム全体をテストする。 ユーザが利用する時のように、ブラウザ操作をしながら テスト。
1. E2Eテストとは? 3. 主な使い方 4. 実践! 5. 感想や学び 6. 参考資料
2. TestCaféとは?
TestCaféとは? ・E2Eテスト自動化フレームワーク。 ・JavaScript/TypeScriptで記述。 ・複数のブラウザに対応 ・複数のブラウザで同時実行できる。
TestCaféとは? const const homeTab = ( ). ( ). (
); = . ( ). ( ); . ( . ). ( ); tabs homeTab tabs Selector find nth child nth expect eql '#root' 'div' 'a' 'Home' 2 0 awaitt innerText (例)
手動でポチポチ...。 手動の操作不要! TestCaféなし TestCaféあり
1. E2Eテストとは? 2. TestCaféとは? 4. 実践! 5. 感想や学び 6. 参考資料
3. 主な使い方
主な使い方 ①要素関係(取り出してくるなど...) ②テスト関係
innerText value 要素のテキストを取得。 input要素のテキストを 取得。
(例) // innerText // value const const = . (
). ; = . ( ). ; pageTitle pageContents inputForm form $ formName child find 'h1' `input[name=" "]` innerText value { }
getStyleProperty() 要素が持つ、指定したCSSのプロパティの値を取得。
(例) // 背景色を取ってくる。 const = . ( ); activeBG homeTab
getStyleProperty 'background-color'
hasAttribute() その要素が指定した属性を持っているかどうかを返す。
(例) const = . ( ); btnWithDisabled submitBtn hasAttribute 'disabled'
click() 要素をクリックする。
click() (例) const const = ( ). ( ). (
); = . ( ). ( ); . ( ); navTabs formTab navTabs formTab Selector find nth child nth click '#root' 'div' 'a' 2 1 await t
typeText() テキストを入力する。
click() (例) const true . await inputForm form inputForm =
( ); find typeText `input[name="name"]` 'テスト花子' . ( , , : ); t { } replace
eql() notEql() 値が合っているか。 値が異なっているか。
click() (例) // クラス名で指定することも可能 // await t.expect(対象要素).eql(想定している結果); const const =
( ). ( ); = . ( ). ; . ( ). ( ); modal modalText modal modalText Selector child child expect eql '.test-modal' 'div' 'p' 'Modalが出現!!' innerText t await
ok() notOk() 値がtrueであるか。 値がfalseであるか。
click() (例) // ok() // notOk() await await . (
. ( )). (); . ( . ( )). (); t t expect hasAttribute ok expect hasAttribute notOk submitBtn submitBtn 'disabled' 'disabled'
takeScreenshot() スクリーンショットを撮影。 指定したパスに保存される。
click() (例) await . ( : , : ); t
takeScreenshot { 'result/checkHomeTabContents.png' } path fullPage true
1. E2Eテストとは? 2. TestCaféとは? 3. 主な使い方 5. 感想や学び 6. 参考資料
4. 実践!
実践! 表示されている内容や要素が持つ属性などを利用して、 テストしていく!
実践! 〜主なテスト内容〜 ・Homeタブが表示されているか。
実践! 〜主なテスト内容〜 ・Formタブが表示されているか。 ・初期状態で、送信ボタンが無効になっているか。 ・初期値が合っているか。 ・フォームに入力できるか。 ・フォーム入力後、送信ボタンが有効になっているか。
実践! 〜主なテスト内容〜 ・Buttonsタブが表示されているか。 ・モーダルが表示されるか。 ・モーダルを消すことができるか。
動かしてみる!!
1. E2Eテストとは? 2. TestCaféとは? 3. 主な使い方 4. 実践! 6. 参考資料
5. 感想や学び
感想や学び ・「現状」だけでなく、「今後」のことも考慮して要素 を指定! ・色関係や改行ありテキスト判定において、制約がある のになかなか気がつけずて手間取った。 ・画面仕様をじっくり見る機会になり、プロジェクトに 途中から参画しても仕様把握に繋がって助かった!
感想や学び ・コマンドを実行すると、ブラウザが立ち上がって、自 動でテストできるのは便利! ・テストコード作成初心者でも、メソッドを組み合わせ ていくことで問題なく扱えた!
1. E2Eテストとは? 2. TestCaféとは? 3. 主な使い方 4. 実践! 5. 感想や学び
6. 参考資料
参考資料 TestCafé公式ドキュメント
ご清聴ありがとう ございました!