Ruby学习笔记(23)_Capybara Actions

来源:互联网 发布:金亚洲软件下载 编辑:程序博客网 时间:2024/06/05 14:45

attach_file

语法:

#attach_file(locator, path, options = {}) ⇒ Capybara::Node::Element

Find a file field on the page and attach a file given its path. The file field can be found via its name, id or label text.

page.attach_file(locator, '/path/to/file.png')

Parameters:

  • locator (String) — Which field to attach the file to
  • path (String) — The path of the file that will be attached, or an array of paths
  • options (Hash) (defaults to: {}) — a customizable set of options

Options Hash (options):

  • wait (false, Numeric) — default: Capybara.default_max_wait_time — Maximum time to wait for matching element to appear.
  • match (Symbol) — default: Capybara.match — The matching strategy to use (:one, :first, :prefer_exact, :smart).
  • exact (Boolean) — default: Capybara.exact — Match the exact label name/contents or accept a partial match.
  • multiple (Boolean) — Match field which allows multiple file selection
  • id (String) — Match fields that match the id attribute
  • name (String) — Match fields that match the name attribute
  • :class (String, Array) — Match links that match the class(es) provided
  • make_visible (true, Hash) — A Hash of CSS styles to change before attempting to attach the file, if true { opacity: 1, display: ‘block’, visibility: ‘visible’ } is used (may not be supported by all drivers)

Returns:

(Capybara::Node::Element) — The file field element


check

语法:

#check([locator], options) ⇒ Capybara::Node::Element

Find a check box and mark it as checked. The check box can be found via name, id or label text.

page.check('German')

Options Hash (options):

  • :option (String) — Value of the checkbox to select
  • id (String) — Match fields that match the id attribute
  • name (String) — Match fields that match the name attribute
  • :class (String, Array) — Match links that match the class(es) provided
  • :allow_label_click (Boolean) — default: Capybara.automatic_label_click — Attempt to click the label to toggle state if element is non-visible.
  • wait (false, Numeric) — default: Capybara.default_max_wait_time — Maximum time to wait for matching element to appear.

Returns:

(Capybara::Node::Element) — The element checked or the label clicked

uncheck

page.uncheck('German')

choose

语法:

#choose([locator], options) ⇒ Capybara::Node::Element

Find a radio button and mark it as checked. The radio button can be found via name, id or label text.

page.choose('Male')

Options Hash (options):

  • :option (String) — Value of the radio_button to choose
  • :id (String) — Match fields that match the id attribute
  • :name (String) — Match fields that match the name attribute
  • :class (String, Array) — Match links that match the class(es) provided
  • wait (false, Numeric) — default: Capybara.default_max_wait_time — Maximum time to wait for matching element to appear.
  • :allow_label_click (Boolean) — default: Capybara.automatic_label_click — Attempt to click the label to toggle state if element is non-visible.

Returns:

(Capybara::Node::Element) — The element chosen or the label clicked


click_button

#click_button([locator], options) ⇒ Capybara::Node::Element

Finds a button on the page and clicks it. This can be any element of type submit, reset, image, button or it can be a element. All buttons can be found by their id, value, or title. elements can also be found by their text content, and image elements by their alt attribute

Options Hash (options):

wait (false, Numeric) — default: Capybara.default_max_wait_time — Maximum time to wait for matching element to appear.


语法:

#click_link([locator], options) ⇒ Capybara::Node::Element

Finds a link by id, text or title and clicks it. Also looks at image alt text inside the link.

Options Hash (options):

wait (false, Numeric) — default: Capybara.default_max_wait_time — Maximum time to wait for matching element to appear.


fill_in

语法:

#fill_in([locator], options = {}) ⇒ Capybara::Node::Element

Locate a text field or text area and fill it in with the given text The field can be found via its name, id or label text.

page.fill_in 'Name', with: 'Bob'

Options Hash (options):

  • wait (false, Numeric) — default: Capybara.default_max_wait_time —
    Maximum time to wait for matching element to appear.

  • :with (String) — The value to fill in - required

  • :fill_options (Hash) — Driver specific options regarding how to fill fields
  • :currently_with (String) — The current value property of the field to fill in
  • :multiple (Boolean) — Match fields that can have multiple values?
  • :id (String) — Match fields that match the id attribute
  • :name (String) — Match fields that match the name attribute
  • :placeholder (String) — Match fields that match the placeholder attribute
  • :class (String, Array) — Match links that match the class(es) provided

select

语法:

#select(value, options = {}) ⇒ Capybara::Node::Element

If :from option is present, select finds a select box on the page and selects a particular option from it. Otherwise it finds an option inside current scope and selects it. If the select box is a multiple select, select can be called multiple times to select more than one option. The select box can be found via its name, id or label text. The option can be found by its text.

page.select 'March', from: 'Month'

Parameters:

  • value (String) — Which option to select
  • options (Hash) (defaults to: {}) — a customizable set of options

Options Hash (options):

  • wait (false, Numeric) — default: Capybara.default_max_wait_time — Maximum time to wait for matching element to appear.
  • :from (String) — The id, name or label of the select box

Returns:

(Capybara::Node::Element) — The option element selected

unselect

page.unselect 'March', from: 'Month'
原创粉丝点击