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

e2e_prototype_capybara.pdf

 e2e_prototype_capybara.pdf

mokuo

May 10, 2018
Tweet

More Decks by mokuo

Other Decks in Programming

Transcript

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

    View full-size slide

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

    View full-size slide

  3. ܦྺ
    • େֶจܥ
    • Πϯλʔϯʢखಈςετ, WordPressʣ
    • ࣾձਓ̍೥໨
    • SIer (SE)
    • ࣾձਓ̎೥໨
    • ॴଐɿࣗࣾύοέʔδ։ൃɾൢച ← ຊ೔͸ίίͰͷ࿩
    • ग़޲ɿRailsडୗ։ൃ
    • ݱࡏɿSansan

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  6. ಥવͰ͕͢

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  9. CFML
    (ColdFusion Markup
    Language)

    #DateFormat(Now())#

    #TimeFormat(Now())#

    #TimeFormat(Now())#, #DateFormat(Now())#

    ࢀߟ"EPCF$PME'VTJPOϑϩʔ੍ޚ

    View full-size slide

  10. ColdFusion ͰͰ͖ͨγεςϜ
    • ࣗಈςετҰ੾ͳ͠
    • ຖճखಈςετ
    ·͋ɺԶ
    ؔ܎ͳ͍͠ɾɾɾ

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  15. σΟϨΫτϦߏ੒
    .
    !"" .env.sample
    !"" .gitignore
    !"" .ruby-version
    !"" Gemfile
    !"" Gemfile.lock
    !"" README.md
    #"" spec
    !"" features
    !"" pages
    !"" spec_helper.rb
    #"" support

    View full-size slide

  16. ֤ϑΝΠϧͷઆ໌

    View full-size slide

  17. Gemfile
    source "https://rubygems.org"
    gem 'capybara'
    gem 'selenium-webdriver'
    gem 'chromedriver-helper'
    gem 'dotenv'
    gem 'rspec'
    gem 'tapp'
    gem ‘byebug'

    View full-size slide

  18. .env.sample
    SYSTEM_URL= https://example.com/
    ADMIN_LOGIN= admin_user
    ADMIN_PASS= password
    HEADLESS= true

    View full-size slide

  19. .env ͷઆ໌
    ؀ڥม਺ આ໌ ྫ
    4:45&.@63- γεςϜͷ63- IUUQTFYBNQMFDPN
    "%.*/@-0(*/ ؅ཧऀͷϩάΠϯ*% MPHJO
    "%.*/@1"44 ؅ཧऀͷύεϫʔυ QBTTXPSE
    )&"%-&44
    ϔουϨεϞʔυͰ
    ࣮ߦ͢Δ͔
    USVF

    View full-size slide

  20. 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

    View full-size slide

  21. 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

    View full-size slide

  22. spec_helper.rb
    ΛඞͣಡΈࠐΉ
    require 'spec_helper'
    RSpec.feature 'γεςϜ؅ཧ', :type => :feature do
    background :all do
    system_admin_login

    View full-size slide

  23. ڞ௨ॲཧ͸Ϟδϡʔϧʹ੾Γग़͢
    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

    View full-size slide

  24. ϖʔδΦϒδΣΫτύλʔϯ
    • Selenium Ͱ͸༗໊ͳσβΠϯύλʔϯΒ͍͠
    • ϖʔδΛΫϥεʹݟཱͯΔ
    • ϘλϯΫϦοΫͳͲΛϝιουͱͯ࣋ͨͤ͠Δ
    • ϝϦοτ
    • ԿΛ͍ͯ͠Δ͔෼͔Γ΍͍͢
    • มߋ͠΍͍͢
    • ࠶ར༻͠΍͍͢

    View full-size slide

  25. ϢʔβʔϩάΠϯϖʔδ
    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

    View full-size slide

  26. ϢʔβʔϩάΠϯ
    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

    View full-size slide

  27. ϩʔΧϧͰͷ࣮ߦखॱ
    $ git clone [email protected]:xxxxx/xxxxx.git
    $ bundle install --path vendor/bundle
    $ cp .env.sample .env
    $ bundle exec rspec

    View full-size slide

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

    View full-size slide

  29. ϙΠϯτ
    • ॻ੶ͳͲͰΠϯϓοτ͢Δ
    • Ruby on Rails Λࢀߟʹ͢Δ
    • Capybara ʹ͍ͭͯ͸ɺҏ౻३Ұ͞Μͷهࣄ
    • ࢖͑ΔRSpecೖ໳ɾͦͷ4ʮͲΜͳϒϥ΢β
    ૢ࡞΋ࣗ༝ࣗࡏʂٯҾ͖Capybaraେࣙయʯ

    View full-size slide

  30. ࠓճ͸ϨΨγʔγεςϜ
    Ͱ͕ͨ͠ɾɾɾ
    ϚΠΫϩαʔϏεͱ͔ʹ΋࢖͑Δ͔΋ʁ

    View full-size slide

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

    View full-size slide