# -*- encoding: UTF-8 -*- require 'spec_helper' require 'capybara/webkit' module TestSessions Webkit = Capybara::Session.new(:reusable_webkit, TestApp) end Capybara::SpecHelper.run_specs TestSessions::Webkit, "webkit" describe Capybara::Session do subject { Capybara::Session.new(:reusable_webkit, @app) } after { subject.reset! } context "slow javascript app" do before(:all) do @app = lambda do |env| body = <<-HTML
Hello
HTML [200, { 'Content-Type' => 'text/html', 'Content-Length' => body.length.to_s }, [body]] end end before do @default_wait_time = Capybara.default_wait_time Capybara.default_wait_time = 1 end after { Capybara.default_wait_time = @default_wait_time } it "waits for a request to load" do subject.visit("/") subject.find_button("Submit").click subject.should have_content("Goodbye"); end end context "simple app" do before(:all) do @app = lambda do |env| body = <<-HTML Hello UTF8文字列 HTML [200, { 'Content-Type' => 'text/html; charset=UTF-8', 'Content-Length' => body.length.to_s }, [body]] end end before do subject.visit("/") end it "inspects nodes" do subject.all(:xpath, "//strong").first.inspect.should include("strong") end it "can read utf8 string" do utf8str = subject.all(:xpath, "//span").first.text utf8str.should eq('UTF8文字列') end it "can click utf8 string" do subject.click_button('ボタン') end end context "response headers with status code" do before(:all) do @app = lambda do |env| params = ::Rack::Utils.parse_query(env['QUERY_STRING']) if params["img"] == "true" body = 'not found' return [404, { 'Content-Type' => 'image/gif', 'Content-Length' => body.length.to_s }, [body]] end body = <<-HTMLWelcome, #{session[:username]}.
HTML end end end it "should not start queued commands more than once" do subject.visit('/') subject.fill_in('username', with: 'admin') subject.fill_in('password', with: 'temp4now') subject.click_button('Submit') subject.visit('/other') subject.should have_content('admin') end end end