4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

jasmineとselenium-webdriverでシンプルにE2Eテストする

Last updated at Posted at 2017-09-16

用意するもの

  • npm で以下のモジュールをインストールする
    • jasmine
    • selenium-webdriver
  • どうにかしてchromedriverを入手する(Chromeで試したい場合)
    • chromedriverという名前で(windowsだとchromedriver.exeかな?)カレントフォルダに置いておく(ほかにいい感じに管理する方法があれば教えてください・・・!)

こう書く

シンプルに書いています。(ほんとはasync/awaitで書きたいけど)

test.js
var wd = require("selenium-webdriver");

describe("e2e test", function() {
  var driver;
  beforeAll(function () {
    // デフォルトだと、5秒しか待ってくれないので、20秒くらい待たせる
    jasmine.DEFAULT_TIMEOUT_INTERVAL = 20000;
    driver = wd.Builder().forBrowser("chrome").build();
  });
  afterAll(function() {
    driver.quit();
  });

  it("should get google.com", function(done) {
    driver.get("http://google.com")
    .then(function() {
      return driver.findElement(by.id("なんかてきとうに"));
    })
    .then(function(element) {
      return element.getText();
    })
    .then(function(text){
      expect(text).toBe("なんかてきとうに");
    })
    .then(done, done);
  });
});

実行する

jasmine ./test.js

4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?