Best Capybara code snippet using Capybara.descriptions
filter_set.rb
Source:filter_set.rb
...7 def initialize(name, &block)8 @name = name9 @node_filters = {}10 @expression_filters = {}11 @descriptions = Hash.new { |hsh, key| hsh[key] = [] }12 instance_eval(&block) if block13 end14 def node_filter(names, *types, **options, &block)15 Array(names).each do |name|16 add_filter(name, Filters::NodeFilter, *types, **options, &block)17 end18 end19 alias_method :filter, :node_filter20 def expression_filter(name, *types, **options, &block)21 add_filter(name, Filters::ExpressionFilter, *types, **options, &block)22 end23 def describe(what = nil, &block)24 case what25 when nil26 undeclared_descriptions.push block27 when :node_filters28 node_filter_descriptions.push block29 when :expression_filters30 expression_filter_descriptions.push block31 else32 raise ArgumentError, 'Unknown description type'33 end34 end35 def description(node_filters: true, expression_filters: true, **options)36 opts = options_with_defaults(options)37 description = +''38 description << undeclared_descriptions.map { |desc| desc.call(**opts).to_s }.join39 description << expression_filter_descriptions.map { |desc| desc.call(**opts).to_s }.join if expression_filters40 description << node_filter_descriptions.map { |desc| desc.call(**opts).to_s }.join if node_filters41 description42 end43 def descriptions44 Capybara::Helpers.warn 'DEPRECATED: FilterSet#descriptions is deprecated without replacement'45 [undeclared_descriptions, node_filter_descriptions, expression_filter_descriptions].flatten46 end47 def import(name, filters = nil)48 filter_selector = filters.nil? ? ->(*) { true } : ->(filter_name, _) { filters.include? filter_name }49 self.class[name].tap do |f_set|50 expression_filters.merge!(f_set.expression_filters.select(&filter_selector))51 node_filters.merge!(f_set.node_filters.select(&filter_selector))52 f_set.undeclared_descriptions.each { |desc| describe(&desc) }53 f_set.expression_filter_descriptions.each { |desc| describe(:expression_filters, &desc) }54 f_set.node_filter_descriptions.each { |desc| describe(:node_filters, &desc) }55 end56 self57 end58 class << self59 def all60 @filter_sets ||= {} # rubocop:disable Naming/MemoizedInstanceVariableName61 end62 def [](name)63 all.fetch(name.to_sym) { |set_name| raise ArgumentError, "Unknown filter set (:#{set_name})" }64 end65 def add(name, &block)66 all[name.to_sym] = FilterSet.new(name.to_sym, &block)67 end68 def remove(name)69 all.delete(name.to_sym)70 end71 end72 protected73 def undeclared_descriptions74 @descriptions[:undeclared]75 end76 def node_filter_descriptions77 @descriptions[:node_filters]78 end79 def expression_filter_descriptions80 @descriptions[:expression_filters]81 end82 private83 def options_with_defaults(options)84 options = options.dup85 [expression_filters, node_filters].each do |filters|86 filters.select { |_n, filter| filter.default? }.each do |name, filter|87 options[name] = filter.default unless options.key?(name)88 end89 end90 options91 end92 def add_filter(name, filter_class, *types, matcher: nil, **options, &block)93 types.each { |type| options[type] = true }94 if matcher && options[:default]...
capybara_helper.rb
Source:capybara_helper.rb
...23 FileUtils.remove_dir(failed_dir) if failed_dir.directory?24 end25 def self.take_screenshot(page)26 metadata = RSpec.current_example.metadata27 metadata_descriptions = metadata_descriptions(metadata)28 directory = metadata_descriptions.shift.gsub(REGEX_SAFE_FILENAME, '_')29 description = metadata_descriptions.join('-').gsub(REGEX_SAFE_FILENAME, '_')30 driver = Capybara.current_driver31 timestamp = Time.now.strftime('%Y%m%d%H%M%S%L')32 release_dir = release_dir()33 screenshot_name = release_dir.join(34 driver.to_s,35 directory,36 "#{description}.#{timestamp}.png"37 )38 page.save_screenshot(screenshot_name, full: true)39 end40 def self.metadata_descriptions(metadata)41 descriptions = [metadata[:description]]42 group_metadata = metadata.fetch(:example_group) { metadata[:parent_example_group] }43 return descriptions unless group_metadata44 loop do45 descriptions.unshift(group_metadata[:description])46 break unless (group_metadata = group_metadata[:parent_example_group])47 end48 descriptions49 end50end...
scraper.rb
Source:scraper.rb
...14 browser.visit 'https://www.onliner.by/'15 browser.click_on(start_page)16 headings = []17 img_hrefs = []18 descriptions = []19 pages.each { |name| inspect_page(browser, name, headings, img_hrefs, descriptions) }20 headings.zip(img_hrefs, descriptions)21 end22 private23 # конÑиг capybara24 def configure25 Capybara.register_driver :selenium do |app|26 Capybara::Selenium::Driver.new(app, browser: :chrome)27 end28 Capybara.default_driver = :selenium29 Capybara.javascript_driver = :chrome30 Capybara.match = :first31 Capybara.exact = :true32 Capybara.current_session33 end34 # пÑовеÑка ÑÑÑаниÑки35 def inspect_page(browser, page_name, headings, img_hrefs, descriptions)36 browser.click_on(page_name)37 headings.concat(browser.all(class: 'news-tidings__subtitle').map(&:text))38 img_hrefs.concat(browser.all(class: 'news-tidings__image').map { |a| a['style'].match(/^.*:\s*url\((\".*\")\)/).captures[0] })39 descriptions.concat(browser.all(class: 'news-tidings__speech').map { |a| a.text.slice(0, 200) })40 end41end...
descriptions
Using AI Code Generation
1 visit('/')2 def search_for(search_term)3 fill_in('q', :with => search_term)4 click_button('Google Search')5 puts page.all('h3.r').map(&:text)6google.search_for('capybara')7 visit('/')8 def search_for(search_term)9 fill_in('q', :with => search_term)10 click_button('Google Search')11 puts all('h3.r').map(&:text)12google.search_for('capybara')13 visit('/')14 def search_for(search_term)15 fill_in('q', :with => search_term)16 click_button('Google Search')17 puts all('h3.r').map(&:text)
descriptions
Using AI Code Generation
1 Capybara::Poltergeist::Driver.new(app, :js_errors => false, :timeout => 60, :debug => false)2 all(:css, 'td.description').map(&:text)3Given(/^I go to the page$/) do4Then(/^I should see the descriptions$/) do5 descriptions.should include('Capybara')61 scenario (1 passed)72 steps (2 passed)
descriptions
Using AI Code Generation
1 visit('/')2 fill_in('q', with => 'Capybara')3 click_on('Google Search')4 expect(page).to have_content('Capybara')5 visit('/')6 fill_in('q', with => 'Capybara')7 click_on('Google Search')8 expect(page).to have_content('Capybara')9 Failure/Error: expect(page).to have_content('Capybara')
descriptions
Using AI Code Generation
1 Capybara::Selenium::Driver.new(app, :browser => :chrome)2Capybara::Selenium::Driver.new(app, :browser => :firefox)3Capybara::Selenium::Driver.new(app, :browser => :chrome)4Capybara::Poltergeist::Driver.new(app, {:js_errors => false})5Capybara::Poltergeist::Driver.new(app, {:js_errors => true})6Capybara::Poltergeist::Driver.new(app, {:js_errors => true, :timeout => 60, :debug => false, :inspector => true})7Capybara::Poltergeist::Driver.new(app, {:js_errors => true, :timeout => 60, :debug => false, :inspector => true, :phantomjs_logger => StringIO.new})8Capybara::Poltergeist::Driver.new(app, {:js_errors => true, :timeout => 60, :debug => false, :inspector => true, :phantomjs_logger => File.open('/dev/null', 'w')})9Capybara::Poltergeist::Driver.new(app, {:js_errors => true, :timeout => 60, :debug => false, :inspector => true, :phantomj
descriptions
Using AI Code Generation
1Capybara::Session.new(:selenium).visit('http://google.com')2Capybara::Session.new(:selenium).visit('http://yahoo.com')3Capybara::Session.new(:selenium).visit('http://bing.com')4Capybara::Session.new(:selenium).visit('http://google.com')5Capybara::Session.new(:selenium).visit('http://yahoo.com')6Capybara::Session.new(:selenium).visit('http://bing.com')7Capybara::Session.new(:selenium).visit('http://google.com')8Capybara::Session.new(:selenium).visit('http://yahoo.com')9Capybara::Session.new(:selenium).visit('http://bing.com')10Capybara::Session.new(:selenium).visit('http://google.com')11Capybara::Session.new(:selenium).visit('http://yahoo.com')12Capybara::Session.new(:selenium).visit('http://bing.com')13Capybara::Session.new(:selenium).visit('http://google.com')14Capybara::Session.new(:selenium).visit('http://yahoo.com')15Capybara::Session.new(:selenium).visit('http://bing.com')16Capybara::Session.new(:selenium).visit('http://google.com')17Capybara::Session.new(:selenium).visit('http://yahoo.com')18Capybara::Session.new(:selenium).visit('http://bing.com')19Capybara::Session.new(:selenium).visit('http://google.com')20Capybara::Session.new(:selenium).visit('http://yahoo.com')21Capybara::Session.new(:selenium).visit('http://bing.com')22Capybara::Session.new(:s
descriptions
Using AI Code Generation
1 Capybara::Selenium::Driver.new(app, :browser => :chrome)2Capybara::Selenium::Driver.new(app, :browser => :firefox)3Capybara::Selenium::Driver.new(app, :browser => :chrome)4Capybara::Poltergeist::Driver.new(app, {:js_errors => false})5Capybara::Poltergeist::Driver.new(app, {:js_errors => true})6Capybara::Poltergeist::Driver.new(app, {:js_errors => true, :timeout => 60, :debug => false, :inspector => true})7Capybara::Poltergeist::Driver.new(app, {:js_errors => true, :timeout => 60, :debug => false, :inspector => true, :phantomjs_logger => StringIO.new})8Capybara::Poltergeist::Driver.new(app, {:js_errors => true, :timeout => 60, :debug => false, :inspector => true, :phantomjs_logger => File.open('/dev/null', 'w')})9Capybara::Poltergeist::Driver.new(app, {:js_errors => true, :timeout => 60, :debug => false, :inspector => true, :phantomjs
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!