LoginSignup
9
9

More than 5 years have passed since last update.

[Ruby] selenium-webdriver で HTML ソースに特定の文字列が含まれているかテストする

Posted at

selenium-webdriver では page_source メソッドを使うと、アクセスしているページの HTML ソースを取得することができます。include マッチャーを使って期待した文字列が HTML ソース内に含まれているか確認します。下記は RSpec のテストコードです。

sample_spec.rb
require 'selenium-webdriver'

describe "qiita.com" do
  before :all do 
    @webdriver = Selenium::WebDriver.for :firefox
  end
  it "includes expected text" do
    expected = "Qiitaは、プログラマのための技術情報共有サービスです。"
    @webdriver.navigate.to "http://qiita.com"
    expect(@webdriver.page_source).to include expected
  end
  after :all do
    @webdriver.quit
  end
end
9
9
4

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
9
9