Last active
December 24, 2015 23:59
-
-
Save kitak/6884047 to your computer and use it in GitHub Desktop.
SeleniumWebDriver(リモートサーバー)+Capybara試してみた。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'capybara/rspec' | |
require 'selenium-webdriver' | |
Capybara.register_driver :remote_firefox do |app| | |
# ブラウザの指定、 | |
# リモートサーバのURLの指定などもできるが今回は省略 | |
# なにも指定しないとFirefox、ローカルホストを指す | |
Capybara::Selenium::Driver.new(app, {browser: :remote}) | |
end | |
Capybara.default_driver = :remote_firefox | |
Capybara.app_host = 'http://www.google.co.jp' | |
RSpec.configure do |config| | |
config.include Capybara::DSL | |
end | |
describe "google" do | |
before do | |
visit '/' | |
end | |
context "トップページ" do | |
it { expect(page).to have_content('Google') } | |
end | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source "https://rubygems.org" | |
gem "selenium-webdriver" | |
gem "capybara" | |
gem "rspec" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'selenium-webdriver' | |
# リモートサーバを指定 | |
driver = Selenium::WebDriver.for :remote | |
# Googleにアクセス | |
driver.navigate.to "http://www.google.co.jp" | |
# HTMLのソースを取得 | |
puts driver.page_source | |
# HTMLページの操作・解析をごにょごにょ | |
driver.quit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment