How to use disabled method of Capybara.Node Package

Best Capybara code snippet using Capybara.Node.disabled

selector.rb

Source:selector.rb Github

copy

Full Screen

...93Capybara.add_selector(:field) do94 xpath { |locator| XPath::HTML.field(locator) }95 filter(:checked, boolean: true) { |node, value| not(value ^ node.checked?) }96 filter(:unchecked, boolean: true) { |node, value| (value ^ node.checked?) }97 filter(:disabled, default: false, boolean: true) { |node, value| not(value ^ node.disabled?) }98 filter(:with) { |node, with| node.value == with.to_s }99 filter(:type) do |node, type|100 if ['textarea', 'select'].include?(type)101 node.tag_name == type102 else103 node[:type] == type104 end105 end106 describe do |options|107 desc, states = "", []108 desc << " of type #{options[:type].inspect}" if options[:type]109 desc << " with value #{options[:with].to_s.inspect}" if options.has_key?(:with)110 states << 'checked' if options[:checked] || (options.has_key?(:unchecked) && !options[:unchecked])111 states << 'not checked' if options[:unchecked] || (options.has_key?(:checked) && !options[:checked])112 states << 'disabled' if options[:disabled]113 desc << " that is #{states.join(' and ')}" unless states.empty?114 desc115 end116end117Capybara.add_selector(:fieldset) do118 xpath { |locator| XPath::HTML.fieldset(locator) }119end120Capybara.add_selector(:link_or_button) do121 label "link or button"122 xpath { |locator| XPath::HTML.link_or_button(locator) }123 filter(:disabled, default: false, boolean: true) { |node, value| node.tag_name == "a" or not(value ^ node.disabled?) }124 describe { |options| " that is disabled" if options[:disabled] }125end126Capybara.add_selector(:link) do127 xpath { |locator| XPath::HTML.link(locator) }128 filter(:href) do |node, href|129 node.first(:xpath, XPath.axis(:self)[XPath.attr(:href).equals(href.to_s)])130 end131 describe { |options| " with href #{options[:href].inspect}" if options[:href] }132end133Capybara.add_selector(:button) do134 xpath { |locator| XPath::HTML.button(locator) }135 filter(:disabled, default: false, boolean: true) { |node, value| not(value ^ node.disabled?) }136 describe { |options| " that is disabled" if options[:disabled] }137end138Capybara.add_selector(:fillable_field) do139 label "field"140 xpath { |locator| XPath::HTML.fillable_field(locator) }141 filter(:disabled, default: false, boolean: true) { |node, value| not(value ^ node.disabled?) }142 describe { |options| " that is disabled" if options[:disabled] }143end144Capybara.add_selector(:radio_button) do145 label "radio button"146 xpath { |locator| XPath::HTML.radio_button(locator) }147 filter(:checked, boolean: true) { |node, value| not(value ^ node.checked?) }148 filter(:unchecked, boolean: true) { |node, value| (value ^ node.checked?) }149 filter(:option) { |node, value| node.value == value.to_s }150 filter(:disabled, default: false, boolean: true) { |node, value| not(value ^ node.disabled?) }151 describe do |options|152 desc, states = "", []153 desc << " with value #{options[:option].inspect}" if options[:option]154 states << 'checked' if options[:checked] || (options.has_key?(:unchecked) && !options[:unchecked])155 states << 'not checked' if options[:unchecked] || (options.has_key?(:checked) && !options[:checked])156 states << 'disabled' if options[:disabled]157 desc << " that is #{states.join(' and ')}" unless states.empty?158 desc159 end160end161Capybara.add_selector(:checkbox) do162 xpath { |locator| XPath::HTML.checkbox(locator) }163 filter(:checked, boolean: true) { |node, value| not(value ^ node.checked?) }164 filter(:unchecked, boolean: true) { |node, value| (value ^ node.checked?) }165 filter(:option) { |node, value| node.value == value.to_s }166 filter(:disabled, default: false, boolean: true) { |node, value| not(value ^ node.disabled?) }167 describe do |options|168 desc, states = "", []169 desc << " with value #{options[:option].inspect}" if options[:option]170 states << 'checked' if options[:checked] || (options.has_key?(:unchecked) && !options[:unchecked])171 states << 'not checked' if options[:unchecked] || (options.has_key?(:checked) && !options[:checked])172 states << 'disabled' if options[:disabled]173 desc << " that is #{states.join(' and ')}" unless states.empty?174 desc175 end176end177Capybara.add_selector(:select) do178 label "select box"179 xpath { |locator| XPath::HTML.select(locator) }180 filter(:options) do |node, options|181 actual = node.all(:xpath, './/option').map { |option| option.text }182 options.sort == actual.sort183 end184 filter(:with_options) { |node, options| options.all? { |option| node.first(:option, option) } }185 filter(:selected) do |node, selected|186 actual = node.all(:xpath, './/option').select { |option| option.selected? }.map { |option| option.text }187 [selected].flatten.sort == actual.sort188 end189 filter(:disabled, default: false, boolean: true) { |node, value| not(value ^ node.disabled?) }190 describe do |options|191 desc = ""192 desc << " with options #{options[:options].inspect}" if options[:options]193 desc << " with at least options #{options[:with_options].inspect}" if options[:with_options]194 desc << " with #{options[:selected].inspect} selected" if options[:selected]195 desc << " that is disabled" if options[:disabled]196 desc197 end198end199Capybara.add_selector(:option) do200 xpath { |locator| XPath::HTML.option(locator) }201end202Capybara.add_selector(:file_field) do203 label "file field"204 xpath { |locator| XPath::HTML.file_field(locator) }205 filter(:disabled, default: false, boolean: true) { |node, value| not(value ^ node.disabled?) }206 describe { |options| " that is disabled" if options[:disabled] }207end208Capybara.add_selector(:table) do209 xpath { |locator| XPath::HTML.table(locator) }210end...

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