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
49
AIで生成したものをAIでチェックしてる話
ippey
0
1.9k
『WordPressコミュニティで学ぶ』OSS貢献の多様性
ippey
0
660
25分で理解する!Symfonyの魅力とその実践的活用法
ippey
1
6.4k
素早いバリュー提供のための DROBEの新戦略
ippey
0
1.2k
Symfony 6.3のおすすめ新機能まとめ
ippey
1
1.7k
PhpStorm + GitHub Copilotはいいぞ
ippey
0
2.3k
それぞれの特徴から考えるフレームワーク選び
ippey
1
860
なるべくJavaScriptを書かないで SymfonyのUIをリッチにする Symfony UX
ippey
1
1.8k
Other Decks in Programming
See All in Programming
みんなでプロポーザルを書いてみた
yuriko1211
0
270
What’s New in Compose Multiplatform - A Live Tour (droidcon London 2024)
zsmb
1
480
Why Jakarta EE Matters to Spring - and Vice Versa
ivargrimstad
0
1.1k
Compose 1.7のTextFieldはPOBox Plusで日本語変換できない
tomoya0x00
0
190
A Journey of Contribution and Collaboration in Open Source
ivargrimstad
0
950
OnlineTestConf: Test Automation Friend or Foe
maaretp
0
110
最新TCAキャッチアップ
0si43
0
190
Jakarta EE meets AI
ivargrimstad
0
200
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
0
120
ActiveSupport::Notifications supporting instrumentation of Rails apps with OpenTelemetry
ymtdzzz
1
240
Flutterを言い訳にしない!アプリの使い心地改善テクニック5選🔥
kno3a87
1
190
C++でシェーダを書く
fadis
6
4.1k
Featured
See All Featured
Designing for Performance
lara
604
68k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
329
21k
Embracing the Ebb and Flow
colly
84
4.5k
No one is an island. Learnings from fostering a developers community.
thoeni
19
3k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
26
1.4k
The Straight Up "How To Draw Better" Workshop
denniskardys
232
140k
Fontdeck: Realign not Redesign
paulrobertlloyd
82
5.2k
The Language of Interfaces
destraynor
154
24k
Docker and Python
trallard
40
3.1k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
10
720
Adopting Sorbet at Scale
ufuk
73
9.1k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.1k
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