Upgrade to Pro — share decks privately, control downloads, hide ads and more …

e2e_prototype_capybara.pdf

 e2e_prototype_capybara.pdf

Bd73c8006f95df876a0dda5c8f43502b?s=128

mokuo

May 10, 2018
Tweet

Transcript

  1. ϨΨγʔγεςϜͷ E2EࣗಈςετͷϓϩτλΠϓΛ CapybaraͰ࡞ͬͨ࿩ 2018.05.10 දࢀಓ.rb#34 Sansanגࣜձࣾ Eightࣄۀ෦ ΤϯδχΞ ໦ా ༔Ұ࿠

  2. ϓϩϑΟʔϧ • ໊લɿ໦ా ༔Ұ࿠ • ग़਎ɿਆಸ઒ݝԣ඿ࢢ • झຯɿςχεɺϓϩάϥϛϯά • Twitter

    : @mokuo_ • GitHub : mokuo • Qiita : @mokuo
  3. ܦྺ • େֶจܥ • Πϯλʔϯʢखಈςετ, WordPressʣ • ࣾձਓ̍೥໨ • SIer

    (SE) • ࣾձਓ̎೥໨ • ॴଐɿࣗࣾύοέʔδ։ൃɾൢച ← ຊ೔͸ίίͰͷ࿩ • ग़޲ɿRailsडୗ։ൃ • ݱࡏɿSansan
  4. ໨࣍ • ϓϩτλΠϓΛ࡞ͬͨഎܠ • ϓϩτλΠϓͷߏ੒ͱઆ໌ • ·ͱΊ

  5. ໨࣍ • ϓϩτλΠϓΛ࡞ͬͨഎܠ • ϓϩτλΠϓͷߏ੒ͱઆ໌ • ·ͱΊ

  6. ಥવͰ͕͢

  7. ColdFusion ͬͯ͝ଘ஌Ͱ͔͢ʁ

  8. –Wikipedia “ColdFusion ͸ɺιϑτ΢ΣΞશൠʢಛ ʹಈత΢ΣϒαΠτʣͷ։ൃʹ࢖ΘΕΔ ΞϓϦέʔγϣϯϑϨʔϜϫʔΫͰ͋Γɺ ΞϓϦέʔγϣϯαʔόͰ͋Δɻ”

  9. CFML (ColdFusion Markup Language) <cfif type IS "Date"> <cfoutput>#DateFormat(Now())#</cfoutput> <cfelseif

    type IS "Time"> <cfoutput>#TimeFormat(Now())#</cfoutput> <cfelse> <cfoutput>#TimeFormat(Now())#, #DateFormat(Now())#</cfoutput> </cfif> ࢀߟ"EPCF$PME'VTJPO ϑϩʔ੍ޚ
  10. ColdFusion ͰͰ͖ͨγεςϜ • ࣗಈςετҰ੾ͳ͠ • ຖճखಈςετ ·͋ɺԶ ؔ܎ͳ͍͠ɾɾɾ

  11. ͋Δ೔

  12. ʮ͍΍ʔɺਓ଍Γͳ͘ͳͬͪΌͬͯ͞www mokuo͘Μɺςετ΍ͬͯΑসসʯ

  13. None
  14. ࣗಈςετͷϓϩτλΠϓ࡞Δͧ • ϓϩτλΠϓΛݟͤΕ͹ɺԿ͔มΘΔ͔΋͠ Εͳ͍ • Ϧʔμʔ΋՝୊ײ͸͋ͬͨ

  15. ໨࣍ • ϓϩτλΠϓΛ࡞ͬͨഎܠ • ϓϩτλΠϓͷߏ੒ͱઆ໌ • ·ͱΊ

  16. • ݴޠ : Ruby • ϑϨʔϜϫʔΫ : Capybara

  17. σΟϨΫτϦߏ੒ . !"" .env.sample !"" .gitignore !"" .ruby-version !"" Gemfile

    !"" Gemfile.lock !"" README.md #"" spec !"" features !"" pages !"" spec_helper.rb #"" support
  18. ֤ϑΝΠϧͷઆ໌

  19. Gemfile source "https://rubygems.org" gem 'capybara' gem 'selenium-webdriver' gem 'chromedriver-helper' gem

    'dotenv' gem 'rspec' gem 'tapp' gem ‘byebug'
  20. .env.sample SYSTEM_URL= https://example.com/ ADMIN_LOGIN= admin_user ADMIN_PASS= password HEADLESS= true

  21. .env ͷઆ໌ ؀ڥม਺ આ໌ ྫ 4:45&.@63- γεςϜͷ63- IUUQTFYBNQMFDPN "%.*/@-0(*/ ؅ཧऀͷϩάΠϯ*%

    MPHJO "%.*/@1"44 ؅ཧऀͷύεϫʔυ QBTTXPSE )&"%-&44 ϔουϨεϞʔυͰ ࣮ߦ͢Δ͔ USVF
  22. spec_helper.rbʢલ൒ʣ require 'selenium-webdriver' require 'capybara/rspec' require 'tapp' require 'dotenv' require

    'byebug' Dotenv.load Capybara.configure do |capybara_config| capybara_config.default_driver = :selenium_chrome capybara_config.default_max_wait_time = 10 # seconds end Capybara.register_driver :selenium_chrome do |app| options = Selenium::WebDriver::Chrome::Options.new options.add_argument('headless') if ENV['HEADLESS'] == 'true' Capybara::Selenium::Driver.new(app, browser: :chrome, options: options) end Capybara.javascript_driver = :selenium_chrome
  23. spec_helper.rbʢޙ൒ʣ require 'support/constants' require 'pages/base_page' # ܧঝ͢ΔͷͰɺઌʹಡΈࠐΜͰ͓͘ require 'pages/admin/base_page' #

    ܧঝ͢ΔͷͰɺઌʹಡΈࠐΜͰ͓͘ require 'pages/user/base_page' # ܧঝ͢ΔͷͰɺઌʹಡΈࠐΜͰ͓͘ Dir[Constants::APP_ROOT.join('spec/pages/**/*.rb')].each { |f| require f } Dir[Constants::APP_ROOT.join('spec/support/**/*.rb')].each { |f| require f } include SupportMacros include LoginMacros include CourseMacros include GroupMacros include UserMacros include CourseGroupMacros include AdminMacros include InquiryMacros include QuestionnaireMacros include SeminarMacros include PortalMenuMacros include LmsSettingMacros
  24. spec_helper.rb ΛඞͣಡΈࠐΉ require 'spec_helper' RSpec.feature 'γεςϜ؅ཧ', :type => :feature do

    background :all do system_admin_login
  25. ڞ௨ॲཧ͸Ϟδϡʔϧʹ੾Γग़͢ module LoginMacros def admin_login visit “#{ENV[‘SYSTEM_URL']}/admin_login" admin_login_page = Admin::LoginPage.new(page)

    admin_login_page.set_id(ENV['ADMIN_LOGIN']) admin_login_page.set_pass(ENV['ADMIN_PASS']) admin_login_page.login end def user_login(id, pass) visit “#{ENV[‘SYSTEM_URL']}/user_login" user_login_page = User::LoginPage.new(page) user_login_page.set_id(id) user_login_page.set_pass(pass) user_login_page.login end end
  26. ϖʔδΦϒδΣΫτύλʔϯ • Selenium Ͱ͸༗໊ͳσβΠϯύλʔϯΒ͍͠ • ϖʔδΛΫϥεʹݟཱͯΔ • ϘλϯΫϦοΫͳͲΛϝιουͱͯ࣋ͨͤ͠Δ • ϝϦοτ

    • ԿΛ͍ͯ͠Δ͔෼͔Γ΍͍͢ • มߋ͠΍͍͢ • ࠶ར༻͠΍͍͢
  27. ϢʔβʔϩάΠϯϖʔδ module User class LoginPage < BasePage def set_id(id) page.fill_in

    'login', with: id end def set_pass(pass) page.fill_in 'password', with: pass end def login page.click_on 'ϩάΠϯ' User::TopPage.new(page) end end end
  28. ϢʔβʔϩάΠϯ visit "#{ENV['SYSTEM_URL']}/user/" user_login_page = User::LoginPage.new(page) user_login_page.set_id(id) user_login_page.set_pass(id) user_top_page =

    user_login_page.login
  29. ϩʔΧϧͰͷ࣮ߦखॱ $ git clone git@github.com:xxxxx/xxxxx.git $ bundle install --path vendor/bundle

    $ cp .env.sample .env $ bundle exec rspec
  30. ໨࣍ • ϓϩτλΠϓΛ࡞ͬͨഎܠ • ϓϩτλΠϓͷߏ੒ͱઆ໌ • ·ͱΊ

  31. ϙΠϯτ • ॻ੶ͳͲͰΠϯϓοτ͢Δ • Ruby on Rails Λࢀߟʹ͢Δ • Capybara

    ʹ͍ͭͯ͸ɺҏ౻३Ұ͞Μͷهࣄ • ࢖͑ΔRSpecೖ໳ɾͦͷ4ʮͲΜͳϒϥ΢β ૢ࡞΋ࣗ༝ࣗࡏʂٯҾ͖Capybaraେࣙయʯ
  32. ࠓճ͸ϨΨγʔγεςϜ Ͱ͕ͨ͠ɾɾɾ ϚΠΫϩαʔϏεͱ͔ʹ΋࢖͑Δ͔΋ʁ

  33. ͝੩ௌ͋Γ͕ͱ͏ ͍͟͝·ͨ͠ɻ