SlideShare a Scribd company logo
StevenYap
stevenyap@futureworkz.com
https://github.com/stevenyap
Capybara testing
A Garden City
A Lion City
Capybara testing
• Host Saigon.rb Ruby Meetup
• Co-Founder of Futureworkz
• Ruby on Rails coder
• Agile startup consultant
Awesome Ruby on Rails Development
http://www.futureworkz.com
http://playbook.futureworkz.com/
CAPYBARA TESTING
STEVEN YAP
CAPYBARA TESTING BY STEVEN YAP
WHAT IS CAPYBARA TESTING?
▸ Capybara is a gem for feature test (a.k.a. integration test)
▸ Loads your app in a browser and runs a test like a user
CAPYBARA TESTING BY STEVEN YAP
WHY DO CAPYBARA TESTING?
▸ Ensure all models/controllers/views are working together
▸ Ensure important user interactions are working
▸ Tests/Works with external scripts/windows such as Google
Map API, Paypal Sandbox
CAPYBARA TESTING BY STEVEN YAP
I HATE CAPYBARA TESTING!!!
▸ Slow
▸ Very slow
▸ Very very slow
▸ Breakable
▸ Very breakable
▸ Very very breakable
▸ Hard to debug
▸ Very hard to debug
▸ Very very hard to debug
CAPYBARA TESTING BY STEVEN YAP
WHERE TO APPLY CAPYBARA TESTING?
▸ Minimise number of capybara tests
▸ Happy paths
▸ Critical functions
WHEN I PUSH A MAJOR FEATURE TO
PRODUCTION,
I FEEL SAFER WHEN MY CAPYBARA
TESTS PASSED
Steven Yap
CAPYBARA TESTING BY STEVEN YAP
WHY SO SLOW?
CAPYBARA TESTING BY STEVEN YAP
WHY IS CAPYBARA TESTS SO SLOW?
▸ Loads entire app stack
▸ Calls many controllers/models/views
▸ By default, capybara does not run JS
CAPYBARA TESTING BY STEVEN YAP
RUNNING JAVASCRIPT WITH CAPYBARA
▸ https://rubygems.org/gems/selenium-webdriver/versions/
2.48.1 with Firefox
▸ https://github.com/thoughtbot/capybara-webkit with Qt
▸ https://github.com/teampoltergeist/poltergeist with
PhantomJS
▸ Add ‘js: true’ to your test case
CAPYBARA TESTING BY STEVEN YAP
WHY IS CAPYBARA TESTS SO SLOW?
▸ Loads entire app stack
▸ Runs Javascript including AJAX calls
▸ Loads external scripts such as Google fonts, CDN
Javascript libraries, etc (and executes it)
▸ Fully functional browser to test on
▸ Poor coding
CAPYBARA TESTING BY STEVEN YAP
POOR CODING
▸ Bloated CSS
▸ Slow/Too many AJAX calls
▸ Poor performance (eg. N + 1 queries)
▸ Too many external scripts (eg. 2 x date-picker libraries, full
modernizr library for video checking only)
CAPYBARA TESTING BY STEVEN YAP
DATABASE CLEANER
▸ Problem: Created user cannot login in Capybara JS test
▸ Reason: Javascript driver runs in a separate process from
database
▸ Solution: Change from transaction to truncation using
https://github.com/DatabaseCleaner/database_cleaner
▸ Read more: https://github.com/DatabaseCleaner/
database_cleaner#rspec-with-capybara-example
CAPYBARA TESTING BY STEVEN YAP
EXCLUDE CAPYBARA TEST
▸ RSpec.configure do |config|

config.filter_run_excluding(:js) unless ENV['ALL']

end
▸ rspec

=> will not run capybara tests
▸ ALL=1 rspec

=> will run all tests including capybara
WHY SO
BREAKABLE?
CAPYBARA TESTING BY STEVEN YAP
WHY IS CAPYBARA SO BREAKABLE?
▸ Failed tests in model/controller
▸ Text changes
▸ Design changes (eg. layout)
CAPYBARA TESTING BY STEVEN YAP
TARGET ELEMENT WISELY
▸ Use “within ‘#modal’ { }” to scope your targeting
▸ Avoid targeting an element by text or label
▸ Target an element by ID or field name
▸ Target an element by class
CAPYBARA TESTING BY STEVEN YAP
GOOD USE OF CSS CLASS NAME + SEMANTIC HTML
▸ Descriptive CSS class naming: 

<button class=“green” />
▸ Functional CSS class naming: 

<button class=“submit-button” />
▸ Non-semantic HTML:

<div class=“wrapper”><h1>Product Title</h1></div>
▸ Semantic HTML:

<div class=“product wrapper”>

<h1 class=“title”>Product Title</h1>

</div>
WHY SO
HARD TO DEBUG?
CAPYBARA TESTING BY STEVEN YAP
TOO MANY THINGS HAPPENING!
▸ Asset pipeline, Javascript functions, CSS rendering, partials,
controllers, models, database, EVERYTHING!!!
▸ Failure can come from anywhere (unlike functional/unit tests)
▸ External script loads too slow (timeout)
▸ Performance too bad (AJAX call timeout)
▸ Errors in assets compilation (SASS error)
▸ Javascript driver bugs
CAPYBARA TESTING BY STEVEN YAP
THINK LIKE A USER
▸ Capybara tests run like a real user using the site
▸ Anything your users cannot do = Your test cannot do
▸ User cannot post to a URL directly so your test code cannot
post to a URL directly like a controller test
▸ User cannot click on hidden elements (eg. a hidden link)
CAPYBARA TESTING BY STEVEN YAP
CAPYBARA DEBUGGING METHODS
▸ Make sure your development site works first!
▸ https://github.com/jnicklas/capybara#debugging
▸ https://github.com/mattheworiordan/capybara-screenshot
▸ Painful examination of rendered HTML
CAPYBARA TESTING BY STEVEN YAP
OVERLAYED ELEMENTS VS HIDDEN ELEMENTS
▸ Sometimes CSS styling overlay the original element with
another layout
▸ Eg. http://materializecss.com/forms.html#checkbox
▸ Forced click:

page.find(‘#user_terms_and_conditions’, visible:
false).trigger('click')
CAPYBARA TESTING BY STEVEN YAP
AJAX CALLS
▸ Difficult to debug
▸ Is the AJAX fired or fired with errors?
▸ Console.log() will output when running the test
▸ Understand when Capybara will wait or will not wait
▸ https://github.com/jnicklas/capybara#asynchronous-
javascript-ajax-and-friends
CAPYBARA TESTING BY STEVEN YAP
ACTIONVIEW::TEMPLATE::ERROR: END OF FILE REACHED
▸ Random bug that appeared
▸ https://github.com/jfirebaugh/konacha/issues/123
▸ Reason: sprockets reading uncompiled asset files
▸ Solution: gem 'sprockets-rails', '~> 3.0.0', :require =>
'sprockets/railtie'
PAYPAL SANDBOX
CAPYBARA TESTING BY STEVEN YAP
PAYPAL SANDBOX
def make_payment_via_paypal()
using_wait_time(30) do
resolve_paypal_js_error
click_on 'Pay with my PayPal account'
within '#method-paypal' do
fill_in 'Email', with: Rails.application.secrets.paypal_testing_email
fill_in 'PayPal password', with: Rails.application.secrets.paypal_testing_password
click_on 'Log In'
end
find('#continue_abovefold').click
expect(page).not_to have_content 'Loading...'
end
end
# Paypal has a JS error
# where it cannot find div#paywithmybank_container
def resolve_paypal_js_error
execute_script <<-EOF
var ele = document.createElement("DIV");
ele.id = "paywithmybank_container";
document.getElementsByTagName("body")[0].appendChild(ele);
EOF
end
CAPYBARA TESTING BY STEVEN YAP
DO CAPYBARA TEST
▸ It is the Ultimate Test
▸ Give assurances to critical functions
▸ Helps you to think about your views
▸ Easier with experience
Thank you!
Awesome Ruby on Rails Development
http://www.futureworkz.com
http://playbook.futureworkz.com/
Ad

More Related Content

What's hot (20)

Test automation with Cucumber-JVM
Test automation with Cucumber-JVMTest automation with Cucumber-JVM
Test automation with Cucumber-JVM
Alan Parkinson
 
How do I write Testable Javascript - Presented at dev.Objective() June 16, 2016
How do I write Testable Javascript - Presented at dev.Objective() June 16, 2016How do I write Testable Javascript - Presented at dev.Objective() June 16, 2016
How do I write Testable Javascript - Presented at dev.Objective() June 16, 2016
Gavin Pickin
 
Jest: Frontend Testing richtig gemacht @WebworkerNRW
Jest: Frontend Testing richtig gemacht @WebworkerNRWJest: Frontend Testing richtig gemacht @WebworkerNRW
Jest: Frontend Testing richtig gemacht @WebworkerNRW
Holger Grosse-Plankermann
 
Making Watir and Cucumber an efficient tool for Web UI Automation
Making Watir and Cucumber an efficient tool for Web UI AutomationMaking Watir and Cucumber an efficient tool for Web UI Automation
Making Watir and Cucumber an efficient tool for Web UI Automation
Ruslan Strazhnyk
 
Better Page Object Handling with Loadable Component Pattern
Better Page Object Handling with Loadable Component PatternBetter Page Object Handling with Loadable Component Pattern
Better Page Object Handling with Loadable Component Pattern
Sargis Sargsyan
 
Integration Testing With Cucumber How To Test Anything J A O O 2009
Integration Testing With  Cucumber    How To Test Anything    J A O O 2009Integration Testing With  Cucumber    How To Test Anything    J A O O 2009
Integration Testing With Cucumber How To Test Anything J A O O 2009
Dr Nic Williams
 
The LAZY Developer's Guide to BDD (with Cucumber)
The LAZY Developer's Guide to BDD (with Cucumber)The LAZY Developer's Guide to BDD (with Cucumber)
The LAZY Developer's Guide to BDD (with Cucumber)
Tze Yang Ng
 
Automate Thyself
Automate ThyselfAutomate Thyself
Automate Thyself
Ortus Solutions, Corp
 
Better End-to-End Testing with Page Objects Model using Protractor
Better End-to-End Testing with Page Objects Model using ProtractorBetter End-to-End Testing with Page Objects Model using Protractor
Better End-to-End Testing with Page Objects Model using Protractor
Kasun Kodagoda
 
Behavior Driven Development and Automation Testing Using Cucumber
Behavior Driven Development and Automation Testing Using CucumberBehavior Driven Development and Automation Testing Using Cucumber
Behavior Driven Development and Automation Testing Using Cucumber
KMS Technology
 
Integration Testing with Selenium
Integration Testing with SeleniumIntegration Testing with Selenium
Integration Testing with Selenium
All Things Open
 
How do I Write Testable Javascript so I can Test my CF API on Server and Client
How do I Write Testable Javascript so I can Test my CF API on Server and ClientHow do I Write Testable Javascript so I can Test my CF API on Server and Client
How do I Write Testable Javascript so I can Test my CF API on Server and Client
ColdFusionConference
 
Introduction to cypress in Angular (Chinese)
Introduction to cypress in Angular (Chinese)Introduction to cypress in Angular (Chinese)
Introduction to cypress in Angular (Chinese)
Hong Tat Yew
 
Conquering AngularJS Limitations
Conquering AngularJS LimitationsConquering AngularJS Limitations
Conquering AngularJS Limitations
Valeri Karpov
 
Continuous Integration Testing in Django
Continuous Integration Testing in DjangoContinuous Integration Testing in Django
Continuous Integration Testing in Django
Kevin Harvey
 
Front-End Testing: Demystified
Front-End Testing: DemystifiedFront-End Testing: Demystified
Front-End Testing: Demystified
Seth McLaughlin
 
Automated Testing in Angular Slides
Automated Testing in Angular SlidesAutomated Testing in Angular Slides
Automated Testing in Angular Slides
Jim Lynch
 
Das Frontend richtig Testen – mit Jest @Developer Week 2018
Das Frontend richtig Testen – mit Jest @Developer Week 2018Das Frontend richtig Testen – mit Jest @Developer Week 2018
Das Frontend richtig Testen – mit Jest @Developer Week 2018
Holger Grosse-Plankermann
 
Protractor Tutorial Quality in Agile 2015
Protractor Tutorial Quality in Agile 2015Protractor Tutorial Quality in Agile 2015
Protractor Tutorial Quality in Agile 2015
Andrew Eisenberg
 
Writing Software not Code with Cucumber
Writing Software not Code with CucumberWriting Software not Code with Cucumber
Writing Software not Code with Cucumber
Ben Mabey
 
Test automation with Cucumber-JVM
Test automation with Cucumber-JVMTest automation with Cucumber-JVM
Test automation with Cucumber-JVM
Alan Parkinson
 
How do I write Testable Javascript - Presented at dev.Objective() June 16, 2016
How do I write Testable Javascript - Presented at dev.Objective() June 16, 2016How do I write Testable Javascript - Presented at dev.Objective() June 16, 2016
How do I write Testable Javascript - Presented at dev.Objective() June 16, 2016
Gavin Pickin
 
Jest: Frontend Testing richtig gemacht @WebworkerNRW
Jest: Frontend Testing richtig gemacht @WebworkerNRWJest: Frontend Testing richtig gemacht @WebworkerNRW
Jest: Frontend Testing richtig gemacht @WebworkerNRW
Holger Grosse-Plankermann
 
Making Watir and Cucumber an efficient tool for Web UI Automation
Making Watir and Cucumber an efficient tool for Web UI AutomationMaking Watir and Cucumber an efficient tool for Web UI Automation
Making Watir and Cucumber an efficient tool for Web UI Automation
Ruslan Strazhnyk
 
Better Page Object Handling with Loadable Component Pattern
Better Page Object Handling with Loadable Component PatternBetter Page Object Handling with Loadable Component Pattern
Better Page Object Handling with Loadable Component Pattern
Sargis Sargsyan
 
Integration Testing With Cucumber How To Test Anything J A O O 2009
Integration Testing With  Cucumber    How To Test Anything    J A O O 2009Integration Testing With  Cucumber    How To Test Anything    J A O O 2009
Integration Testing With Cucumber How To Test Anything J A O O 2009
Dr Nic Williams
 
The LAZY Developer's Guide to BDD (with Cucumber)
The LAZY Developer's Guide to BDD (with Cucumber)The LAZY Developer's Guide to BDD (with Cucumber)
The LAZY Developer's Guide to BDD (with Cucumber)
Tze Yang Ng
 
Better End-to-End Testing with Page Objects Model using Protractor
Better End-to-End Testing with Page Objects Model using ProtractorBetter End-to-End Testing with Page Objects Model using Protractor
Better End-to-End Testing with Page Objects Model using Protractor
Kasun Kodagoda
 
Behavior Driven Development and Automation Testing Using Cucumber
Behavior Driven Development and Automation Testing Using CucumberBehavior Driven Development and Automation Testing Using Cucumber
Behavior Driven Development and Automation Testing Using Cucumber
KMS Technology
 
Integration Testing with Selenium
Integration Testing with SeleniumIntegration Testing with Selenium
Integration Testing with Selenium
All Things Open
 
How do I Write Testable Javascript so I can Test my CF API on Server and Client
How do I Write Testable Javascript so I can Test my CF API on Server and ClientHow do I Write Testable Javascript so I can Test my CF API on Server and Client
How do I Write Testable Javascript so I can Test my CF API on Server and Client
ColdFusionConference
 
Introduction to cypress in Angular (Chinese)
Introduction to cypress in Angular (Chinese)Introduction to cypress in Angular (Chinese)
Introduction to cypress in Angular (Chinese)
Hong Tat Yew
 
Conquering AngularJS Limitations
Conquering AngularJS LimitationsConquering AngularJS Limitations
Conquering AngularJS Limitations
Valeri Karpov
 
Continuous Integration Testing in Django
Continuous Integration Testing in DjangoContinuous Integration Testing in Django
Continuous Integration Testing in Django
Kevin Harvey
 
Front-End Testing: Demystified
Front-End Testing: DemystifiedFront-End Testing: Demystified
Front-End Testing: Demystified
Seth McLaughlin
 
Automated Testing in Angular Slides
Automated Testing in Angular SlidesAutomated Testing in Angular Slides
Automated Testing in Angular Slides
Jim Lynch
 
Das Frontend richtig Testen – mit Jest @Developer Week 2018
Das Frontend richtig Testen – mit Jest @Developer Week 2018Das Frontend richtig Testen – mit Jest @Developer Week 2018
Das Frontend richtig Testen – mit Jest @Developer Week 2018
Holger Grosse-Plankermann
 
Protractor Tutorial Quality in Agile 2015
Protractor Tutorial Quality in Agile 2015Protractor Tutorial Quality in Agile 2015
Protractor Tutorial Quality in Agile 2015
Andrew Eisenberg
 
Writing Software not Code with Cucumber
Writing Software not Code with CucumberWriting Software not Code with Cucumber
Writing Software not Code with Cucumber
Ben Mabey
 

Viewers also liked (20)

Testing Microservices with a Citrus twist
Testing Microservices with a Citrus twistTesting Microservices with a Citrus twist
Testing Microservices with a Citrus twist
christophd
 
Bdd (Behavior Driven Development)
Bdd (Behavior Driven Development)Bdd (Behavior Driven Development)
Bdd (Behavior Driven Development)
Helder De Oliveira
 
Testing Java EE apps with Arquillian
Testing Java EE apps with ArquillianTesting Java EE apps with Arquillian
Testing Java EE apps with Arquillian
Ivan Ivanov
 
Workshop calabash appium
Workshop calabash appiumWorkshop calabash appium
Workshop calabash appium
Enrique Sánchez-Bayuela
 
Arquillian & Citrus
Arquillian & CitrusArquillian & Citrus
Arquillian & Citrus
christophd
 
Pruebas funcionales de Software
Pruebas funcionales de SoftwarePruebas funcionales de Software
Pruebas funcionales de Software
Brian Pando
 
Automated Acceptance Tests & Tool choice
Automated Acceptance Tests & Tool choiceAutomated Acceptance Tests & Tool choice
Automated Acceptance Tests & Tool choice
toddbr
 
Three Uses Of JIRA Beyond Bug Tracking
Three Uses Of JIRA Beyond Bug TrackingThree Uses Of JIRA Beyond Bug Tracking
Three Uses Of JIRA Beyond Bug Tracking
Atlassian
 
TestLink introduction
TestLink introductionTestLink introduction
TestLink introduction
David Ionut
 
Introduction To Confluence
Introduction To ConfluenceIntroduction To Confluence
Introduction To Confluence
Hua Soon Sim
 
Jira as a Tool for Test Management
Jira as a Tool for Test ManagementJira as a Tool for Test Management
Jira as a Tool for Test Management
Maija Laksa
 
Using JIRA Software for Issue Tracking
Using JIRA Software for Issue TrackingUsing JIRA Software for Issue Tracking
Using JIRA Software for Issue Tracking
Anjali Rao
 
Introduction To Jira
Introduction To JiraIntroduction To Jira
Introduction To Jira
Hua Soon Sim
 
Story Testing Approach for Enterprise Applications using Selenium Framework
Story Testing Approach for Enterprise Applications using Selenium FrameworkStory Testing Approach for Enterprise Applications using Selenium Framework
Story Testing Approach for Enterprise Applications using Selenium Framework
Oleksiy Rezchykov
 
Next level of Appium
Next level of AppiumNext level of Appium
Next level of Appium
Keshav Kashyap
 
Automate you Appium test like a pro!
Automate you Appium test like a pro!Automate you Appium test like a pro!
Automate you Appium test like a pro!
TestObject - Mobile Testing
 
Gerrit is Getting Native with RPM, Deb and Docker
Gerrit is Getting Native with RPM, Deb and DockerGerrit is Getting Native with RPM, Deb and Docker
Gerrit is Getting Native with RPM, Deb and Docker
Luca Milanesio
 
Introduction to Bdd and cucumber
Introduction to Bdd and cucumberIntroduction to Bdd and cucumber
Introduction to Bdd and cucumber
Nibu Baby
 
DevQA: make your testers happier with Groovy, Spock and Geb (Greach 2014)
DevQA: make your testers happier with Groovy, Spock and Geb (Greach 2014)DevQA: make your testers happier with Groovy, Spock and Geb (Greach 2014)
DevQA: make your testers happier with Groovy, Spock and Geb (Greach 2014)
Alvaro Sanchez-Mariscal
 
Continuous integration using Jenkins and Sonar
Continuous integration using Jenkins and SonarContinuous integration using Jenkins and Sonar
Continuous integration using Jenkins and Sonar
Pascal Larocque
 
Testing Microservices with a Citrus twist
Testing Microservices with a Citrus twistTesting Microservices with a Citrus twist
Testing Microservices with a Citrus twist
christophd
 
Bdd (Behavior Driven Development)
Bdd (Behavior Driven Development)Bdd (Behavior Driven Development)
Bdd (Behavior Driven Development)
Helder De Oliveira
 
Testing Java EE apps with Arquillian
Testing Java EE apps with ArquillianTesting Java EE apps with Arquillian
Testing Java EE apps with Arquillian
Ivan Ivanov
 
Arquillian & Citrus
Arquillian & CitrusArquillian & Citrus
Arquillian & Citrus
christophd
 
Pruebas funcionales de Software
Pruebas funcionales de SoftwarePruebas funcionales de Software
Pruebas funcionales de Software
Brian Pando
 
Automated Acceptance Tests & Tool choice
Automated Acceptance Tests & Tool choiceAutomated Acceptance Tests & Tool choice
Automated Acceptance Tests & Tool choice
toddbr
 
Three Uses Of JIRA Beyond Bug Tracking
Three Uses Of JIRA Beyond Bug TrackingThree Uses Of JIRA Beyond Bug Tracking
Three Uses Of JIRA Beyond Bug Tracking
Atlassian
 
TestLink introduction
TestLink introductionTestLink introduction
TestLink introduction
David Ionut
 
Introduction To Confluence
Introduction To ConfluenceIntroduction To Confluence
Introduction To Confluence
Hua Soon Sim
 
Jira as a Tool for Test Management
Jira as a Tool for Test ManagementJira as a Tool for Test Management
Jira as a Tool for Test Management
Maija Laksa
 
Using JIRA Software for Issue Tracking
Using JIRA Software for Issue TrackingUsing JIRA Software for Issue Tracking
Using JIRA Software for Issue Tracking
Anjali Rao
 
Introduction To Jira
Introduction To JiraIntroduction To Jira
Introduction To Jira
Hua Soon Sim
 
Story Testing Approach for Enterprise Applications using Selenium Framework
Story Testing Approach for Enterprise Applications using Selenium FrameworkStory Testing Approach for Enterprise Applications using Selenium Framework
Story Testing Approach for Enterprise Applications using Selenium Framework
Oleksiy Rezchykov
 
Gerrit is Getting Native with RPM, Deb and Docker
Gerrit is Getting Native with RPM, Deb and DockerGerrit is Getting Native with RPM, Deb and Docker
Gerrit is Getting Native with RPM, Deb and Docker
Luca Milanesio
 
Introduction to Bdd and cucumber
Introduction to Bdd and cucumberIntroduction to Bdd and cucumber
Introduction to Bdd and cucumber
Nibu Baby
 
DevQA: make your testers happier with Groovy, Spock and Geb (Greach 2014)
DevQA: make your testers happier with Groovy, Spock and Geb (Greach 2014)DevQA: make your testers happier with Groovy, Spock and Geb (Greach 2014)
DevQA: make your testers happier with Groovy, Spock and Geb (Greach 2014)
Alvaro Sanchez-Mariscal
 
Continuous integration using Jenkins and Sonar
Continuous integration using Jenkins and SonarContinuous integration using Jenkins and Sonar
Continuous integration using Jenkins and Sonar
Pascal Larocque
 
Ad

Similar to Capybara testing (20)

Capybara with Rspec
Capybara with RspecCapybara with Rspec
Capybara with Rspec
Omnia Helmi
 
Real-World DevOps — 20 Practical Developers Tips for Tightening Your Operatio...
Real-World DevOps — 20 Practical Developers Tips for Tightening Your Operatio...Real-World DevOps — 20 Practical Developers Tips for Tightening Your Operatio...
Real-World DevOps — 20 Practical Developers Tips for Tightening Your Operatio...
VictorSzoltysek
 
Continuous Testing With React Storybook & WebdriverIO
Continuous Testing With React Storybook & WebdriverIOContinuous Testing With React Storybook & WebdriverIO
Continuous Testing With React Storybook & WebdriverIO
Josh Cypher
 
How to write Testable Javascript
How to write Testable JavascriptHow to write Testable Javascript
How to write Testable Javascript
ColdFusionConference
 
Building scala with bazel
Building scala with bazelBuilding scala with bazel
Building scala with bazel
Natan Silnitsky
 
Introduction to Continous Integration with WordPress
Introduction to Continous Integration with WordPressIntroduction to Continous Integration with WordPress
Introduction to Continous Integration with WordPress
Seagyn Davis
 
Mocking - Visug session
Mocking - Visug sessionMocking - Visug session
Mocking - Visug session
Maarten Balliauw
 
Java Web Start czyli jak żyć z tą dziwną technologią & Continuous Delivery w ...
Java Web Start czyli jak żyć z tą dziwną technologią & Continuous Delivery w ...Java Web Start czyli jak żyć z tą dziwną technologią & Continuous Delivery w ...
Java Web Start czyli jak żyć z tą dziwną technologią & Continuous Delivery w ...
MarcinStachniuk
 
Autotesting rails app
Autotesting rails appAutotesting rails app
Autotesting rails app
Anton Naumenko
 
Agile Java Testing With Open Source Frameworks
Agile Java Testing With Open Source FrameworksAgile Java Testing With Open Source Frameworks
Agile Java Testing With Open Source Frameworks
Viraf Karai
 
Blazing Fast Feedback Loops in the Java Universe
Blazing Fast Feedback Loops in the Java UniverseBlazing Fast Feedback Loops in the Java Universe
Blazing Fast Feedback Loops in the Java Universe
Michał Kordas
 
Introduction to test_driven_development
Introduction to test_driven_developmentIntroduction to test_driven_development
Introduction to test_driven_development
haochenglee
 
Running Containerized Node.js Services on AWS Elastic Beanstalk
Running Containerized Node.js Services on AWS Elastic BeanstalkRunning Containerized Node.js Services on AWS Elastic Beanstalk
Running Containerized Node.js Services on AWS Elastic Beanstalk
zupzup.org
 
Serenity BDD Workshop - 9th March 2016
Serenity BDD Workshop - 9th March 2016Serenity BDD Workshop - 9th March 2016
Serenity BDD Workshop - 9th March 2016
vodqasg
 
BDD / cucumber /Capybara
BDD / cucumber /CapybaraBDD / cucumber /Capybara
BDD / cucumber /Capybara
ShraddhaSF
 
JavaScript - Web Development Fundaments Part 2 - DeepDive Learning Academy
JavaScript - Web Development Fundaments Part 2 - DeepDive Learning AcademyJavaScript - Web Development Fundaments Part 2 - DeepDive Learning Academy
JavaScript - Web Development Fundaments Part 2 - DeepDive Learning Academy
Parag Mujumdar
 
Wicket Deliver Your Webapp On Time
Wicket Deliver Your Webapp On TimeWicket Deliver Your Webapp On Time
Wicket Deliver Your Webapp On Time
Will Hoover
 
Why Use Rails by Dr Nic
Why Use Rails by  Dr NicWhy Use Rails by  Dr Nic
Why Use Rails by Dr Nic
Dr Nic Williams
 
Ugo Cei Presentation
Ugo Cei PresentationUgo Cei Presentation
Ugo Cei Presentation
RubyOnRails_dude
 
Thomas Fuchs Presentation
Thomas Fuchs PresentationThomas Fuchs Presentation
Thomas Fuchs Presentation
RubyOnRails_dude
 
Capybara with Rspec
Capybara with RspecCapybara with Rspec
Capybara with Rspec
Omnia Helmi
 
Real-World DevOps — 20 Practical Developers Tips for Tightening Your Operatio...
Real-World DevOps — 20 Practical Developers Tips for Tightening Your Operatio...Real-World DevOps — 20 Practical Developers Tips for Tightening Your Operatio...
Real-World DevOps — 20 Practical Developers Tips for Tightening Your Operatio...
VictorSzoltysek
 
Continuous Testing With React Storybook & WebdriverIO
Continuous Testing With React Storybook & WebdriverIOContinuous Testing With React Storybook & WebdriverIO
Continuous Testing With React Storybook & WebdriverIO
Josh Cypher
 
Building scala with bazel
Building scala with bazelBuilding scala with bazel
Building scala with bazel
Natan Silnitsky
 
Introduction to Continous Integration with WordPress
Introduction to Continous Integration with WordPressIntroduction to Continous Integration with WordPress
Introduction to Continous Integration with WordPress
Seagyn Davis
 
Java Web Start czyli jak żyć z tą dziwną technologią & Continuous Delivery w ...
Java Web Start czyli jak żyć z tą dziwną technologią & Continuous Delivery w ...Java Web Start czyli jak żyć z tą dziwną technologią & Continuous Delivery w ...
Java Web Start czyli jak żyć z tą dziwną technologią & Continuous Delivery w ...
MarcinStachniuk
 
Agile Java Testing With Open Source Frameworks
Agile Java Testing With Open Source FrameworksAgile Java Testing With Open Source Frameworks
Agile Java Testing With Open Source Frameworks
Viraf Karai
 
Blazing Fast Feedback Loops in the Java Universe
Blazing Fast Feedback Loops in the Java UniverseBlazing Fast Feedback Loops in the Java Universe
Blazing Fast Feedback Loops in the Java Universe
Michał Kordas
 
Introduction to test_driven_development
Introduction to test_driven_developmentIntroduction to test_driven_development
Introduction to test_driven_development
haochenglee
 
Running Containerized Node.js Services on AWS Elastic Beanstalk
Running Containerized Node.js Services on AWS Elastic BeanstalkRunning Containerized Node.js Services on AWS Elastic Beanstalk
Running Containerized Node.js Services on AWS Elastic Beanstalk
zupzup.org
 
Serenity BDD Workshop - 9th March 2016
Serenity BDD Workshop - 9th March 2016Serenity BDD Workshop - 9th March 2016
Serenity BDD Workshop - 9th March 2016
vodqasg
 
BDD / cucumber /Capybara
BDD / cucumber /CapybaraBDD / cucumber /Capybara
BDD / cucumber /Capybara
ShraddhaSF
 
JavaScript - Web Development Fundaments Part 2 - DeepDive Learning Academy
JavaScript - Web Development Fundaments Part 2 - DeepDive Learning AcademyJavaScript - Web Development Fundaments Part 2 - DeepDive Learning Academy
JavaScript - Web Development Fundaments Part 2 - DeepDive Learning Academy
Parag Mujumdar
 
Wicket Deliver Your Webapp On Time
Wicket Deliver Your Webapp On TimeWicket Deliver Your Webapp On Time
Wicket Deliver Your Webapp On Time
Will Hoover
 
Ad

Recently uploaded (20)

Designing AI-Powered APIs on Azure: Best Practices& Considerations
Designing AI-Powered APIs on Azure: Best Practices& ConsiderationsDesigning AI-Powered APIs on Azure: Best Practices& Considerations
Designing AI-Powered APIs on Azure: Best Practices& Considerations
Dinusha Kumarasiri
 
Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)
Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)
Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)
Andre Hora
 
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRYLEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
NidaFarooq10
 
Landscape of Requirements Engineering for/by AI through Literature Review
Landscape of Requirements Engineering for/by AI through Literature ReviewLandscape of Requirements Engineering for/by AI through Literature Review
Landscape of Requirements Engineering for/by AI through Literature Review
Hironori Washizaki
 
How to Optimize Your AWS Environment for Improved Cloud Performance
How to Optimize Your AWS Environment for Improved Cloud PerformanceHow to Optimize Your AWS Environment for Improved Cloud Performance
How to Optimize Your AWS Environment for Improved Cloud Performance
ThousandEyes
 
Societal challenges of AI: biases, multilinguism and sustainability
Societal challenges of AI: biases, multilinguism and sustainabilitySocietal challenges of AI: biases, multilinguism and sustainability
Societal challenges of AI: biases, multilinguism and sustainability
Jordi Cabot
 
Douwan Crack 2025 new verson+ License code
Douwan Crack 2025 new verson+ License codeDouwan Crack 2025 new verson+ License code
Douwan Crack 2025 new verson+ License code
aneelaramzan63
 
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Lionel Briand
 
Adobe Illustrator Crack FREE Download 2025 Latest Version
Adobe Illustrator Crack FREE Download 2025 Latest VersionAdobe Illustrator Crack FREE Download 2025 Latest Version
Adobe Illustrator Crack FREE Download 2025 Latest Version
kashifyounis067
 
Secure Test Infrastructure: The Backbone of Trustworthy Software Development
Secure Test Infrastructure: The Backbone of Trustworthy Software DevelopmentSecure Test Infrastructure: The Backbone of Trustworthy Software Development
Secure Test Infrastructure: The Backbone of Trustworthy Software Development
Shubham Joshi
 
WinRAR Crack for Windows (100% Working 2025)
WinRAR Crack for Windows (100% Working 2025)WinRAR Crack for Windows (100% Working 2025)
WinRAR Crack for Windows (100% Working 2025)
sh607827
 
Adobe Lightroom Classic Crack FREE Latest link 2025
Adobe Lightroom Classic Crack FREE Latest link 2025Adobe Lightroom Classic Crack FREE Latest link 2025
Adobe Lightroom Classic Crack FREE Latest link 2025
kashifyounis067
 
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
AxisTechnolabs
 
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
Egor Kaleynik
 
Scaling GraphRAG: Efficient Knowledge Retrieval for Enterprise AI
Scaling GraphRAG:  Efficient Knowledge Retrieval for Enterprise AIScaling GraphRAG:  Efficient Knowledge Retrieval for Enterprise AI
Scaling GraphRAG: Efficient Knowledge Retrieval for Enterprise AI
danshalev
 
Not So Common Memory Leaks in Java Webinar
Not So Common Memory Leaks in Java WebinarNot So Common Memory Leaks in Java Webinar
Not So Common Memory Leaks in Java Webinar
Tier1 app
 
Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...
Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...
Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...
Ranjan Baisak
 
Explaining GitHub Actions Failures with Large Language Models Challenges, In...
Explaining GitHub Actions Failures with Large Language Models Challenges, In...Explaining GitHub Actions Failures with Large Language Models Challenges, In...
Explaining GitHub Actions Failures with Large Language Models Challenges, In...
ssuserb14185
 
Meet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Meet the Agents: How AI Is Learning to Think, Plan, and CollaborateMeet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Meet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Maxim Salnikov
 
Avast Premium Security Crack FREE Latest Version 2025
Avast Premium Security Crack FREE Latest Version 2025Avast Premium Security Crack FREE Latest Version 2025
Avast Premium Security Crack FREE Latest Version 2025
mu394968
 
Designing AI-Powered APIs on Azure: Best Practices& Considerations
Designing AI-Powered APIs on Azure: Best Practices& ConsiderationsDesigning AI-Powered APIs on Azure: Best Practices& Considerations
Designing AI-Powered APIs on Azure: Best Practices& Considerations
Dinusha Kumarasiri
 
Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)
Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)
Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)
Andre Hora
 
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRYLEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
NidaFarooq10
 
Landscape of Requirements Engineering for/by AI through Literature Review
Landscape of Requirements Engineering for/by AI through Literature ReviewLandscape of Requirements Engineering for/by AI through Literature Review
Landscape of Requirements Engineering for/by AI through Literature Review
Hironori Washizaki
 
How to Optimize Your AWS Environment for Improved Cloud Performance
How to Optimize Your AWS Environment for Improved Cloud PerformanceHow to Optimize Your AWS Environment for Improved Cloud Performance
How to Optimize Your AWS Environment for Improved Cloud Performance
ThousandEyes
 
Societal challenges of AI: biases, multilinguism and sustainability
Societal challenges of AI: biases, multilinguism and sustainabilitySocietal challenges of AI: biases, multilinguism and sustainability
Societal challenges of AI: biases, multilinguism and sustainability
Jordi Cabot
 
Douwan Crack 2025 new verson+ License code
Douwan Crack 2025 new verson+ License codeDouwan Crack 2025 new verson+ License code
Douwan Crack 2025 new verson+ License code
aneelaramzan63
 
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Lionel Briand
 
Adobe Illustrator Crack FREE Download 2025 Latest Version
Adobe Illustrator Crack FREE Download 2025 Latest VersionAdobe Illustrator Crack FREE Download 2025 Latest Version
Adobe Illustrator Crack FREE Download 2025 Latest Version
kashifyounis067
 
Secure Test Infrastructure: The Backbone of Trustworthy Software Development
Secure Test Infrastructure: The Backbone of Trustworthy Software DevelopmentSecure Test Infrastructure: The Backbone of Trustworthy Software Development
Secure Test Infrastructure: The Backbone of Trustworthy Software Development
Shubham Joshi
 
WinRAR Crack for Windows (100% Working 2025)
WinRAR Crack for Windows (100% Working 2025)WinRAR Crack for Windows (100% Working 2025)
WinRAR Crack for Windows (100% Working 2025)
sh607827
 
Adobe Lightroom Classic Crack FREE Latest link 2025
Adobe Lightroom Classic Crack FREE Latest link 2025Adobe Lightroom Classic Crack FREE Latest link 2025
Adobe Lightroom Classic Crack FREE Latest link 2025
kashifyounis067
 
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
AxisTechnolabs
 
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
Egor Kaleynik
 
Scaling GraphRAG: Efficient Knowledge Retrieval for Enterprise AI
Scaling GraphRAG:  Efficient Knowledge Retrieval for Enterprise AIScaling GraphRAG:  Efficient Knowledge Retrieval for Enterprise AI
Scaling GraphRAG: Efficient Knowledge Retrieval for Enterprise AI
danshalev
 
Not So Common Memory Leaks in Java Webinar
Not So Common Memory Leaks in Java WebinarNot So Common Memory Leaks in Java Webinar
Not So Common Memory Leaks in Java Webinar
Tier1 app
 
Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...
Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...
Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...
Ranjan Baisak
 
Explaining GitHub Actions Failures with Large Language Models Challenges, In...
Explaining GitHub Actions Failures with Large Language Models Challenges, In...Explaining GitHub Actions Failures with Large Language Models Challenges, In...
Explaining GitHub Actions Failures with Large Language Models Challenges, In...
ssuserb14185
 
Meet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Meet the Agents: How AI Is Learning to Think, Plan, and CollaborateMeet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Meet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Maxim Salnikov
 
Avast Premium Security Crack FREE Latest Version 2025
Avast Premium Security Crack FREE Latest Version 2025Avast Premium Security Crack FREE Latest Version 2025
Avast Premium Security Crack FREE Latest Version 2025
mu394968
 

Capybara testing

  • 6. • Host Saigon.rb Ruby Meetup • Co-Founder of Futureworkz • Ruby on Rails coder • Agile startup consultant
  • 7. Awesome Ruby on Rails Development http://www.futureworkz.com http://playbook.futureworkz.com/
  • 9. CAPYBARA TESTING BY STEVEN YAP WHAT IS CAPYBARA TESTING? ▸ Capybara is a gem for feature test (a.k.a. integration test) ▸ Loads your app in a browser and runs a test like a user
  • 10. CAPYBARA TESTING BY STEVEN YAP WHY DO CAPYBARA TESTING? ▸ Ensure all models/controllers/views are working together ▸ Ensure important user interactions are working ▸ Tests/Works with external scripts/windows such as Google Map API, Paypal Sandbox
  • 11. CAPYBARA TESTING BY STEVEN YAP I HATE CAPYBARA TESTING!!! ▸ Slow ▸ Very slow ▸ Very very slow ▸ Breakable ▸ Very breakable ▸ Very very breakable ▸ Hard to debug ▸ Very hard to debug ▸ Very very hard to debug
  • 12. CAPYBARA TESTING BY STEVEN YAP WHERE TO APPLY CAPYBARA TESTING? ▸ Minimise number of capybara tests ▸ Happy paths ▸ Critical functions
  • 13. WHEN I PUSH A MAJOR FEATURE TO PRODUCTION, I FEEL SAFER WHEN MY CAPYBARA TESTS PASSED Steven Yap CAPYBARA TESTING BY STEVEN YAP
  • 15. CAPYBARA TESTING BY STEVEN YAP WHY IS CAPYBARA TESTS SO SLOW? ▸ Loads entire app stack ▸ Calls many controllers/models/views ▸ By default, capybara does not run JS
  • 16. CAPYBARA TESTING BY STEVEN YAP RUNNING JAVASCRIPT WITH CAPYBARA ▸ https://rubygems.org/gems/selenium-webdriver/versions/ 2.48.1 with Firefox ▸ https://github.com/thoughtbot/capybara-webkit with Qt ▸ https://github.com/teampoltergeist/poltergeist with PhantomJS ▸ Add ‘js: true’ to your test case
  • 17. CAPYBARA TESTING BY STEVEN YAP WHY IS CAPYBARA TESTS SO SLOW? ▸ Loads entire app stack ▸ Runs Javascript including AJAX calls ▸ Loads external scripts such as Google fonts, CDN Javascript libraries, etc (and executes it) ▸ Fully functional browser to test on ▸ Poor coding
  • 18. CAPYBARA TESTING BY STEVEN YAP POOR CODING ▸ Bloated CSS ▸ Slow/Too many AJAX calls ▸ Poor performance (eg. N + 1 queries) ▸ Too many external scripts (eg. 2 x date-picker libraries, full modernizr library for video checking only)
  • 19. CAPYBARA TESTING BY STEVEN YAP DATABASE CLEANER ▸ Problem: Created user cannot login in Capybara JS test ▸ Reason: Javascript driver runs in a separate process from database ▸ Solution: Change from transaction to truncation using https://github.com/DatabaseCleaner/database_cleaner ▸ Read more: https://github.com/DatabaseCleaner/ database_cleaner#rspec-with-capybara-example
  • 20. CAPYBARA TESTING BY STEVEN YAP EXCLUDE CAPYBARA TEST ▸ RSpec.configure do |config|
 config.filter_run_excluding(:js) unless ENV['ALL']
 end ▸ rspec
 => will not run capybara tests ▸ ALL=1 rspec
 => will run all tests including capybara
  • 22. CAPYBARA TESTING BY STEVEN YAP WHY IS CAPYBARA SO BREAKABLE? ▸ Failed tests in model/controller ▸ Text changes ▸ Design changes (eg. layout)
  • 23. CAPYBARA TESTING BY STEVEN YAP TARGET ELEMENT WISELY ▸ Use “within ‘#modal’ { }” to scope your targeting ▸ Avoid targeting an element by text or label ▸ Target an element by ID or field name ▸ Target an element by class
  • 24. CAPYBARA TESTING BY STEVEN YAP GOOD USE OF CSS CLASS NAME + SEMANTIC HTML ▸ Descriptive CSS class naming: 
 <button class=“green” /> ▸ Functional CSS class naming: 
 <button class=“submit-button” /> ▸ Non-semantic HTML:
 <div class=“wrapper”><h1>Product Title</h1></div> ▸ Semantic HTML:
 <div class=“product wrapper”>
 <h1 class=“title”>Product Title</h1>
 </div>
  • 25. WHY SO HARD TO DEBUG?
  • 26. CAPYBARA TESTING BY STEVEN YAP TOO MANY THINGS HAPPENING! ▸ Asset pipeline, Javascript functions, CSS rendering, partials, controllers, models, database, EVERYTHING!!! ▸ Failure can come from anywhere (unlike functional/unit tests) ▸ External script loads too slow (timeout) ▸ Performance too bad (AJAX call timeout) ▸ Errors in assets compilation (SASS error) ▸ Javascript driver bugs
  • 27. CAPYBARA TESTING BY STEVEN YAP THINK LIKE A USER ▸ Capybara tests run like a real user using the site ▸ Anything your users cannot do = Your test cannot do ▸ User cannot post to a URL directly so your test code cannot post to a URL directly like a controller test ▸ User cannot click on hidden elements (eg. a hidden link)
  • 28. CAPYBARA TESTING BY STEVEN YAP CAPYBARA DEBUGGING METHODS ▸ Make sure your development site works first! ▸ https://github.com/jnicklas/capybara#debugging ▸ https://github.com/mattheworiordan/capybara-screenshot ▸ Painful examination of rendered HTML
  • 29. CAPYBARA TESTING BY STEVEN YAP OVERLAYED ELEMENTS VS HIDDEN ELEMENTS ▸ Sometimes CSS styling overlay the original element with another layout ▸ Eg. http://materializecss.com/forms.html#checkbox ▸ Forced click:
 page.find(‘#user_terms_and_conditions’, visible: false).trigger('click')
  • 30. CAPYBARA TESTING BY STEVEN YAP AJAX CALLS ▸ Difficult to debug ▸ Is the AJAX fired or fired with errors? ▸ Console.log() will output when running the test ▸ Understand when Capybara will wait or will not wait ▸ https://github.com/jnicklas/capybara#asynchronous- javascript-ajax-and-friends
  • 31. CAPYBARA TESTING BY STEVEN YAP ACTIONVIEW::TEMPLATE::ERROR: END OF FILE REACHED ▸ Random bug that appeared ▸ https://github.com/jfirebaugh/konacha/issues/123 ▸ Reason: sprockets reading uncompiled asset files ▸ Solution: gem 'sprockets-rails', '~> 3.0.0', :require => 'sprockets/railtie'
  • 33. CAPYBARA TESTING BY STEVEN YAP PAYPAL SANDBOX def make_payment_via_paypal() using_wait_time(30) do resolve_paypal_js_error click_on 'Pay with my PayPal account' within '#method-paypal' do fill_in 'Email', with: Rails.application.secrets.paypal_testing_email fill_in 'PayPal password', with: Rails.application.secrets.paypal_testing_password click_on 'Log In' end find('#continue_abovefold').click expect(page).not_to have_content 'Loading...' end end # Paypal has a JS error # where it cannot find div#paywithmybank_container def resolve_paypal_js_error execute_script <<-EOF var ele = document.createElement("DIV"); ele.id = "paywithmybank_container"; document.getElementsByTagName("body")[0].appendChild(ele); EOF end
  • 34. CAPYBARA TESTING BY STEVEN YAP DO CAPYBARA TEST ▸ It is the Ultimate Test ▸ Give assurances to critical functions ▸ Helps you to think about your views ▸ Easier with experience
  • 35. Thank you! Awesome Ruby on Rails Development http://www.futureworkz.com http://playbook.futureworkz.com/