SlideShare ist ein Scribd-Unternehmen logo
1 von 35
Downloaden Sie, um offline zu lesen
StevenYap
stevenyap@futureworkz.com
https://github.com/stevenyap
A Garden City
A Lion City
• 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/

Weitere ähnliche Inhalte

Was ist angesagt?

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

Was ist angesagt? (20)

Test automation with Cucumber-JVM
Test automation with Cucumber-JVMTest automation with Cucumber-JVM
Test automation with Cucumber-JVM
 
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
 
Jest: Frontend Testing richtig gemacht @WebworkerNRW
Jest: Frontend Testing richtig gemacht @WebworkerNRWJest: Frontend Testing richtig gemacht @WebworkerNRW
Jest: Frontend Testing richtig gemacht @WebworkerNRW
 
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
 
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
 
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
 
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)
 
Automate Thyself
Automate ThyselfAutomate Thyself
Automate Thyself
 
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
 
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
 
Integration Testing with Selenium
Integration Testing with SeleniumIntegration Testing with Selenium
Integration Testing with Selenium
 
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
 
Introduction to cypress in Angular (Chinese)
Introduction to cypress in Angular (Chinese)Introduction to cypress in Angular (Chinese)
Introduction to cypress in Angular (Chinese)
 
Conquering AngularJS Limitations
Conquering AngularJS LimitationsConquering AngularJS Limitations
Conquering AngularJS Limitations
 
Continuous Integration Testing in Django
Continuous Integration Testing in DjangoContinuous Integration Testing in Django
Continuous Integration Testing in Django
 
Front-End Testing: Demystified
Front-End Testing: DemystifiedFront-End Testing: Demystified
Front-End Testing: Demystified
 
Automated Testing in Angular Slides
Automated Testing in Angular SlidesAutomated Testing in Angular Slides
Automated Testing in Angular Slides
 
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
 
Protractor Tutorial Quality in Agile 2015
Protractor Tutorial Quality in Agile 2015Protractor Tutorial Quality in Agile 2015
Protractor Tutorial Quality in Agile 2015
 
Writing Software not Code with Cucumber
Writing Software not Code with CucumberWriting Software not Code with Cucumber
Writing Software not Code with Cucumber
 

Andere mochten auch

Andere mochten auch (20)

Testing Microservices with a Citrus twist
Testing Microservices with a Citrus twistTesting Microservices with a Citrus twist
Testing Microservices with a Citrus twist
 
Bdd (Behavior Driven Development)
Bdd (Behavior Driven Development)Bdd (Behavior Driven Development)
Bdd (Behavior Driven Development)
 
Testing Java EE apps with Arquillian
Testing Java EE apps with ArquillianTesting Java EE apps with Arquillian
Testing Java EE apps with Arquillian
 
Workshop calabash appium
Workshop calabash appiumWorkshop calabash appium
Workshop calabash appium
 
Arquillian & Citrus
Arquillian & CitrusArquillian & Citrus
Arquillian & Citrus
 
Pruebas funcionales de Software
Pruebas funcionales de SoftwarePruebas funcionales de Software
Pruebas funcionales de Software
 
Automated Acceptance Tests & Tool choice
Automated Acceptance Tests & Tool choiceAutomated Acceptance Tests & Tool choice
Automated Acceptance Tests & Tool choice
 
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
 
TestLink introduction
TestLink introductionTestLink introduction
TestLink introduction
 
Introduction To Confluence
Introduction To ConfluenceIntroduction To Confluence
Introduction To Confluence
 
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
 
Using JIRA Software for Issue Tracking
Using JIRA Software for Issue TrackingUsing JIRA Software for Issue Tracking
Using JIRA Software for Issue Tracking
 
Introduction To Jira
Introduction To JiraIntroduction To Jira
Introduction To Jira
 
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
 
Next level of Appium
Next level of AppiumNext level of Appium
Next level of Appium
 
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!
 
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
 
Introduction to Bdd and cucumber
Introduction to Bdd and cucumberIntroduction to Bdd and cucumber
Introduction to Bdd and cucumber
 
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)
 
Continuous integration using Jenkins and Sonar
Continuous integration using Jenkins and SonarContinuous integration using Jenkins and Sonar
Continuous integration using Jenkins and Sonar
 

Ähnlich wie Capybara testing

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
 

Ähnlich wie Capybara testing (20)

Capybara with Rspec
Capybara with RspecCapybara with Rspec
Capybara with Rspec
 
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...
 
Continuous Testing With React Storybook & WebdriverIO
Continuous Testing With React Storybook & WebdriverIOContinuous Testing With React Storybook & WebdriverIO
Continuous Testing With React Storybook & WebdriverIO
 
How to write Testable Javascript
How to write Testable JavascriptHow to write Testable Javascript
How to write Testable Javascript
 
Building scala with bazel
Building scala with bazelBuilding scala with bazel
Building scala with bazel
 
Introduction to Continous Integration with WordPress
Introduction to Continous Integration with WordPressIntroduction to Continous Integration with WordPress
Introduction to Continous Integration with WordPress
 
Mocking - Visug session
Mocking - Visug sessionMocking - Visug session
Mocking - Visug session
 
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 ...
 
Autotesting rails app
Autotesting rails appAutotesting rails app
Autotesting rails app
 
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
 
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
 
Introduction to test_driven_development
Introduction to test_driven_developmentIntroduction to test_driven_development
Introduction to test_driven_development
 
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
 
Serenity BDD Workshop - 9th March 2016
Serenity BDD Workshop - 9th March 2016Serenity BDD Workshop - 9th March 2016
Serenity BDD Workshop - 9th March 2016
 
BDD / cucumber /Capybara
BDD / cucumber /CapybaraBDD / cucumber /Capybara
BDD / cucumber /Capybara
 
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
 
Wicket Deliver Your Webapp On Time
Wicket Deliver Your Webapp On TimeWicket Deliver Your Webapp On Time
Wicket Deliver Your Webapp On Time
 
Why Use Rails by Dr Nic
Why Use Rails by  Dr NicWhy Use Rails by  Dr Nic
Why Use Rails by Dr Nic
 
Ugo Cei Presentation
Ugo Cei PresentationUgo Cei Presentation
Ugo Cei Presentation
 
Thomas Fuchs Presentation
Thomas Fuchs PresentationThomas Fuchs Presentation
Thomas Fuchs Presentation
 

Kürzlich hochgeladen

%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
masabamasaba
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
masabamasaba
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 

Kürzlich hochgeladen (20)

MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 

Capybara testing

  • 2.
  • 5.
  • 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/