Electron + WebDriver = Spectron

Dea1add99f4cf942792c0f185aa2f2fd?s=47 Linda_pp
June 09, 2016

Electron + WebDriver = Spectron

Introduction to Spectron; a E2E testing framework for Electron apps

Dea1add99f4cf942792c0f185aa2f2fd?s=128

Linda_pp

June 09, 2016
Tweet

Transcript

  1. &MFDUSPO 8FC%SJWFS 4QFDUSPO .PEFSO8FC"QQ-5 @Linda_pp @rhysd

  2. &MFDUSPO w σεΫτοϓΞϓϦϑϨʔϜϫʔΫGSPN(JU)VC w $ISPNJVNϕʔε /PEFKT

  3. &MFDUSPOΞϓϦ։ൃ༻ΞϓϦ 4QFDUSPO &OEUP&OEςετ ༻ͷςεςΟϯάɹ ϑϨʔϜϫʔΫ $ISPNFESJWFS  XFCESJWFSJP %FWUSPO *1$΍ΠϕϯτΛ؂

    ࢹͰ͖Δ%FW5PPMT ֦ு "1*%FNP"QQ &MFDUSPOͷ֤छ"1* ΛࢼͤΔσϞΞϓϦ
  4. &MFDUSPOΞϓϦ։ൃ༻ΞϓϦ 4QFDUSPO &OEUP&OEςετ ༻ͷςεςΟϯάɹ ϑϨʔϜϫʔΫ $ISPNFESJWFS  XFCESJWFSJP %FWUSPO *1$΍ΠϕϯτΛ

    ؂ࢹͰ͖Δ %FW5PPMT֦ு "1*%FNP"QQ &MFDUSPOͷ֤छ"1* ΛࢼͤΔσϞΞϓϦ
  5. &MFDUSPOΞϓϦͷςετ w ୯ମςετʢ&MFDUSPO"1*΁ͷґଘແ͠ʣ w ϩʔΧϧͷ/PEFKTͰςετʢ৔߹ʹΑͬͯ KTEPNʣ w ୯ମςετʢ&MFDUSPO"1*΁ͷґଘ༗Γʣ w FMFDUSPONPDIBΛ࢖ͬͯ&MFDUSPOͷϓϩηε্ͰςετΛ૸ΒͤΔ

    w IUUQTHJUIVCDPNKQSJDIBSETPOFMFDUSPONPDIB w &OEUP&OEςετ w 4QFDUSPOΛ࢖࣮ͬͯࡍͷΞϓϦΛಈ͔͢ w IUUQTHJUIVCDPNFMFDUSPOTQFDUSPO
  6. σϞʂ w IUUQTHJUIVCDPNSIZTE:PVS'VLVSPV w πΠολʔΫϥΠΞϯτ w 5ZQF4DSJQU BWBKT BTZODBXBJU

  7. 4QFDUSPO w 4QFDUSPODISPNFESJWFS XFCESJWFSJP w DISPNFESJWFSͷηοτΞοϓ΍ΞϓϦଆͷ &MFDUSPO"1*Λୟͨ͘Ίͷϔϧύʔ w ΞϓϦͷQBUIΛࢦఆ͢Δ͚ͩͰ͙͢ςετ͕࢝Ί ΒΕΔ

    w 5SBWJT$*"QQ7FZPSSFBEZ
  8. XFCESJWFSJP w 4FMFOJVN8FC%SJWFSͷ+BWB4DSJQUόΠϯσΟϯ άɽ8FC%SJWFS"1*ܦ༝Ͱϒϥ΢βΛૢ࡞͢Δϥ ΠϒϥϦ w ඪ४ͷ+4όΠϯσΟϯάʹൺ΂ͯ؆ܿʹॻ͚Δ

  9. &MFDUSPO $ISPNJVN 4QFDUSPO XFCESJWFSJP :PVS5FTU $PEF :PVS"QQ w DBQBCJMJUZࣗಈࢦఆ w

    ESJWFSΦϒδΣΫ τ֦ு w 8FC%SJWFS"1* WJBDISPNFESJWFS w NPDIB΍BWBͳͲ Ͱςετ w &MFDUSPO"1*ͷϦ Ϟʔτ࣮ߦ
  10. import test from 'ava'; import {Application} from 'spectron'; test.beforeEach(async t

    => { t.context.app = new Application({ path: '/Applications/MyApp.app/Contents/MacOS/MyApp' }); await t.context.app.start(); }); test.afterEach.always(async t => { await t.context.app.stop(); }); test(async t => { const app = t.context.app; const client = app.client; await client.waitUntilWindowLoaded(); // Electron API (BrowserWindow) const win = app.browserWindow; t.true(await win.isVisible()); // Operate app via WebDriver await client.element('#name-input').keys('my name'); await client.click('#submit-btn'); t.true(await client.waitForExist('#login-success')); });
  11. FMFDUSPOQSFCVJMU ύοέʔδΛ࢖͍͍ͨ࣌ import {Application} from 'spectron'; import * as electron

    from 'electron-prebuilt'; test.beforeEach(async t => { t.context.app = new Application({ path: electron, args: ['/path/to/your/repository'], env: process.env, }); });
  12. HPUP'"*- w ςετ͕GBJMͨ͠ͱ͖ w NBJOϓϩηε΍SFOEFSFSϓϩηεͷϩάΛऩूͯ͠อ ଘ w DMJFOUHFU.BJO1SPDFTT-PHT  w

    DMJFOUHFU3FOEFS1SPDFTT-PHT  w DMJFOUDBQUVSF1BHF ͰεΫϦʔϯγϣοτอଘ w DMJFOUTBWF1BHF Ͱϖʔδͷ)5.-ςΩετΛอଘ
  13. ࠓ೔࿩ͯ͠ͳ͍͜ͱ w ςετέʔεઃܭ w 1BHF0CKFDUύλʔϯʹΑΔ6*ૢ࡞ͷϥΠϒϥϦ Խ w ςετεΫϦϓτͷϝϯςφϯε w ࢓༷มߋʹڧ͍&&ςετεΫϦϓτઃܭ

  14. ·ͱΊ w &MFDUSPOΞϓϦͷ&OEUP&OEςετ͸ 4QFDUSPOͰ؆୯ʹͰ͖Δ @Linda_pp @rhysd