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

Selenium + Sinon.js

Selenium + Sinon.js

Kazuhito Hokamura

January 27, 2015
Tweet

More Decks by Kazuhito Hokamura

Other Decks in Programming

Transcript

  1. Selenium + Sinon.js
    #template_literal_sushi #e2e_sushi

    View full-size slide

  2. $('button').click(function() {
    navigator.geolocation.getCurrentPosition(
    function(res) {
    var lat = res.coords.latitude;
    var lon = res.coords.longitude;
    $('#pos').text(lat + ':' + lon);
    });
    });

    View full-size slide

  3. // stub.js
    sinon.stub(navigator.geolocation, 'getCurrentPosition')
    .callsArgWith(0, {
    coords: {
    latitude: 10,
    longitude: 20
    }
    });

    View full-size slide

  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');
    });

    View full-size slide

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

    View full-size slide

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

    View full-size slide