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
59
AIで生成したものをAIでチェックしてる話
ippey
0
2k
『WordPressコミュニティで学ぶ』OSS貢献の多様性
ippey
0
690
25分で理解する!Symfonyの魅力とその実践的活用法
ippey
1
6.5k
素早いバリュー提供のための DROBEの新戦略
ippey
0
1.3k
Symfony 6.3のおすすめ新機能まとめ
ippey
1
1.7k
PhpStorm + GitHub Copilotはいいぞ
ippey
0
2.4k
それぞれの特徴から考えるフレームワーク選び
ippey
1
880
なるべくJavaScriptを書かないで SymfonyのUIをリッチにする Symfony UX
ippey
1
1.8k
Other Decks in Programming
See All in Programming
14 Years of iOS: Lessons and Key Points
seyfoyun
1
770
42 best practices for Symfony, a decade later
tucksaun
1
180
htmxって知っていますか?次世代のHTML
hiro_ghap1
0
330
LLM Supervised Fine-tuningの理論と実践
datanalyticslabo
3
1.1k
Recoilを剥がしている話
kirik
5
6.6k
命名をリントする
chiroruxx
1
390
Итераторы в Go 1.23: зачем они нужны, как использовать, и насколько они быстрые?
lamodatech
0
700
開発者とQAの越境で自動テストが増える開発プロセスを実現する
92thunder
1
180
Monixと常駐プログラムの勘どころ / Scalaわいわい勉強会 #4
stoneream
0
270
return文におけるstd::moveについて
onihusube
1
920
testcontainers のススメ
sgash708
1
120
ゆるやかにgolangci-lintのルールを強くする / Kyoto.go #56
utgwkk
1
370
Featured
See All Featured
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
48
2.2k
jQuery: Nuts, Bolts and Bling
dougneiner
61
7.5k
Being A Developer After 40
akosma
87
590k
Building Flexible Design Systems
yeseniaperezcruz
327
38k
How to Ace a Technical Interview
jacobian
276
23k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
330
21k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
95
17k
Why Our Code Smells
bkeepers
PRO
335
57k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
45
2.2k
Into the Great Unknown - MozCon
thekraken
33
1.5k
Why You Should Never Use an ORM
jnunemaker
PRO
54
9.1k
Embracing the Ebb and Flow
colly
84
4.5k
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