マニュアル: Selenium WebDriver

投稿日: 更新日:

API

ドライバ

Google Chrome

Mozilla Firefox

以下のような場合を想定。

  • ファイルダウンロード時に確認ダイアログを出さない(blob)
  • プロファイルのパスを指定(Cookieを使用したいため)

Gebを使った例を載せておきます。

System.setProperty('webdriver.gecko.driver', 'path/to/geckodriver')

environments {
    firefox {
        driver = {
            FirefoxOptions options = new FirefoxOptions()
            FirefoxProfile profile = new FirefoxProfile(new File("/path/to/profile"))
            profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/octet-stream")
            options.setProfile(profile)
            new FirefoxDriver(options)
        }
    }
}

Microsoft Edge

Page Objectパターン

ページをオブジェクトとして考えるデザインパターンです。

同じページに対して、正常ケースとエラーケースで結果が異なる場合の扱い

PageObjectsによれば、Summaryとして以下の6点が書かれている。

  1. The public methods represent the services that the page offers
  2. Try not to expose the internals of the page
  3. Generally don’t make assertions
  4. Methods return other PageObjects
  5. Need not represent an entire page
  6. Different results for the same action are modelled as different methods

よって、メソッドはPageObjectsを返して、Assertionは呼び出し元で行うべき。