项目作者: matti

项目描述 :
Capybara CLI on Steroids
高级语言: Ruby
项目地址: git://github.com/matti/superbara.git
创建时间: 2017-10-07T13:53:39Z
项目社区:https://github.com/matti/superbara

开源协议:

下载


Superbara

Web app test scripting that does not hurt.

Demo of Superbara

  • Stands on the shoulders of Capybara
  • All batteries included: just start scripting, nothing extra required
  • A powerful command line interface with interactive debugger
  • The most natural test language that is still programming, see:
  1. visit "mysite.com"
  2. wait 3 do
  3. has_text? "welcome"
  4. end
  5. scroll 20
  6. click_link "enter"
  7. name_field = find "input#name"
  8. name_field.type "Sarah", :enter
  9. if has_text? "Welcome, Sarah"
  10. run "logout"
  11. else
  12. assert "no greeting visible"
  13. end

Install & Usage

  1. gem install superbara
  2. superbara init example
  3. superbara start example
  4. superbara usage

Documentation

See https://matti.github.io/superbara for getting started and language reference.

Some things that Superbara does that Capybara does not:

  1. # find+click in one line!
  2. click 'h1'
  3. # wait up to 3 seconds for block to return something else than nil or false
  4. wait 3 do
  5. has_text? "Welcome"
  6. end
  7. wait 3.1 do
  8. find "#username"
  9. end
  10. # simulates real typing
  11. textarea = find "textarea"
  12. textarea.type "hello", :backspace, :backspace, :backspace, "sinki", :enter
  13. # scrolling
  14. scroll 50
  15. scroll -20, duration: 4
  16. # works also without http://
  17. visit 'example.com'
  18. # highlights when in interactive mode or SUPERBARA_VISUAL env is set
  19. find "h1"
  20. # runs project/file.rb
  21. run "vars"
  22. # possible to run just once per session (superbara start) to speed up
  23. run "login", {}, once: true
  24. # ..and do something when already ran
  25. run "login", {}, once: true do
  26. # when already logged in
  27. visit "http://www.example.com/main"
  28. end
  29. # opens debugger when exception happens or when the test finishes or
  30. debug
  31. # back, forward, reload (and not only go_back, go_forward, refresh)
  32. back
  33. forward
  34. reload
  35. # natural sleeps, sleep between 2 and 4 seconds
  36. think 2..4

Everything that works in Capybara, works in Superbara, see https://github.com/teamcapybara/capybara/#the-dsl

Quick Reference:

  1. click_link 'id-of-link'
  2. click_link 'Link Text'
  3. click_button 'Save'
  4. click_on 'Link Text' || click_on 'Button Value'
  5. click_text 'get started'
  6. find 'h1'
  7. find_field('First Name').value
  8. find_field(id: 'my_field').value
  9. find_link('Hello', :visible => :all).visible?
  10. find_link(class: ['some_class', 'some_other_class'], visible: :all).visible?
  11. find_button('Send').click
  12. find_button(value: '1234').click
  13. find(:xpath, ".//table/tr").click
  14. find("#overlay").find("h1").click
  15. for a in all('a') do
  16. if a[:href].include? "about"
  17. a.click
  18. end
  19. end
  20. img_boxed = find('img') do |el|
  21. el['data-box'] == true
  22. end
  23. within '#menu' do
  24. click 'a', text: 'Pricing'
  25. end
  26. within_table 'Employee' do
  27. fill_in 'Name', with: 'Sarah'
  28. end
  29. within_fieldset 'Employee' do
  30. ...
  31. end
  32. facebook_window = window_opened_by do
  33. click_button 'Like'
  34. end
  35. within_window facebook_window do
  36. find('#login_email').type 'a@example.com'
  37. find('#login_password').type 'qwerty'
  38. click_button 'Submit'
  39. end
  40. execute_script "document.querySelector("#name").style.border = '1px solid red';"
  41. value = evaluate_script "window.innerHeight"
  42. accept_alert do
  43. click_link 'Show Alert'
  44. end
  45. dismiss_confirm do
  46. click_link 'Show Confirm'
  47. end
  48. message = accept_prompt with: 'Linda Liukas' do
  49. click_link 'Author Quiz!'
  50. end
  51. message = 'Who is the author of Hello Ruby?'
  52. has_selector? 'table tr'
  53. has_no_selector? 'table tr'
  54. has_selector? :xpath, './/table/tr'
  55. has_xpath? './/table/tr'
  56. has_no_xpath? './/table/tr'
  57. has_css? 'table tr.foo'
  58. has_no_css? 'table tr.foo'
  59. has_content? 'foo'
  60. has_no_content? 'foo'
  61. has_text? 'foo'
  62. has_no_text? 'foo'
  63. fill_in 'First Name', with: 'Johwn'
  64. choose 'A Radio Button'
  65. check 'A Checkbox'
  66. uncheck 'A Checkbox'
  67. attach_file 'Image', File.join(Dir.pwd,'image.jpg')
  68. select 'Option', from: 'Select Box'