How to use obscured method of Capybara.Node Package

Best Capybara code snippet using Capybara.Node.obscured

node_spec.rb

Source:node_spec.rb Github

copy

Full Screen

...232 expect(@session).to have_no_css(descendants_css, visible: true)233 .and(have_css(descendants_css, visible: :hidden, count: 3))234 end235 end236 describe '#obscured?', requires: [:css] do237 it 'should see non visible elements as obscured' do238 Capybara.ignore_hidden_elements = false239 expect(@session.find('//div[@id="hidden"]')).to be_obscured240 expect(@session.find('//div[@id="hidden_via_ancestor"]')).to be_obscured241 expect(@session.find('//div[@id="hidden_attr"]')).to be_obscured242 expect(@session.find('//a[@id="hidden_attr_via_ancestor"]')).to be_obscured243 expect(@session.find('//input[@id="hidden_input"]')).to be_obscured244 end245 it 'should see non-overlapped elements as not obscured' do246 @session.visit('/obscured')247 expect(@session.find(:css, '#cover')).not_to be_obscured248 end249 it 'should see elements only overlapped by descendants as not obscured' do250 expect(@session.first(:css, 'p:not(.para)')).not_to be_obscured251 end252 it 'should see elements outside the viewport as obscured' do253 @session.visit('/obscured')254 off = @session.find(:css, '#offscreen')255 off_wrapper = @session.find(:css, '#offscreen_wrapper')256 expect(off).to be_obscured257 expect(off_wrapper).to be_obscured258 @session.scroll_to(off_wrapper)259 expect(off_wrapper).not_to be_obscured260 expect(off).to be_obscured261 off_wrapper.scroll_to(off)262 expect(off).not_to be_obscured263 expect(off_wrapper).not_to be_obscured264 end265 it 'should see overlapped elements as obscured' do266 @session.visit('/obscured')267 expect(@session.find(:css, '#obscured')).to be_obscured268 end269 it 'should be boolean' do270 Capybara.ignore_hidden_elements = false271 expect(@session.first('//a').obscured?).to be false272 expect(@session.find('//div[@id="hidden"]').obscured?).to be true273 end274 it 'should work in frames' do275 @session.visit('/obscured')276 frame = @session.find(:css, '#frameOne')277 @session.within_frame(frame) do278 div = @session.find(:css, '#divInFrameOne')279 expect(div).to be_obscured280 @session.scroll_to div281 expect(div).not_to be_obscured282 end283 end284 it 'should work in nested iframes' do285 @session.visit('/obscured')286 frame = @session.find(:css, '#nestedFrames')287 @session.within_frame(frame) do288 @session.within_frame(:css, '#childFrame') do289 gcframe = @session.find(:css, '#grandchildFrame2')290 @session.within_frame(gcframe) do291 expect(@session.find(:css, '#divInFrameTwo')).to be_obscured292 end293 @session.scroll_to(gcframe)294 @session.within_frame(gcframe) do295 expect(@session.find(:css, '#divInFrameTwo')).not_to be_obscured296 end297 end298 end299 end300 end301 describe '#checked?' do302 it 'should extract node checked state' do303 @session.visit('/form')304 expect(@session.find('//input[@id="gender_female"]')).to be_checked305 expect(@session.find('//input[@id="gender_male"]')).not_to be_checked306 expect(@session.first('//h1')).not_to be_checked307 end308 it 'should be boolean' do309 @session.visit('/form')310 expect(@session.find('//input[@id="gender_female"]').checked?).to be true311 expect(@session.find('//input[@id="gender_male"]').checked?).to be false312 expect(@session.find('//input[@id="no_attr_value_checked"]').checked?).to be true313 end314 end315 describe '#selected?' do316 it 'should extract node selected state' do317 @session.visit('/form')318 expect(@session.find('//option[@value="en"]')).to be_selected319 expect(@session.find('//option[@value="sv"]')).not_to be_selected320 expect(@session.first('//h1')).not_to be_selected321 end322 it 'should be boolean' do323 @session.visit('/form')324 expect(@session.find('//option[@value="en"]').selected?).to be true325 expect(@session.find('//option[@value="sv"]').selected?).to be false326 expect(@session.first('//h1').selected?).to be false327 end328 end329 describe '#==' do330 it 'preserve object identity' do331 expect(@session.find('//h1') == @session.find('//h1')).to be true # rubocop:disable Lint/UselessComparison332 expect(@session.find('//h1') === @session.find('//h1')).to be true # rubocop:disable Style/CaseEquality, Lint/UselessComparison333 expect(@session.find('//h1').eql?(@session.find('//h1'))).to be false334 end335 it 'returns false for unrelated object' do336 expect(@session.find('//h1') == 'Not Capybara::Node::Base').to be false337 end338 end339 describe '#path' do340 # Testing for specific XPaths here doesn't make sense since there341 # are many that can refer to the same element342 before do343 @session.visit('/path')344 end345 it 'returns xpath which points to itself' do346 element = @session.find(:link, 'Second Link')347 expect(@session.find(:xpath, element.path)).to eq(element)348 end349 end350 describe '#trigger', requires: %i[js trigger] do351 it 'should allow triggering of custom JS events' do352 @session.visit('/with_js')353 @session.find(:css, '#with_focus_event').trigger(:focus)354 expect(@session).to have_css('#focus_event_triggered')355 end356 end357 describe '#drag_to', requires: %i[js drag] do358 it 'should drag and drop an object' do359 @session.visit('/with_js')360 element = @session.find('//div[@id="drag"]')361 target = @session.find('//div[@id="drop"]')362 element.drag_to(target)363 expect(@session).to have_xpath('//div[contains(., "Dropped!")]')364 end365 it 'should drag and drop if scrolling is needed' do366 @session.visit('/with_js')367 element = @session.find('//div[@id="drag_scroll"]')368 target = @session.find('//div[@id="drop_scroll"]')369 element.drag_to(target)370 expect(@session).to have_xpath('//div[contains(., "Dropped!")]')371 end372 it 'should drag a link' do373 @session.visit('/with_js')374 link = @session.find_link('drag_link')375 target = @session.find(:id, 'drop')376 link.drag_to target377 expect(@session).to have_xpath('//div[contains(., "Dropped!")]')378 end379 it 'should work with Dragula' do380 @session.visit('/with_dragula')381 @session.within(:css, '#sortable') do382 src = @session.find('div', text: 'Item 1')383 target = @session.find('div', text: 'Item 3')384 src.drag_to target385 expect(@session).to have_content(/Item 2.*Item 1/, normalize_ws: true)386 end387 end388 it 'should work with jsTree' do389 @session.visit('/with_jstree')390 @session.within(:css, '#container') do391 @session.assert_text(/A.*B.*C/m)392 source = @session.find(:css, '#j1_1_anchor')393 target = @session.find(:css, '#j1_2_anchor')394 source.drag_to(target)395 @session.assert_no_text(/A.*B.*C/m)396 @session.assert_text(/B.*C/m)397 end398 end399 context 'HTML5', requires: %i[js html5_drag] do400 it 'should HTML5 drag and drop an object' do401 @session.visit('/with_js')402 element = @session.find('//div[@id="drag_html5"]')403 target = @session.find('//div[@id="drop_html5"]')404 element.drag_to(target)405 expect(@session).to have_xpath('//div[contains(., "HTML5 Dropped string: text/plain drag_html5")]')406 end407 it 'should HTML5 drag and drop an object child' do408 @session.visit('/with_js')409 element = @session.find('//div[@id="drag_html5"]/p')410 target = @session.find('//div[@id="drop_html5"]')411 element.drag_to(target)412 expect(@session).to have_xpath('//div[contains(., "HTML5 Dropped string: text/plain drag_html5")]')413 end414 it 'should set clientX/Y in dragover events' do415 @session.visit('/with_js')416 element = @session.find('//div[@id="drag_html5"]')417 target = @session.find('//div[@id="drop_html5"]')418 element.drag_to(target)419 expect(@session).to have_css('div.log', text: /DragOver with client position: [1-9]\d*,[1-9]\d*/, count: 2)420 end421 it 'should not HTML5 drag and drop on a non HTML5 drop element' do422 @session.visit('/with_js')423 element = @session.find('//div[@id="drag_html5"]')424 target = @session.find('//div[@id="drop_html5"]')425 target.execute_script("$(this).removeClass('drop');")426 element.drag_to(target)427 sleep 1428 expect(@session).not_to have_xpath('//div[contains(., "HTML5 Dropped")]')429 end430 it 'should HTML5 drag and drop when scrolling needed' do431 @session.visit('/with_js')432 element = @session.find('//div[@id="drag_html5_scroll"]')433 target = @session.find('//div[@id="drop_html5_scroll"]')434 element.drag_to(target)435 expect(@session).to have_xpath('//div[contains(., "HTML5 Dropped string: text/plain drag_html5_scroll")]')436 end437 it 'should drag HTML5 default draggable elements' do438 @session.visit('/with_js')439 link = @session.find_link('drag_link_html5')440 target = @session.find(:id, 'drop_html5')441 link.drag_to target442 expect(@session).to have_xpath('//div[contains(., "HTML5 Dropped")]')443 end444 it 'should work with SortableJS' do445 @session.visit('/with_sortable_js')446 @session.within(:css, '#sortable') do447 src = @session.find('div', text: 'Item 1')448 target = @session.find('div', text: 'Item 3')449 src.drag_to target450 expect(@session).to have_content(/Item 3.*Item 1/, normalize_ws: true)451 end452 end453 it 'should drag HTML5 default draggable element child' do454 @session.visit('/with_js')455 source = @session.find_link('drag_link_html5').find(:css, 'p')456 target = @session.find(:id, 'drop_html5')457 source.drag_to target458 expect(@session).to have_xpath('//div[contains(., "HTML5 Dropped")]')459 end460 end461 end462 describe 'Element#drop', requires: %i[js html5_drag] do463 it 'can drop a file' do464 @session.visit('/with_js')465 target = @session.find('//div[@id="drop_html5"]')466 target.drop(467 with_os_path_separators(File.expand_path('../fixtures/capybara.jpg', File.dirname(__FILE__)))468 )469 expect(@session).to have_xpath('//div[contains(., "HTML5 Dropped file: capybara.jpg")]')470 end471 it 'can drop multiple files' do472 @session.visit('/with_js')473 target = @session.find('//div[@id="drop_html5"]')474 target.drop(475 with_os_path_separators(File.expand_path('../fixtures/capybara.jpg', File.dirname(__FILE__))),476 with_os_path_separators(File.expand_path('../fixtures/test_file.txt', File.dirname(__FILE__)))477 )478 expect(@session).to have_xpath('//div[contains(., "HTML5 Dropped file: capybara.jpg")]')479 expect(@session).to have_xpath('//div[contains(., "HTML5 Dropped file: test_file.txt")]')480 end481 it 'can drop strings' do482 @session.visit('/with_js')483 target = @session.find('//div[@id="drop_html5"]')484 target.drop('text/plain' => 'Some dropped text')485 expect(@session).to have_xpath('//div[contains(., "HTML5 Dropped string: text/plain Some dropped text")]')486 end487 it 'can drop multiple strings' do488 @session.visit('/with_js')489 target = @session.find('//div[@id="drop_html5"]')490 target.drop('text/plain' => 'Some dropped text', 'text/url' => 'http://www.google.com')491 expect(@session).to have_xpath('//div[contains(., "HTML5 Dropped string: text/plain Some dropped text")]')492 expect(@session).to have_xpath('//div[contains(., "HTML5 Dropped string: text/url http://www.google.com")]')493 end494 end495 describe '#hover', requires: [:hover] do496 it 'should allow hovering on an element' do497 @session.visit('/with_hover')498 expect(@session.find(:css, '.wrapper:not(.scroll_needed) .hidden_until_hover', visible: false)).not_to be_visible499 @session.find(:css, '.wrapper:not(.scroll_needed)').hover500 expect(@session.find(:css, '.wrapper:not(.scroll_needed) .hidden_until_hover', visible: false)).to be_visible501 end502 it 'should allow hovering on an element that needs to be scrolled into view' do503 @session.visit('/with_hover')504 expect(@session.find(:css, '.wrapper.scroll_needed .hidden_until_hover', visible: false)).not_to be_visible505 @session.find(:css, '.wrapper.scroll_needed').hover506 expect(@session.find(:css, '.wrapper.scroll_needed .hidden_until_hover', visible: false)).to be_visible507 end508 it 'should hover again after following a link and back' do509 @session.visit('/with_hover')510 @session.find(:css, '.wrapper:not(.scroll_needed)').hover511 @session.click_link('Other hover page')512 @session.click_link('Go back')513 @session.find(:css, '.wrapper:not(.scroll_needed)').hover514 expect(@session.find(:css, '.wrapper:not(.scroll_needed) .hidden_until_hover', visible: false)).to be_visible515 end516 end517 describe '#click' do518 it 'should not follow a link if no href' do519 @session.find(:css, '#link_placeholder').click520 expect(@session.current_url).to match(%r{/with_html$})521 end522 it 'should go to the same page if href is blank' do523 @session.find(:css, '#link_blank_href').click524 sleep 1525 expect(@session).to have_current_path('/with_html')526 end527 it 'should be able to check a checkbox' do528 @session.visit('form')529 cbox = @session.find(:checkbox, 'form_terms_of_use')530 expect(cbox).not_to be_checked531 cbox.click532 expect(cbox).to be_checked533 end534 it 'should be able to uncheck a checkbox' do535 @session.visit('/form')536 cbox = @session.find(:checkbox, 'form_pets_dog')537 expect(cbox).to be_checked538 cbox.click539 expect(cbox).not_to be_checked540 end541 it 'should be able to select a radio button' do542 @session.visit('/form')543 radio = @session.find(:radio_button, 'gender_male')544 expect(radio).not_to be_checked545 radio.click546 expect(radio).to be_checked547 end548 it 'should allow modifiers', requires: [:js] do549 @session.visit('/with_js')550 @session.find(:css, '#click-test').click(:shift)551 expect(@session).to have_link('Has been shift clicked')552 end553 it 'should allow multiple modifiers', requires: [:js] do554 @session.visit('with_js')555 @session.find(:css, '#click-test').click(:control, :alt, :meta, :shift)556 # Selenium with Chrome on OSX ctrl-click generates a right click so just verify all keys but not click type557 expect(@session).to have_link('alt control meta shift')558 end559 it 'should allow to adjust the click offset', requires: [:js] do560 @session.visit('with_js')561 @session.find(:css, '#click-test').click(x: 5, y: 5)562 link = @session.find(:link, 'has-been-clicked')563 locations = link.text.match(/^Has been clicked at (?<x>[\d\.-]+),(?<y>[\d\.-]+)$/)564 # Resulting click location should be very close to 0, 0 relative to top left corner of the element, but may not be exact due to565 # integer/float conversions and rounding.566 expect(locations[:x].to_f).to be_within(1).of(5)567 expect(locations[:y].to_f).to be_within(1).of(5)568 end569 it 'should raise error if both x and y values are not passed' do570 @session.visit('with_js')571 el = @session.find(:css, '#click-test')572 expect { el.click(x: 5) }.to raise_error ArgumentError573 expect { el.click(x: nil, y: 3) }.to raise_error ArgumentError574 end575 it 'should be able to click a table row', requires: [:js] do576 @session.visit('/tables')577 tr = @session.find(:css, '#agent_table tr:first-child').click578 expect(tr).to have_css('label', text: 'Clicked')579 end580 it 'should retry clicking', requires: [:js] do581 @session.visit('/animated')582 obscured = @session.find(:css, '#obscured')583 @session.execute_script <<~JS584 setTimeout(function(){ $('#cover').hide(); }, 700)585 JS586 expect { obscured.click }.not_to raise_error587 end588 it 'should allow to retry longer', requires: [:js] do589 @session.visit('/animated')590 obscured = @session.find(:css, '#obscured')591 @session.execute_script <<~JS592 setTimeout(function(){ $('#cover').hide(); }, 3000)593 JS594 expect { obscured.click(wait: 4) }.not_to raise_error595 end596 it 'should not retry clicking when wait is disabled', requires: [:js] do597 @session.visit('/animated')598 obscured = @session.find(:css, '#obscured')599 @session.execute_script <<~JS600 setTimeout(function(){ $('#cover').hide(); }, 2000)601 JS602 expect { obscured.click(wait: 0) }.to(raise_error { |e| expect(e).to be_an_invalid_element_error(@session) })603 end604 context 'offset', requires: [:js] do605 before do606 @session.visit('/offset')607 @clicker = @session.find(:id, 'clicker')608 end609 context 'when w3c_click_offset is false' do610 before do611 Capybara.w3c_click_offset = false612 end613 it 'should offset from top left of element' do614 @clicker.click(x: 10, y: 5)615 expect(@session).to have_text(/clicked at 110,105/)616 end617 it 'should offset outside the element' do618 @clicker.click(x: -15, y: -10)619 expect(@session).to have_text(/clicked at 85,90/)620 end621 it 'should default to click the middle' do622 @clicker.click623 expect(@session).to have_text(/clicked at 150,150/)624 end625 end626 context 'when w3c_click_offset is true' do627 before do628 Capybara.w3c_click_offset = true629 end630 it 'should offset from center of element' do631 @clicker.click(x: 10, y: 5)632 expect(@session).to have_text(/clicked at 160,155/)633 end634 it 'should offset outside from center of element' do635 @clicker.click(x: -65, y: -60)636 expect(@session).to have_text(/clicked at 85,90/)637 end638 it 'should default to click the middle' do639 @clicker.click640 expect(@session).to have_text(/clicked at 150,150/)641 end642 end643 end644 end645 describe '#double_click', requires: [:js] do646 it 'should double click an element' do647 @session.visit('/with_js')648 @session.find(:css, '#click-test').double_click649 expect(@session.find(:css, '#has-been-double-clicked')).to be_truthy650 end651 it 'should allow modifiers', requires: [:js] do652 @session.visit('/with_js')653 @session.find(:css, '#click-test').double_click(:alt)654 expect(@session).to have_link('Has been alt double clicked')655 end656 it 'should allow to adjust the offset', requires: [:js] do657 @session.visit('with_js')658 @session.find(:css, '#click-test').double_click(x: 10, y: 5)659 link = @session.find(:link, 'has-been-double-clicked')660 locations = link.text.match(/^Has been double clicked at (?<x>[\d\.-]+),(?<y>[\d\.-]+)$/)661 # Resulting click location should be very close to 10, 5 relative to top left corner of the element, but may not be exact due662 # to integer/float conversions and rounding.663 expect(locations[:x].to_f).to be_within(1).of(10)664 expect(locations[:y].to_f).to be_within(1).of(5)665 end666 it 'should retry clicking', requires: [:js] do667 @session.visit('/animated')668 obscured = @session.find(:css, '#obscured')669 @session.execute_script <<~JS670 setTimeout(function(){ $('#cover').hide(); }, 700)671 JS672 expect { obscured.double_click }.not_to raise_error673 end674 context 'offset', requires: [:js] do675 before do676 @session.visit('/offset')677 @clicker = @session.find(:id, 'clicker')678 end679 context 'when w3c_click_offset is false' do680 before do681 Capybara.w3c_click_offset = false682 end683 it 'should offset from top left of element' do684 @clicker.double_click(x: 10, y: 5)685 expect(@session).to have_text(/clicked at 110,105/)686 end687 it 'should offset outside the element' do688 @clicker.double_click(x: -15, y: -10)689 expect(@session).to have_text(/clicked at 85,90/)690 end691 it 'should default to click the middle' do692 @clicker.double_click693 expect(@session).to have_text(/clicked at 150,150/)694 end695 end696 context 'when w3c_click_offset is true' do697 before do698 Capybara.w3c_click_offset = true699 end700 it 'should offset from center of element' do701 @clicker.double_click(x: 10, y: 5)702 expect(@session).to have_text(/clicked at 160,155/)703 end704 it 'should offset outside from center of element' do705 @clicker.double_click(x: -65, y: -60)706 expect(@session).to have_text(/clicked at 85,90/)707 end708 it 'should default to click the middle' do709 @clicker.double_click710 expect(@session).to have_text(/clicked at 150,150/)711 end712 end713 end714 end715 describe '#right_click', requires: [:js] do716 it 'should right click an element' do717 @session.visit('/with_js')718 @session.find(:css, '#click-test').right_click719 expect(@session.find(:css, '#has-been-right-clicked')).to be_truthy720 end721 it 'should allow modifiers', requires: [:js] do722 @session.visit('/with_js')723 @session.find(:css, '#click-test').right_click(:meta)724 expect(@session).to have_link('Has been meta right clicked')725 end726 it 'should allow to adjust the offset', requires: [:js] do727 @session.visit('with_js')728 @session.find(:css, '#click-test').right_click(x: 10, y: 10)729 link = @session.find(:link, 'has-been-right-clicked')730 locations = link.text.match(/^Has been right clicked at (?<x>[\d\.-]+),(?<y>[\d\.-]+)$/)731 # Resulting click location should be very close to 10, 10 relative to top left corner of the element, but may not be exact due732 # to integer/float conversions and rounding733 expect(locations[:x].to_f).to be_within(1).of(10)734 expect(locations[:y].to_f).to be_within(1).of(10)735 end736 it 'should retry clicking', requires: [:js] do737 @session.visit('/animated')738 obscured = @session.find(:css, '#obscured')739 @session.execute_script <<~JS740 setTimeout(function(){ $('#cover').hide(); }, 700)741 JS742 expect { obscured.right_click }.not_to raise_error743 end744 context 'offset', requires: [:js] do745 before do746 @session.visit('/offset')747 @clicker = @session.find(:id, 'clicker')748 end749 context 'when w3c_click_offset is false' do750 before do751 Capybara.w3c_click_offset = false752 end753 it 'should offset from top left of element' do754 @clicker.right_click(x: 10, y: 5)755 expect(@session).to have_text(/clicked at 110,105/)756 end...

Full Screen

Full Screen

obscured

Using AI Code Generation

copy

Full Screen

1 evaluate_script("$(arguments[0]).is(':visible') && $(arguments[0]).css('visibility') != 'hidden' && $(arguments[0]).css('opacity') != 0", self)2 config.allow_url("www.google.com")3 visit("/")4 puts page.all("a").first._obscured?5puts page.all("a").first._obscured?

Full Screen

Full Screen

obscured

Using AI Code Generation

copy

Full Screen

1 Capybara::Node::Element.instance_method(:visible?).bind(self).call2 Capybara::Node::Element.instance_method(:visible?).bind(self).call3 Capybara::Node::Element.instance_method(:visible?).bind(self).call4 Capybara::Node::Element.instance_method(:visible?).bind(self).call5 Capybara::Node::Element.instance_method(:visible?).bind(self).call6 Capybara::Node::Element.instance_method(:visible?).bind(self).call7 Capybara::Node::Element.instance_method(:visible?).bind(self).call8 Capybara::Node::Element.instance_method(:visible?).bind(self).call9 Capybara::Node::Element.instance_method(:visible?).bind(self).call

Full Screen

Full Screen

obscured

Using AI Code Generation

copy

Full Screen

1 !evaluate_script("return !!(arguments[0].offsetWidth === 0 && arguments[0].offsetHeight === 0)", self)2def obscured?(locator)3 find(locator).obscured?4def obscured?(locator)5 find(locator).obscured?6 !evaluate_script("return !!(arguments[0].offsetWidth === 0 && arguments[0].offsetHeight === 0)", @actual)7 !evaluate_script("return !!(arguments[0].offsetWidth === 0 && arguments[0].offsetHeight === 0)", @actual)8 !evaluate_script("return !!(arguments[0].offsetWidth === 0 && arguments[0].offsetHeight === 0)", self)9 !evaluate_script("return !!(arguments[0].offsetWidth === 0 && arguments[0].offsetHeight === 0)", self)

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful