/usr/lib/ruby/vendor_ruby/capybara/spec/session/node_spec.rb is in ruby-capybara 2.2.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 | Capybara::SpecHelper.spec "node" do
before do
@session.visit('/with_html')
end
it "should act like a session object" do
@session.visit('/form')
@form = @session.find(:css, '#get-form')
@form.should have_field('Middle Name')
@form.should have_no_field('Languages')
@form.fill_in('Middle Name', :with => 'Monkey')
@form.click_button('med')
extract_results(@session)['middle_name'].should == 'Monkey'
end
it "should scope CSS selectors" do
@session.find(:css, '#second').should have_no_css('h1')
end
describe "#parent" do
it "should have a reference to its parent if there is one" do
@node = @session.find(:css, '#first')
@node.parent.should == @node.session.document
@node.find(:css, '#foo').parent.should == @node
end
end
describe "#text" do
it "should extract node texts" do
@session.all('//a')[0].text.should == 'labore'
@session.all('//a')[1].text.should == 'ullamco'
end
it "should return document text on /html selector" do
@session.visit('/with_simple_html')
@session.all('/html')[0].text.should == 'Bar'
end
end
describe "#[]" do
it "should extract node attributes" do
@session.all('//a')[0][:class].should == 'simple'
@session.all('//a')[1][:id].should == 'foo'
@session.all('//input')[0][:type].should == 'text'
end
it "should extract boolean node attributes" do
@session.find('//input[@id="checked_field"]')[:checked].should be_true
end
end
describe "#value" do
it "should allow retrieval of the value" do
@session.find('//textarea[@id="normal"]').value.should == 'banana'
end
it "should not swallow extra newlines in textarea" do
@session.find('//textarea[@id="additional_newline"]').value.should == "\nbanana"
end
it "should not swallow leading newlines for set content in textarea" do
@session.find('//textarea[@id="normal"]').set("\nbanana")
@session.find('//textarea[@id="normal"]').value.should == "\nbanana"
end
it "return any HTML content in textarea" do
@session.find('//textarea[1]').set("some <em>html</em> here")
@session.find('//textarea[1]').value.should == "some <em>html</em> here"
end
it "defaults to 'on' for checkbox" do
@session.visit('/form')
@session.find('//input[@id="valueless_checkbox"]').value.should == 'on'
end
it "defaults to 'on' for radio buttons" do
@session.visit('/form')
@session.find('//input[@id="valueless_radio"]').value.should == 'on'
end
end
describe "#set" do
it "should allow assignment of field value" do
@session.first('//input').value.should == 'monkey'
@session.first('//input').set('gorilla')
@session.first('//input').value.should == 'gorilla'
end
it "should fill the field even if the caret was not at the end", :requires => [:js] do
@session.execute_script("var el = document.getElementById('test_field'); el.focus(); el.setSelectionRange(0, 0);")
@session.first('//input').set('')
@session.first('//input').value.should == ''
end
it "should not set if the text field is readonly" do
@session.first('//input[@readonly]').value.should == 'should not change'
@session.first('//input[@readonly]').set('changed')
@session.first('//input[@readonly]').value.should == 'should not change'
end
it "should not set if the textarea is readonly" do
@session.first('//textarea[@readonly]').value.should == 'textarea should not change'
@session.first('//textarea[@readonly]').set('changed')
@session.first('//textarea[@readonly]').value.should == 'textarea should not change'
end
it 'should allow me to change the contents of a contenteditable element', :requires => [:js] do
@session.visit('/with_js')
@session.find(:css,'#existing_content_editable').set('WYSIWYG')
@session.find(:css,'#existing_content_editable').text.should == 'WYSIWYG'
end
it 'should allow me to set the contents of a contenteditable element', :requires => [:js] do
@session.visit('/with_js')
@session.find(:css,'#blank_content_editable').set('WYSIWYG')
@session.find(:css,'#blank_content_editable').text.should == 'WYSIWYG'
end
it 'should allow me to change the contents of a contenteditable elements child', :requires => [:js] do
pending "Selenium doesn't like editing nested contents"
@session.visit('/with_js')
@session.find(:css,'#existing_content_editable_child').set('WYSIWYG')
@session.find(:css,'#existing_content_editable_child').text.should == 'WYSIWYG'
end
end
describe "#tag_name" do
it "should extract node tag name" do
@session.all('//a')[0].tag_name.should == 'a'
@session.all('//a')[1].tag_name.should == 'a'
@session.all('//p')[1].tag_name.should == 'p'
end
end
describe "#disabled?" do
it "should extract disabled node" do
@session.visit('/form')
@session.find('//input[@id="customer_name"]').should be_disabled
@session.find('//input[@id="customer_email"]').should_not be_disabled
end
it "should see disabled options as disabled" do
@session.visit('/form')
@session.find('//select[@id="form_title"]/option[1]').should_not be_disabled
@session.find('//select[@id="form_title"]/option[@disabled]').should be_disabled
end
it "should see enabled options in disabled select as disabled" do
@session.visit('/form')
@session.find('//select[@id="form_disabled_select"]/option').should be_disabled
@session.find('//select[@id="form_title"]/option[1]').should_not be_disabled
end
end
describe "#visible?" do
it "should extract node visibility" do
Capybara.ignore_hidden_elements = false
@session.first('//a').should be_visible
@session.find('//div[@id="hidden"]').should_not be_visible
@session.find('//div[@id="hidden_via_ancestor"]').should_not be_visible
@session.find('//div[@id="hidden_attr"]').should_not be_visible
@session.find('//a[@id="hidden_attr_via_ancestor"]').should_not be_visible
end
end
describe "#checked?" do
it "should extract node checked state" do
@session.visit('/form')
@session.find('//input[@id="gender_female"]').should be_checked
@session.find('//input[@id="gender_male"]').should_not be_checked
@session.first('//h1').should_not be_checked
end
end
describe "#selected?" do
it "should extract node selected state" do
@session.visit('/form')
@session.find('//option[@value="en"]').should be_selected
@session.find('//option[@value="sv"]').should_not be_selected
@session.first('//h1').should_not be_selected
end
end
describe "#==" do
it "preserve object identity" do
(@session.find('//h1') == @session.find('//h1')).should be_true
(@session.find('//h1') === @session.find('//h1')).should be_true
(@session.find('//h1').eql? @session.find('//h1')).should be_false
end
it "returns false for unrelated object" do
(@session.find('//h1') == "Not Capybara::Node::Base").should be_false
end
end
describe "#trigger", :requires => [:js, :trigger] do
it "should allow triggering of custom JS events" do
@session.visit('/with_js')
@session.find(:css, '#with_focus_event').trigger(:focus)
@session.should have_css('#focus_event_triggered')
end
end
describe '#drag_to', :requires => [:js, :drag] do
it "should drag and drop an object" do
@session.visit('/with_js')
element = @session.find('//div[@id="drag"]')
target = @session.find('//div[@id="drop"]')
element.drag_to(target)
@session.find('//div[contains(., "Dropped!")]').should_not be_nil
end
end
describe '#hover', :requires => [:hover] do
it "should allow hovering on an element" do
@session.visit('/with_hover')
@session.find(:css,'.hidden_until_hover', :visible => false).should_not be_visible
@session.find(:css,'.wrapper').hover
@session.find(:css, '.hidden_until_hover', :visible => false).should be_visible
end
end
describe '#reload', :requires => [:js] do
context "without automatic reload" do
before { Capybara.automatic_reload = false }
it "should reload the current context of the node" do
@session.visit('/with_js')
node = @session.find(:css, '#reload-me')
@session.click_link('Reload!')
sleep(0.3)
node.reload.text.should == 'has been reloaded'
node.text.should == 'has been reloaded'
end
it "should reload a parent node" do
@session.visit('/with_js')
node = @session.find(:css, '#reload-me').find(:css, 'em')
@session.click_link('Reload!')
sleep(0.3)
node.reload.text.should == 'has been reloaded'
node.text.should == 'has been reloaded'
end
it "should not automatically reload" do
@session.visit('/with_js')
node = @session.find(:css, '#reload-me')
@session.click_link('Reload!')
sleep(0.3)
expect { node.text.to == 'has been reloaded' }.to raise_error
end
after { Capybara.automatic_reload = true }
end
context "with automatic reload" do
it "should reload the current context of the node automatically" do
@session.visit('/with_js')
node = @session.find(:css, '#reload-me')
@session.click_link('Reload!')
sleep(0.3)
node.text.should == 'has been reloaded'
end
it "should reload a parent node automatically" do
@session.visit('/with_js')
node = @session.find(:css, '#reload-me').find(:css, 'em')
@session.click_link('Reload!')
sleep(0.3)
node.text.should == 'has been reloaded'
end
it "should reload a node automatically when using find" do
@session.visit('/with_js')
node = @session.find(:css, '#reload-me')
@session.click_link('Reload!')
sleep(0.3)
node.find(:css, 'a').text.should == 'has been reloaded'
end
it "should not reload nodes which haven't been found" do
@session.visit('/with_js')
node = @session.all(:css, '#the-list li')[1]
@session.click_link('Fetch new list!')
sleep(0.3)
expect { node.text.to == 'Foo' }.to raise_error
expect { node.text.to == 'Bar' }.to raise_error
end
it "should reload nodes with options" do
@session.visit('/with_js')
node = @session.find(:css, 'em', :text => "reloaded")
@session.click_link('Reload!')
sleep(1)
node.text.should == 'has been reloaded'
end
end
end
end
|