项目作者: isaacfreeman

项目描述 :
Generate simple user guides from Capybara specs
高级语言: Ruby
项目地址: git://github.com/isaacfreeman/capybara-guides.git
创建时间: 2017-01-08T00:06:32Z
项目社区:https://github.com/isaacfreeman/capybara-guides

开源协议:MIT License

下载


Capybara::Guides

Manually producing screenshots for user guides is time-consuming.

This gem automates the production of simple guides from Capybara feature specs, so that simple guides can be updated every time the spec is run.

This is currently a proof-of-concept, and hasn’t been tested in practice yet.

Example

Here’s an example scenario block from a feature spec using Rspec and Capybara, where an admin is creating an order in the Solidus eCommerce platform.

  1. scenario "Admin is manually creating an order", js: true do
  2. text_block <<~HEREDOC.html_safe
  3. <h3>Introduction</h3>
  4. This guide covers how to create a manual order from the Admin Interface.
  5. HEREDOC
  6. heading "Create a New Order"
  7. visit spree.admin_path
  8. click_on "Orders"
  9. click_on "New Order"
  10. heading "Add Products to the Order"
  11. expect(page).to have_text('Cart')
  12. expect(first('fieldset')).to have_text('Add Product')
  13. select2_search product.name, from: Spree.t(:name_or_sku)
  14. expect(page).to have_text('Select stock')
  15. fill_in_quantity("table.stock-levels", "quantity_0", 2)
  16. click_button 'Add'
  17. sidebar "Follow the same steps to add more products to the order"
  18. heading "Add Customer Details"
  19. click_on "Customer"
  20. expect(page).to have_text('Customer Details')
  21. within "#select-customer" do
  22. targetted_select2_search user.email, from: "#s2id_customer_search"
  23. end
  24. sidebar <<~HEREDOC
  25. You can either select a name from the "Customer Search" field if the customer has ordered from you before, or you can enter the customer's email address in the "Email" field of the "Account" section. The setting for "Guest Checkout" will automatically change accordingly."
  26. HEREDOC
  27. check "order_use_billing"
  28. fill_in "First Name", with: "John 99"
  29. fill_in "Last Name", with: "Doe"
  30. fill_in "Street Address", with: "100 first lane"
  31. fill_in "Street Address (cont'd)", with: "#101"
  32. fill_in "City", with: "Bethesda"
  33. fill_in "Zip", with: "20170"
  34. targetted_select2_search state.name, from: "#s2id_order_bill_address_attributes_state_id"
  35. fill_in "Phone", with: "123-456-7890"
  36. click_on "Update"
  37. heading "Shipments"
  38. expect(page).to have_text('Shipments')
  39. heading "Adjustments"
  40. click_on "Adjustments"
  41. expect(page).to have_text('Adjustments')
  42. heading "Payments"
  43. click_on "Payments"
  44. expect(page).to have_text('Payments')
  45. click_on "Update"
  46. heading "Confirm"
  47. click_on "Confirm"
  48. expect(page).to have_text('Confirm Order')
  49. click_on "Complete Order"
  50. heading "Done"
  51. expect(page).to have_text('Order completed')
  52. end

As the spec is run, capybara-guides records what actions were taken, and saves screenshots at relevant points. AT the end, it produces static HTML reproducing the spec as a human-readable recipe for reproducing the same steps:

Example Image

Installation

Add this line to your application’s Gemfile:

  1. gem 'capybara-guides'

And then execute:

  1. $ bundle

Or install it yourself as:

  1. $ gem install capybara-guides

Usage

Add the :guide tag to the scenario you want to generate a guide from. If you have infer_spec_type_from_file_location! active, you can also put your guide specs directly into /spec/guides.

  1. scenario "How to purchase a product", js: true, guide: true do
  2. ...
  3. end

Add calls to the heading, text_block and sidebar methods as needed.

  1. heading "Create a New Order"
  2. text_block "This guide covers how to create a manual order from the Admin Interface."
  3. sidebar "The setting for \"Guest Checkout\" will automatically change accordingly."

Browser links, buttons and form elements will be captured as images when the relevant Capybara methods are called (e.g. click_button, fill_in, choose, select…)

Additional images will be captured for each use of the Capybara HaveText matcher.

  1. expect(find('.header')).to have_text('Some Text') # ...will capture a particular page element
  2. expect(page).to have_text('Some Text') # ...will capture a screenshot of the full page

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/isaacfreeman/capybara-guides. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.