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
wpceptを使おう
Search
Ippei Sumida
September 19, 2016
Programming
3
650
wpceptを使おう
WordBench京都9月で発表したスライドです。
Ippei Sumida
September 19, 2016
Tweet
Share
More Decks by Ippei Sumida
See All by Ippei Sumida
みんなでQAしてる話
ippey
0
67
AIで生成したものをAIでチェックしてる話
ippey
0
2k
『WordPressコミュニティで学ぶ』OSS貢献の多様性
ippey
0
740
25分で理解する!Symfonyの魅力とその実践的活用法
ippey
1
6.7k
素早いバリュー提供のための DROBEの新戦略
ippey
0
1.3k
Symfony 6.3のおすすめ新機能まとめ
ippey
1
1.8k
PhpStorm + GitHub Copilotはいいぞ
ippey
0
2.4k
それぞれの特徴から考えるフレームワーク選び
ippey
1
890
なるべくJavaScriptを書かないで SymfonyのUIをリッチにする Symfony UX
ippey
1
1.9k
Other Decks in Programming
See All in Programming
非ブラウザランタイムとWeb標準 / Non-Browser Runtimes and Web Standards
petamoriken
0
430
はてなにおけるfujiwara-wareの活用やecspressoのCI/CD構成 / Fujiwara Tech Conference 2025
cohalz
3
2.8k
PHPカンファレンス 2024|共創を加速するための若手の技術挑戦
weddingpark
0
140
令和7年版 あなたが使ってよいフロントエンド機能とは
mugi_uno
10
5.2k
オニオンアーキテクチャを使って、 Unityと.NETでコードを共有する
soi013
0
370
Lookerは可視化だけじゃない。UIコンポーネントもあるんだ!
ymd65536
1
130
PHPとAPI Platformで作る本格的なWeb APIアプリケーション(入門編) / phpcon 2024 Intro to API Platform
ttskch
0
390
生成AIでGitHubソースコード取得して仕様書を作成
shukob
0
630
PSR-15 はあなたのための ものではない? - phpcon2024
myamagishi
0
410
PHPで学ぶプログラミングの教訓 / Lessons in Programming Learned through PHP
nrslib
4
1.1k
「とりあえず動く」コードはよい、「読みやすい」コードはもっとよい / Code that 'just works' is good, but code that is 'readable' is even better.
mkmk884
6
1.4k
月刊 競技プログラミングをお仕事に役立てるには
terryu16
1
1.2k
Featured
See All Featured
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
3
180
Navigating Team Friction
lara
183
15k
Six Lessons from altMBA
skipperchong
27
3.6k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
365
25k
StorybookのUI Testing Handbookを読んだ
zakiyama
28
5.4k
Optimising Largest Contentful Paint
csswizardry
33
3k
Building Your Own Lightsaber
phodgson
104
6.2k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
8
1.2k
Faster Mobile Websites
deanohume
305
30k
A designer walks into a library…
pauljervisheath
205
24k
The World Runs on Bad Software
bkeepers
PRO
66
11k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
Transcript
wpceptΛ͓͏ 2016.09.19 WordBenchژ
ࣗݾհ • ֯ాɹҰฏʢεϛμɹΠοϖΠʣ • ϑϦʔϥϯε • PHP, iOS, AndroidΤϯδχΞ •
CoderDojoຕํओ࠻ • CoderDojoٶɾകాɹੈਓձ
ࣗݾհ @ippey_s ippeisumida
ΞδΣϯμ • wpceptͷલʹ • Codeception • AcceptanceTest
ΞδΣϯμ • wpceptͱʁ • جຊతͳઃఆ • جຊతͳςετͷॻ͖ํ • ςετ࣮ߦ
Codeception
Codeception • PHPͰಈ࡞͢ΔςεςΟϯάϑϨʔϜϫʔΫ • Unit - PHPUnitςετ • Functional -
ػೳςετ • Acceptance - ड͚ೖΕςετɹˡϒϥβςετ • CIͱ࿈ܞՄʂ
Why Codeception? • ຖࢹͰϒϥβͰςετΛߦ͏ͷେม • (WebDriverར༻࣌)ීஈར༻͍ͯ͠ΔϒϥβͰςετͰ͖Δ • ଞͷPCͰ֬ೝ͕Ͱ͖Δ • ϓϥάΠϯɺςʔϚߋ৽࣌ͷఆ֎ͷӨڹʹؾͮ͘͜ͱ͕Ͱ͖
Δ • WordpressຊମΞοϓάϨʔυ࣌ʹ҆৺Ͱ͖Δ
How to install Codeception composer require "codeception/codeception"
How to install Codeception vendor/bin/codecept bootstrap vendor/bin/codecept generate:cept acceptance IndexCept
vendor/bin/codecept generate:cest acceptance IndexCest
Acceptance Test • ϒϥβΛར༻ͨ͠ৼΔ͍ςετΛߦ͏ɻ • ઃఆʹΑΓɺ֤छϒϥβΛར༻Ͱ͖Δɻ • ΥʔλʔϑΥʔϧతʹهड़Ͱ͖ΔCeptɺΫϥεͰهड़Ͱ͖Δ Cest͕͋Δɻ •
ςετ࣮ߦ࣌ʹɺDBΛૢ࡞Ͱ͖Δɻ • ςετͰDBͷૢ࡞͕Ͱ͖ͳ͍ɻ
Acceptance Test • PHPBrowser - PHPͰಈ࡞͢Δ؆қϒϥβɻ JavaScript͕͑ͳ͍ɻ • Phantom.js -
JSͰಈ࡞͢ΔϒϥβɻBasicೝূ͕͑ ͳ͍ɻ • WebDriver - ֤छϒϥβΛར༻͢ΔυϥΠόɻσϑΥ ϧτFirefox
ҙʂ • WebDriver(selenium)ͷόʔδϣϯʹΑͬͯѻ͑ͳ ͍Firefoxͷόʔδϣϯ͕͋Δɻ • Firefoxࣗಈతʹ࠷৽ʹͳΔ͕ɺseleniumࣗ ಈͰ࠷৽ʹͳΒͳ͍ͨΊɺselenium͕ಈ͔ͳ͘ ͳΔɻ
How to write AcceptanceTest /** * ςετϝιου࣮ߦલʹݺΕΔ * @param AcceptanceTester
$I */ public function _before(AcceptanceTester $I) { }
How to write AcceptanceTest /** * ςετϝιου࣮ߦޙʹݺΕΔ * @param AcceptanceTester
$I */ public function _after(AcceptanceTester $I) { }
How to write AcceptanceTest /** * ςετϝιου * @param AcceptanceTester
$I */ public function tryToTest(AcceptanceTester $I) { $this->_notTest($I); }
How to write AcceptanceTest /** * ςετϝιουͰͳ͍߹ϝιου໊ઌ಄ʹͰ”_”Λ͚ͭΔ * @param AcceptanceTester
$I */ public function _notTest(AcceptanceTester $I) { }
How to execute AcceptanceTest vendor/bin/codecept build # શ࣮ߦ vendor/bin/codecept run
acceptance # ࢦఆϑΝΠϧ͚࣮ͩߦ vendor/bin/codecept run acceptance IndexCest
WPCept
wpcept • WordPress༻ʹΧελϚΠζ͞ΕͨCodeception • CodeceptionͰར༻Ͱ͖ͨϝιουʴWP༻ͷϝ ιου
How to install wpcept composer require codeception/codeception --dev composer require
lucatume/wp-browser --dev
How to install Codeception vendor/bin/wpcept bootstrap vendor/bin/wpcept generate:cept acceptance IndexCept
vendor/bin/wpcept generate:cest acceptance IndexCest
Acceptance Test • WPBrowser - PHPͰಈ࡞͢Δ؆қϒϥβɻJavaScript ͕͑ͳ͍ɻ • WPWebDriver(Phantom.js) -
JSͰಈ࡞͢Δϒϥβɻ Basicೝূ͕͑ͳ͍ɻ • WPWebDriver(Selenium) - ֤छϒϥβΛར༻͢Δυ ϥΠόɻσϑΥϧτFirefox
How to configure wpcept • acceptance.suite.ymlͱ͍͏ϑΝΠϧͰઃఆ • Codeceptionͷ߹ͲͷϒϥβΛར༻͢Δ ͔ɺσϑΥϧτͷURLԿ͔ʁͳͲΛઃఆ •
wpceptͷ߹ɺ͜͜ʹwp-adminͷύεɺ ཧऀͷID,PWͳͲΛઃఆͰ͖Δɻ
How to configure wpcept # Codeception Test Suite Configuration #
Suite for WordPress acceptance tests. # Perform tests using or simulating a browser. class_name: AcceptanceTester modules: enabled: - \Helper\Acceptance - WPBrowser: url: 'http://wb-kyoto-201609.local' adminUsername: admin adminPassword: adminp adminPath: /wp-admin acceptance.suite.yml
How to configure wpcept class_name: AcceptanceTester modules: enabled: - \Helper\Acceptance
- WPWebDriver config: WPWebDriver: url: 'http://wb-kyoto-201609.local' browser: 'firefox' window_size: '1024x768' adminUsername: admin adminPassword: adminp adminPath: /wp-admin acceptance.suite.yml
How to configure wpcept env: wpbrowser: modules: enabled: - WPBrowser
disabled: - WPWebDriver config: WPBrowser: url: 'http://wb-kyoto-201609.local' adminUsername: admin adminPassword: adminp adminPath: /wp-admin chrome: modules: config: WPWebDriver: browser: 'chrome' acceptance.suite.yml
How to execute wpcept vendor/bin/wpcept build # શ࣮ߦ vendor/bin/wpcept run
acceptance # ࢦఆϑΝΠϧ͚࣮ͩߦ vendor/bin/wpcept run acceptance IndexCest # ڥΛࢦఆ࣮ͯ͠ߦ vendor/bin/wpcept run acceptance —env=chrome
How to write test case • CodeceptionͷυΩϡϝϯτʹهࡌͷ͋Δϝιο υʴwpceptಠࣗͷϝιουΛར༻ͯ͠ςετΛ هड़ •
ཁૉͷࢦఆXPath, CSS SelectorͰߦ͏ɻ
Commonly Used methods ϝιου උߟ ࢦఆͷϖʔδʹҠಈ *BN0O1BHF l63-z BDDFQUBODFTVJUFZNMʹࢦఆ
ͨ͠63-ʹՃ͞ΕͯΞΫη εɻ ϖʔδʹࢦఆͷจࣈ͕͋Δ͔ *TFF lจࣈྻz *TFF lจࣈྻz lཁૉz *DBO4FF lจࣈྻz DBOΛ͚ͭΔͱݟ͔ͭΒͳ͘ ͯςετ͕ࢭ·Βͳ͍ ϖʔδʹࢦఆͷจࣈ͕ͳ͍͔ *EPOU4FF lจࣈྻz *EPOU4FF lจࣈྻz lཁ ૉz *DBOU4FF lจࣈྻz DBOΛ͚ͭΔͱݟ͔ͭΒͳ͘ ͯςετ͕ࢭ·Βͳ͍ ΫϦοΫ *DMJDL lϩάΠϯz *DMJDL lMPHJOz จࣈྻ 9QBUI $444FMFDUPS Ͱࢦఆ
ϝιου උߟ ςΩετϘοΫεʹॻ͘ *pMM'JFME lOBNFz lWBMVFz *pMM'JFME lOBNFz
lWBMVFz ϑΟʔϧυ໊ 9QBUI $44 4FMFDUPSͰࢦఆ ϥδΦϘλϯબ *DIFDL0QUJPO lOBNFz lWBMVFz *DIFDL0QUJPO lOBNFz lWBMVFz ϑΟʔϧυ໊ 9QBUI $44 4FMFDUPSͰࢦఆ ηϨΫτϘοΫεɺνΣοΫ ϘοΫεબ *TFMFDU0QUJPO lOBNFz lWBMVFz *TFMFDU0QUJPO lOBNFz lWBMVFz ϑΟʔϧυ໊ 9QBUI $44 4FMFDUPSͰࢦఆ Commonly Used methods
ϝιου උߟ ཧϢʔβϩάΠϯ͢Δ *MPHJO"T"ENJO *% 18ઃఆϑΝΠϧʹ ϓϥάΠϯҰཡϖʔδ *BN0O1MVHJOT1BHF
ϓϥάΠϯ༗ޮԽ * BDUJWBUF1MVHJO bQMVHJO4MVH` ϝιουલʹ BN0O1MVHJOT1BHF ΛݺͿ ϓϥάΠϯແޮԽ * EF"DUJWBUF1MVHJO bQMVHJO4M VH` ϝιουલʹ BN0O1MVHJOT1BHF ΛݺͿ ඞཁ͋Γ Commonly Used methods
How to write test case public function indexWithLoginTest(AcceptanceTester $I) {
$I->wantToTest('ϩάΠϯͯ͠Δͱ͖ͷTOPςετ'); $I->loginAsAdmin(); $I->amOnPage("/"); // αΠτͷͲ͔͜ʹ֘ͷจࣈྻ͕͋Δ͔֬ೝ $I->canSee("wb-kyoto-201609"); // CSS SelectorͰࢦఆͯ֘͠ͷจࣈྻ͕͋Δ͔֬ೝ $I->canSee('Just another WordPress site', '#masthead > div > div > p'); // XPathͰࢦఆͯ֘͠ͷจࣈྻ͕͋Δ͔֬ೝ $I->canSee('͜Μʹͪɺadmin ͞Μ !', '//*[@id="wp-admin-bar- my-account"]/a'); }
XPath, CSS Selector • جຊతʹCodeception,wpceptXPath, CSS SelectorΛར༻ͯ͠ཁૉΛऔಘ͠ɺνΣοΫɻ • ͍͔ʹςετʢऔಘʣ͍͢͠Α͏ʹɺHTML, CSSΛ࡞Δ͔͕ॏཁɻ
ͦͦXPathͬͯʁ
XPath XML Path Language ʢXPathʢΤοΫεύεʣʣ ɺϚʔΫΞοϓݴޠ XML ʹ४ڌͨ͠จॻͷಛఆͷ෦Λࢦఆ͢Δݴޠߏจ Ͱ͋Δɻ XPathࣗମ؆ܿͳߏจ
ʢࣜݴޠʣ Ͱ͋ΓɺXMLʹ४ڌͨ͠ϚʔΫΞοϓݴޠͰͳ͍ɻ ඪ४Խஂମ W3C (World Wide Web Consortium) Ͱ։ൃ͞Εɺ199911݄16ʹ XML Path Language (XPath) 1.0 ͕ XSL Transformations (XSLT) 1.0 ͱ ಉ࣌ʹקࠂͱͯ͠ެද͞Εͨ[1][2]ɻ XPathɺXSLT ͱ XSL-FO ͱͱʹελΠϧγʔτٕज़ XSL ͷߏཁૉͱҐஔ͚ͮΒΕͯ ͍Δɻ 20071݄23ɺW3C Ͱ XPath 1.0 ͷ࣍ظόʔδϣϯ੍͕ఆ͞ΕɺXPath 2.0 ͕ XSLT 2.0 ͱಉ࣌ʹקࠂ͞Εͨɻ ·ͨ W3C XPath 2.0 Λ֦ுٕͨ͠ज़ͱͯ͠ XQuery 1.0 Λ։ൃ͠ɺ20071݄23ͷ XPath 2.0 / XSLT 2.0 ͷקࠂͱಉ࣌ʹ XQuery 1.0 ͕קࠂ͞Εͨɻ20144݄8ʹ XPath 3.0 ͕קࠂ͞Εͨɻ XPath 1.0 ͕ެද͞ΕΔͱɺXMLจॻʹର͢Δ؆୯ͳ͍߹Θͤݴޠͱͯ͠ɺٸʹXMLΛѻ͏ιϑτΣΞ։ൃऀ ʢϓϩάϥ Ϛʣ ͨͪʹड͚ೖΕΒΕ͍ͯͬͨɻ ͱͱXPathͷ։ൃɺXSL (XSLT) ͱ XPointer ʹڞ௨͢ΔߏจͱৼΔ͍ͷϞσϧΛ ։ൃ͢Δ͜ͱΛඪͱ͍ͯͨ͠ɻ ࣮ࡍʹXSLTͰɺXMLจॻͷಛఆͷ෦Λࢦఆ͢ΔύλʔϯΛɺXPathΛجʹͨ͠ߏจͰࢦఆ ͢Δɻ ҰൠʹXSLTॲཧܥͷ࣮ɺXPathॲཧܥͷ࣮ΛؚΜͰ͍Δɻ XPath 1.02007ʹ༁͞ΕJIS X 4160ͱͯ͠JISن֨Խ͞Ε͍ͯΔɻ ˞WikipediaΑΓ
Get XPath <div id="page" class="site"> <div class="site-inner"> <a class="skip-link screen-reader-text"
href=“#content”> ίϯςϯπεΩοϓ</a> ←͜͜ //*[@id="page"]/div/a
Get XPath? <section id="meta-2" class="widget widget_meta"><h2 class="widget-title">ϝλใ</ h2> <ul> <li><a
href=“http://wb-kyoto-201609.local/wp-admin/">αΠτཧ</a></li> <li><a href="http://wb-kyoto-201609.local/wp-login.php? action=logout&_wpnonce=c3c4a7821f">ϩάΞτ</a></li> <li><a href="http://wb-kyoto-201609.local/feed/">ߘͷ <abbr title="Really Simple Syndication”>RSS←͜͜ʁ</abbr></a></li> <li><a href="http://wb-kyoto-201609.local/comments/feed/">ίϝϯτͷ <abbr title="Really Simple Syndication">RSS</abbr></a></li> <li><a href="https://ja.wordpress.org/" title="Powered by WordPress, state- of-the-art semantic personal publishing platform.">WordPress.org</a></li> </ul> </section> ??? ※ෳࡶͳHTMLʹͳΔͱେม
None
How to get XPath, CSS Selector
How to get XPath, CSS Selector
How to get XPath, CSS Selector
How to execute wpcept