File: within_window_spec.rb

package info (click to toggle)
ruby-capybara 2.2.1-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 948 kB
  • ctags: 516
  • sloc: ruby: 7,998; makefile: 4
file content (45 lines) | stat: -rw-r--r-- 1,744 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
Capybara::SpecHelper.spec '#within_window', :requires => [:windows] do
  before(:each) do
    @session.visit('/within_popups')
  end
  after(:each) do
    @session.within_window("firstPopup") do
      @session.evaluate_script('window.close()')
    end
    @session.within_window("secondPopup") do
      @session.evaluate_script('window.close()')
    end
  end

  it "should find the div in firstPopup" do
    @session.within_window("firstPopup") do
      @session.find("//*[@id='divInPopupOne']").text.should eql 'This is the text of divInPopupOne'
    end
  end
  it "should find the div in secondPopup" do
    @session.within_window("secondPopup") do
      @session.find("//*[@id='divInPopupTwo']").text.should eql 'This is the text of divInPopupTwo'
    end
  end
  it "should find the divs in both popups" do
    @session.within_window("secondPopup") do
      @session.find("//*[@id='divInPopupTwo']").text.should eql 'This is the text of divInPopupTwo'
    end
    @session.within_window("firstPopup") do
      @session.find("//*[@id='divInPopupOne']").text.should eql 'This is the text of divInPopupOne'
    end
  end
  it "should find the div in the main window after finding a div in a popup" do
    @session.within_window("secondPopup") do
      @session.find("//*[@id='divInPopupTwo']").text.should eql 'This is the text of divInPopupTwo'
    end
    @session.find("//*[@id='divInMainWindow']").text.should eql 'This is the text for divInMainWindow'
  end
  it "should reset scope when switching windows" do
    @session.within(:css, '#divInMainWindow') do
      @session.within_window("secondPopup") do
        @session.find("//*[@id='divInPopupTwo']").text.should eql 'This is the text of divInPopupTwo'
      end
    end
  end
end