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
ブラウザ単体でmp4書き出すまで - muddy-web - 2024-12
yue4u
3
470
PHPUnitしか使ってこなかった 一般PHPerがPestに乗り換えた実録
mashirou1234
0
190
なまけものオバケたち -PHP 8.4 に入った新機能の紹介-
tanakahisateru
1
120
これでLambdaが不要に?!Step FunctionsのJSONata対応について
iwatatomoya
2
3.7k
バグを見つけた?それAppleに直してもらおう!
uetyo
0
180
[JAWS-UG横浜 #76] イケてるアップデートを宇宙いち早く紹介するよ!
maroon1st
0
460
CSC305 Lecture 26
javiergs
PRO
0
140
コンテナをたくさん詰め込んだシステムとランタイムの変化
makihiro
1
130
Spatial Rendering for Apple Vision Pro
warrenm
0
110
PHPで作るWebSocketサーバー ~リアクティブなアプリケーションを知るために~ / WebSocket Server in PHP - To know reactive applications
seike460
PRO
2
380
17年周年のWebアプリケーションにTanStack Queryを導入する / Implementing TanStack Query in a 17th Anniversary Web Application
saitolume
0
250
Amazon S3 NYJavaSIG 2024-12-12
sullis
0
100
Featured
See All Featured
Stop Working from a Prison Cell
hatefulcrawdad
267
20k
How to train your dragon (web standard)
notwaldorf
88
5.7k
Docker and Python
trallard
42
3.1k
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
6.9k
Large-scale JavaScript Application Architecture
addyosmani
510
110k
The World Runs on Bad Software
bkeepers
PRO
65
11k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
247
1.3M
No one is an island. Learnings from fostering a developers community.
thoeni
19
3k
Producing Creativity
orderedlist
PRO
341
39k
Optimizing for Happiness
mojombo
376
70k
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