How to use rect method of Capybara.Driver Package

Best Capybara code snippet using Capybara.Driver.rect

shared_selenium_session.rb

Source:shared_selenium_session.rb Github

copy

Full Screen

...175 end176 it 'handles namespaces in xhtml' do177 pending "IE 11 doesn't handle all XPath querys (namespace-uri, etc)" if ie?(session)178 session.visit '/with_namespace'179 rect = session.find(:css, 'div svg rect:first-of-type')180 expect(rect.path).to eq("/HTML/BODY/DIV/./*[((local-name(.) = 'svg') and (namespace-uri(.) = 'http://www.w3.org/2000/svg'))]/./*[((local-name(.) = 'rect') and (namespace-uri(.) = 'http://www.w3.org/2000/svg'))][1]")181 expect(session.find(:xpath, rect.path)).to eq rect182 end183 it 'handles default namespaces in html5' do184 pending "IE 11 doesn't handle all XPath querys (namespace-uri, etc)" if ie?(session)185 session.visit '/with_html5_svg'186 rect = session.find(:css, 'div svg rect:first-of-type')187 expect(rect.path).to eq("/HTML/BODY/DIV/./*[((local-name(.) = 'svg') and (namespace-uri(.) = 'http://www.w3.org/2000/svg'))]/./*[((local-name(.) = 'rect') and (namespace-uri(.) = 'http://www.w3.org/2000/svg'))][1]")188 expect(session.find(:xpath, rect.path)).to eq rect189 end190 it 'handles case sensitive element names' do191 pending "IE 11 doesn't handle all XPath querys (namespace-uri, etc)" if ie?(session)192 session.visit '/with_namespace'193 els = session.all(:css, 'div *', visible: :all)194 expect { els.map(&:path) }.not_to raise_error195 lg = session.find(:css, 'div linearGradient', visible: :all)196 expect(session.find(:xpath, lg.path, visible: :all)).to eq lg197 end198 end199 describe 'all with disappearing elements' do200 it 'ignores stale elements in results' do201 session.visit('/path')202 elements = session.all(:link) { |_node| raise Selenium::WebDriver::Error::StaleElementReferenceError }203 expect(elements.size).to eq 0204 end205 end206 describe '#evaluate_script' do207 it 'can return an element' do208 session.visit('/form')209 element = session.evaluate_script("document.getElementById('form_title')")210 expect(element).to eq session.find(:id, 'form_title')211 end212 it 'can return arrays of nested elements' do213 session.visit('/form')214 elements = session.evaluate_script('document.querySelectorAll("#form_city option")')215 expect(elements).to all(be_instance_of Capybara::Node::Element)216 expect(elements).to eq session.find(:css, '#form_city').all(:css, 'option').to_a217 end218 it 'can return hashes with elements' do219 session.visit('/form')220 result = session.evaluate_script("{ a: document.getElementById('form_title'), b: {c: document.querySelectorAll('#form_city option')}}")221 expect(result).to eq(222 'a' => session.find(:id, 'form_title'),223 'b' => {224 'c' => session.find(:css, '#form_city').all(:css, 'option').to_a225 }226 )227 end228 describe '#evaluate_async_script' do229 it 'will timeout if the script takes too long' do230 session.visit('/with_js')231 expect do232 session.using_wait_time(1) do233 session.evaluate_async_script('var cb = arguments[0]; setTimeout(function(){ cb(null) }, 3000)')234 end235 end.to raise_error Selenium::WebDriver::Error::ScriptTimeoutError236 end237 end238 end239 describe 'Element#inspect' do240 it 'outputs obsolete elements' do241 session.visit('/form')242 el = session.find(:button, 'Click me!').click243 expect(session).to have_no_button('Click me!')244 allow(el).to receive(:synchronize)245 expect(el.inspect).to eq 'Obsolete #<Capybara::Node::Element>'246 expect(el).not_to have_received(:synchronize)247 end248 end249 describe 'Element#click' do250 it 'should handle fixed headers/footers' do251 session.visit('/with_fixed_header_footer')252 # session.click_link('Go to root')253 session.find(:link, 'Go to root').click254 expect(session).to have_current_path('/')255 end256 end257 describe 'Element#drag_to' do258 before do259 skip "Firefox < 62 doesn't support a DataTransfer constuctor" if firefox_lt?(62.0, session)260 skip "IE doesn't support a DataTransfer constuctor" if ie?(session)261 end262 it 'should HTML5 drag and drop an object' do263 session.visit('/with_js')264 element = session.find('//div[@id="drag_html5"]')265 target = session.find('//div[@id="drop_html5"]')266 element.drag_to(target)267 expect(session).to have_xpath('//div[contains(., "HTML5 Dropped drag_html5")]')268 end269 it 'should not HTML5 drag and drop on a non HTML5 drop element' do270 session.visit('/with_js')271 element = session.find('//div[@id="drag_html5"]')272 target = session.find('//div[@id="drop_html5"]')273 target.execute_script("$(this).removeClass('drop');")274 element.drag_to(target)275 sleep 1276 expect(session).not_to have_xpath('//div[contains(., "HTML5 Dropped drag_html5")]')277 end278 it 'should HTML5 drag and drop when scrolling needed' do279 session.visit('/with_js')280 element = session.find('//div[@id="drag_html5_scroll"]')281 target = session.find('//div[@id="drop_html5_scroll"]')282 element.drag_to(target)283 expect(session).to have_xpath('//div[contains(., "HTML5 Dropped drag_html5_scroll")]')284 end285 it 'should drag HTML5 default draggable elements' do286 session.visit('/with_js')287 link = session.find_link('drag_link_html5')288 target = session.find(:id, 'drop_html5')289 link.drag_to target290 expect(session).to have_xpath('//div[contains(., "HTML5 Dropped")]')291 end292 end293 describe 'Capybara#Node#attach_file' do294 it 'can attach a directory' do295 pending "Geckodriver doesn't support uploading a directory" if firefox?(session)296 pending "Selenium remote doesn't support transferring a directory" if remote?(session)297 pending "Headless Chrome doesn't support directory upload - https://bugs.chromium.org/p/chromedriver/issues/detail?id=2521&q=directory%20upload&colspec=ID%20Status%20Pri%20Owner%20Summary" if chrome?(session) && ENV['HEADLESS']298 session.visit('/form')299 @test_file_dir = File.expand_path('./fixtures', File.dirname(__FILE__))300 session.attach_file('Directory Upload', @test_file_dir)301 session.click_button('Upload Multiple')302 expect(session.body).to include('5 | ') # number of files303 end304 end305 context 'Windows' do306 it "can't close the primary window" do307 expect do308 session.current_window.close309 end.to raise_error(ArgumentError, 'Not allowed to close the primary window')310 end311 end312 describe 'Capybara#disable_animation' do313 context 'when set to `true`' do314 before(:context) do # rubocop:disable RSpec/BeforeAfterAll315 # NOTE: Although Capybara.SpecHelper.reset! sets Capybara.disable_animation to false,316 # it doesn't affect any of these tests because the settings are applied per-session317 Capybara.disable_animation = true318 @animation_session = Capybara::Session.new(session.mode, TestApp.new)319 end320 after(:context) do # rubocop:disable RSpec/BeforeAfterAll321 @animation_session = nil322 end323 it 'should disable CSS transitions' do324 @animation_session.visit('with_animation')325 @animation_session.click_link('transition me away')326 expect(@animation_session).to have_no_link('transition me away', wait: 0.5)327 end328 it 'should disable CSS animations' do329 @animation_session.visit('with_animation')330 @animation_session.click_link('animate me away')331 expect(@animation_session).to have_no_link('animate me away', wait: 0.5)332 end333 end334 context 'if we pass in css that matches elements' do335 before(:context) do # rubocop:disable RSpec/BeforeAfterAll336 # NOTE: Although Capybara.SpecHelper.reset! sets Capybara.disable_animation to false,337 # it doesn't affect any of these tests because the settings are applied per-session338 Capybara.disable_animation = '#with_animation a'339 @animation_session_with_matching_css = Capybara::Session.new(session.mode, TestApp.new)340 end341 after(:context) do # rubocop:disable RSpec/BeforeAfterAll342 @animation_session_with_matching_css = nil343 end344 it 'should disable CSS transitions' do345 @animation_session_with_matching_css.visit('with_animation')346 @animation_session_with_matching_css.click_link('transition me away')347 expect(@animation_session_with_matching_css).to have_no_link('transition me away', wait: 0.5)348 end349 it 'should disable CSS animations' do350 @animation_session_with_matching_css.visit('with_animation')351 @animation_session_with_matching_css.click_link('animate me away')352 expect(@animation_session_with_matching_css).to have_no_link('animate me away', wait: 0.5)353 end354 end355 context 'if we pass in css that does not match elements' do356 before(:context) do # rubocop:disable RSpec/BeforeAfterAll357 # NOTE: Although Capybara.SpecHelper.reset! sets Capybara.disable_animation to false,358 # it doesn't affect any of these tests because the settings are applied per-session359 Capybara.disable_animation = '.this-class-matches-nothing'360 @animation_session_without_matching_css = Capybara::Session.new(session.mode, TestApp.new)361 end362 after(:context) do # rubocop:disable RSpec/BeforeAfterAll363 @animation_session_without_matching_css = nil364 end365 it 'should not disable CSS transitions' do366 @animation_session_without_matching_css.visit('with_animation')367 @animation_session_without_matching_css.click_link('transition me away')368 sleep 0.5 # Wait long enough for click to have been processed369 expect(@animation_session_without_matching_css).to have_link('transition me away', wait: false)370 expect(@animation_session_without_matching_css).to have_no_link('transition me away', wait: 5)371 end372 it 'should not disable CSS animations' do373 @animation_session_without_matching_css.visit('with_animation')374 @animation_session_without_matching_css.click_link('animate me away')375 sleep 0.5 # Wait long enough for click to have been processed376 expect(@animation_session_without_matching_css).to have_link('animate me away', wait: false)377 expect(@animation_session_without_matching_css).to have_no_link('animate me away', wait: 5)378 end379 end380 end381 describe ':element selector' do382 it 'can find html5 svg elements' do383 session.visit('with_html5_svg')384 expect(session).to have_selector(:element, :svg)385 expect(session).to have_selector(:element, :rect, visible: true)386 expect(session).to have_selector(:element, :circle)387 expect(session).to have_selector(:element, :linearGradient, visible: :all)388 end389 it 'can query attributes with strange characters' do390 session.visit('/form')391 expect(session).to have_selector(:element, "{custom}": true)392 expect(session).to have_selector(:element, "{custom}": 'abcdef')393 end394 end395 end396 def headless_or_remote?397 !ENV['HEADLESS'].nil? || session.driver.options[:browser] == :remote398 end399end...

Full Screen

Full Screen

rect

Using AI Code Generation

copy

Full Screen

1visit('/')2visit('/')3 from (irb):9

Full Screen

Full Screen

rect

Using AI Code Generation

copy

Full Screen

1visit('/')2page.save_screenshot('google.png')3puts page.evaluate_script('4+4')4puts page.evaluate_script('window.location.href')5puts page.evaluate_script('window.location')6puts page.evaluate_script('window.location.host')7puts page.evaluate_script('window.location.pathname')8puts page.evaluate_script('window.location.port')9puts page.evaluate_script('window.location.protocol')10puts page.evaluate_script('window.location.search')11puts page.evaluate_script('document.location')12puts page.evaluate_script('document.location.host')13puts page.evaluate_script('document.location.pathname')14puts page.evaluate_script('document.location.port')15puts page.evaluate_script('document.location.protocol')16puts page.evaluate_script('document.location.search')17puts page.evaluate_script('document.URL')18puts page.evaluate_script('document.URL.host')19puts page.evaluate_script('document.URL.pathname')20puts page.evaluate_script('document.URL.port')21puts page.evaluate_script('document.URL.protocol')22puts page.evaluate_script('document.URL.search')23puts page.evaluate_script('document.domain')24puts page.evaluate_script('document.location.href')25puts page.evaluate_script('document.location.href.host')26puts page.evaluate_script('document.location.href.pathname')27puts page.evaluate_script('document.location.href.port')28puts page.evaluate_script('document.location.href.protocol')29puts page.evaluate_script('document.location.href.search')30puts page.evaluate_script('document.location.href')31puts page.evaluate_script('document.location.href.host')32puts page.evaluate_script('document.location.href.pathname')33puts page.evaluate_script('document.location.href.port')34puts page.evaluate_script('document.location.href.protocol')35puts page.evaluate_script('document.location.href.search')36puts page.evaluate_script('window.location.href')37puts page.evaluate_script('window.location.href.host')38puts page.evaluate_script('window.location.href.pathname')39puts page.evaluate_script('window.location.href.port')40puts page.evaluate_script('window.location.href.protocol')41puts page.evaluate_script('window.location.href.search')

Full Screen

Full Screen

rect

Using AI Code Generation

copy

Full Screen

1 Capybara::Poltergeist::Driver.new(app, :js_errors => false)2visit('/')3puts page.driver.render('screenshot.png')

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