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
とにかくAWS GameDay!AWSは世界の共通言語! / Anyway, AWS GameDay! AWS is the world's lingua franca!
seike460
PRO
1
860
Remix on Hono on Cloudflare Workers
yusukebe
1
280
みんなでプロポーザルを書いてみた
yuriko1211
0
260
Arm移行タイムアタック
qnighy
0
310
OSSで起業してもうすぐ10年 / Open Source Conference 2024 Shimane
furukawayasuto
0
100
詳細解説! ArrayListの仕組みと実装
yujisoftware
0
580
Nurturing OpenJDK distribution: Eclipse Temurin Success History and plan
ivargrimstad
0
880
「今のプロジェクトいろいろ大変なんですよ、app/services とかもあって……」/After Kaigi on Rails 2024 LT Night
junk0612
5
2.1k
AWS IaCの注目アップデート 2024年10月版
konokenj
3
3.3k
NSOutlineView何もわからん:( 前編 / I Don't Understand About NSOutlineView :( Pt. 1
usagimaru
0
330
TypeScriptでライブラリとの依存を限定的にする方法
tutinoko
2
660
CSC509 Lecture 11
javiergs
PRO
0
180
Featured
See All Featured
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.3k
Measuring & Analyzing Core Web Vitals
bluesmoon
4
120
What's new in Ruby 2.0
geeforr
343
31k
Building an army of robots
kneath
302
43k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
0
88
Side Projects
sachag
452
42k
The Cost Of JavaScript in 2023
addyosmani
45
6.7k
A designer walks into a library…
pauljervisheath
203
24k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
Code Review Best Practice
trishagee
64
17k
jQuery: Nuts, Bolts and Bling
dougneiner
61
7.5k
GitHub's CSS Performance
jonrohan
1030
460k
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