Permalink
Browse files

Add tests for Browser#attach.

  • Loading branch information...
1 parent 1159328 commit 47325e766656a06eb3885d15b92b831a357de709 @jarmo jarmo committed Aug 19, 2012
Showing with 34 additions and 0 deletions.
  1. +34 −0 spec/browser_spec.rb
View
@@ -0,0 +1,34 @@
+require File.expand_path("watirspec/spec_helper", File.dirname(__FILE__))
+
+describe "Browser" do
+ before do
+ browser.goto(WatirSpec.url_for("images.html"))
+ end
+
+ context "#attach" do
+ it "attaches to existing browser by title" do
+ Browser.attach(:title, /Images/).hwnd.should == browser.hwnd
+ end
+
+ it "attaches to existing browser by url" do
+ Browser.attach(:url, /images\.html/).hwnd.should == browser.hwnd
+ end
+
+ it "attaches to existing browser by handle" do
+ Browser.attach(:hwnd, browser.hwnd).hwnd.should == browser.hwnd
+ end
+
+ it "fails with an error if specified browser was not found" do
+ begin
+ original_timeout = browser.class.attach_timeout
+ browser.class.attach_timeout = 0.1
+
+ expect {
+ Browser.attach(:title, "not-existing-window")
+ }.to raise_error(NoMatchingWindowFoundException)
+ ensure
+ browser.class.attach_timeout = original_timeout
+ end
+ end
+ end
+end

0 comments on commit 47325e7

Please sign in to comment.