Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Selenium + Sinon.js

Selenium + Sinon.js

18b12f8f7910445b2637f0f21f59d467?s=128

Kazuhito Hokamura

January 27, 2015
Tweet

Transcript

  1. Selenium + Sinon.js #template_literal_sushi #e2e_sushi

  2. $('button').click(function() { navigator.geolocation.getCurrentPosition( function(res) { var lat = res.coords.latitude; var

    lon = res.coords.longitude; $('#pos').text(lat + ':' + lon); }); });
  3. // stub.js sinon.stub(navigator.geolocation, 'getCurrentPosition') .callsArgWith(0, { coords: { latitude: 10,

    longitude: 20 } });
  4. // sinon.jsͱstubͷεΫϦϓτΛ࣮ߦ driver.executeScript(fs.readFileSync('./sinon.js').toString()); driver.executeScript(fs.readFileSync('./stub.js').toString()); // ςετ࣮ߦ driver.findElement(By.css('button')).click(); driver.findElement(By.css('#pos')).getText().then(function(text) { assert(text

    === '10:20'); });
  5. ଞʹ΋͜͏͍͏έʔεͰ࢖͑Δ͔΋ • खͰ࠶ݱͮ͠Β͍ҟৗܥͷ࠶ݱ • APIϨεϙϯεͷmockԽ

  6. ͨͩ͠΍Γ͗͢Δͱ ࢮ͵ͷͰ஫ҙ