SlideShare a Scribd company logo
1 of 19
Download to read offline
async makes your
tests fun
Michael Reinsch

michael@movingfast.io

github / twitter: mreinsch
capybara acceptance
testing
scenario "publish event" do
visit event_url(event)
click_on "Publish Event"
expect(event.reload).to be_published
end
scenario "publish event", js: true do
visit event_url(event)
click_on "Publish Event"
expect(event.reload).to be_published
end
scenario "publish event", js: true do
visit event_url(event)
click_on "Publish Event"
expect(event.reload).to be_published
end
scenario "publish event", js: true do
visit event_url(event)
click_on "Publish Event"
expect(event.reload).to be_published
end
Failure/Error: expect(event.reload).to be_published
rspec
process
rspec
process
rails server
process
spawns
rspec
process
rails server
process
spawns
browser
process
spawns /
sends
commands
rspec
process
rails server
process
spawns
browser
process
spawns /
sends
commands
http requests
scenario "publish event", js: true do
visit event_url(event)
click_on "Publish Event"
expect(page).to have_content("Registration: Open")
expect(event.reload).to be_published
end
scenario "publish event", js: true do
visit event_url(event)
click_on "Publish Event"
expect(page).to have_content("Registration: Open")
expect(event.reload).to be_published
end
scenario "publish event", js: true do
visit event_url(event)
click_on "Publish Event"
expect(page).to have_content("Registration: Open")
expect(event.reload).to be_published
end
Failure/Error: Unable to find matching line from backtrace
ActiveRecord::StatementInvalid:
PG::TRDeadlockDetected: ERROR: deadlock detected
DETAIL: Process 7186 waits for AccessShareLock on relation 16570 of
database 16396; blocked by process 7274.
Process 7274 waits for AccessExclusiveLock on relation 17012 of database
16396; blocked by process 7186.
ajax
vs.
database_cleaner
# in spec/spec_helper.rb
config.append_after(:each) do
Rails.logger.debug("======= cleaning DB")
DatabaseCleaner.clean
end
module RSpecLoggerListener
extend self
def start(notification)
Rails.logger.info("nn====== Starting new test run")
end
def stop(notification)
Rails.logger.info("nn====== Test run finished")
end
def example_started(notification)
Rails.logger.info("nn====== START #{notification.example.full_description}")
end
def example_passed(notification)
Rails.logger.info("====== PASSED #{notification.example.full_description}")
end
def example_failed(notification)
Rails.logger.info("====== FAILED #{notification.example.full_description}")
end
def example_pending(notification)
Rails.logger.info("====== PENDING #{notification.example.full_description}")
end
end
RSpec.configuration.reporter.register_listener(
RSpecLoggerListener,
:start, :stop, :example_started, :example_passed,
:example_failed, :example_pending)
get it from: https://gist.github.com/mreinsch/2c8dbb01e51c32c3c5c8
module CapybaraHelperMethods
def wait_for_ajax
counter = 0
while !finished_all_ajax_requests?
counter += 1
sleep 0.2
raise "AJAX request took too long." if counter >= (Capybara.default_wait_time * 5)
end
end
def finished_all_ajax_requests?
active = page.evaluate_script <<-SCRIPT.strip.gsub(/s+/,' ')
(function () {
if (typeof jQuery != 'undefined') {
return jQuery.active;
}
else {
console.error("jQuery was undefined on " + document.URL + " - will retry...");
return -1;
}
})()
SCRIPT
active && active.zero?
end
end
RSpec.configuration.include CapybaraHelperMethods, :type => :feature
based on https://coderwall.com/p/aklybw/wait-for-ajax-with-capybara-2-0
scenario "publish event", js: true do
visit event_url(event)
click_on "Publish Event"
expect(page).to have_content("Registration: Open")
expect(event.reload).to be_published
wait_for_ajax
end
Beware of the async!
Michael Reinsch

michael@movingfast.io

github / twitter: mreinsch

More Related Content

What's hot

Service Worker Presentation
Service Worker PresentationService Worker Presentation
Service Worker Presentation
Kyle Dorman
 
Activation limit&flowlimit&maxjobs
Activation limit&flowlimit&maxjobsActivation limit&flowlimit&maxjobs
Activation limit&flowlimit&maxjobs
Nirmala Devi
 

What's hot (20)

Deploying a Chef Server
Deploying a Chef ServerDeploying a Chef Server
Deploying a Chef Server
 
Service workers
Service workersService workers
Service workers
 
Asynchronous and event-driven Grails applications
Asynchronous and event-driven Grails applicationsAsynchronous and event-driven Grails applications
Asynchronous and event-driven Grails applications
 
Zero Downtime Deployment in Microservices era
Zero Downtime Deployment in Microservices eraZero Downtime Deployment in Microservices era
Zero Downtime Deployment in Microservices era
 
1. Quick sartup a jenkins server on OpenShift
1. Quick sartup a jenkins server on OpenShift1. Quick sartup a jenkins server on OpenShift
1. Quick sartup a jenkins server on OpenShift
 
Test Failed, Then...
Test Failed, Then...Test Failed, Then...
Test Failed, Then...
 
Service Worker Presentation
Service Worker PresentationService Worker Presentation
Service Worker Presentation
 
Activation limit&flowlimit&maxjobs
Activation limit&flowlimit&maxjobsActivation limit&flowlimit&maxjobs
Activation limit&flowlimit&maxjobs
 
Cookbook Reusability @ Chef Community summit 2014
Cookbook Reusability @ Chef Community summit 2014Cookbook Reusability @ Chef Community summit 2014
Cookbook Reusability @ Chef Community summit 2014
 
Stop js-1999
Stop js-1999Stop js-1999
Stop js-1999
 
Service workers
Service workersService workers
Service workers
 
[1C1]Service Workers
[1C1]Service Workers[1C1]Service Workers
[1C1]Service Workers
 
ChefConf 2016 - Writing Compossible Community Cookbooks using Chef Custom Res...
ChefConf 2016 - Writing Compossible Community Cookbooks using Chef Custom Res...ChefConf 2016 - Writing Compossible Community Cookbooks using Chef Custom Res...
ChefConf 2016 - Writing Compossible Community Cookbooks using Chef Custom Res...
 
Service worker API
Service worker APIService worker API
Service worker API
 
Service worker: discover the next web game changer
Service worker: discover the next web game changerService worker: discover the next web game changer
Service worker: discover the next web game changer
 
Secure your Web Application With The New Python Audit Hooks
Secure your Web Application With The New Python Audit HooksSecure your Web Application With The New Python Audit Hooks
Secure your Web Application With The New Python Audit Hooks
 
PWA 應用 - 實現網站離線瀏覽
PWA 應用 - 實現網站離線瀏覽PWA 應用 - 實現網站離線瀏覽
PWA 應用 - 實現網站離線瀏覽
 
Lessons from Etsy: Avoiding Kitchen Nightmares - #ChefConf 2012
Lessons from Etsy: Avoiding Kitchen Nightmares - #ChefConf 2012Lessons from Etsy: Avoiding Kitchen Nightmares - #ChefConf 2012
Lessons from Etsy: Avoiding Kitchen Nightmares - #ChefConf 2012
 
Refactoring a web application with Python
Refactoring a web application with PythonRefactoring a web application with Python
Refactoring a web application with Python
 
Ultimate Node.js countdown: the coolest Application Express examples
Ultimate Node.js countdown: the coolest Application Express examplesUltimate Node.js countdown: the coolest Application Express examples
Ultimate Node.js countdown: the coolest Application Express examples
 

Viewers also liked

Jordan Michael Shaver's Resumé
Jordan Michael Shaver's Resumé Jordan Michael Shaver's Resumé
Jordan Michael Shaver's Resumé
Jordan Shaver
 
GNCTR 2012 Sponsors
GNCTR 2012 SponsorsGNCTR 2012 Sponsors
GNCTR 2012 Sponsors
osnorton
 

Viewers also liked (18)

Ireland and Society, Lecture Three: Culture of Everyday Life
Ireland and Society, Lecture Three: Culture of Everyday LifeIreland and Society, Lecture Three: Culture of Everyday Life
Ireland and Society, Lecture Three: Culture of Everyday Life
 
Presentación12
Presentación12Presentación12
Presentación12
 
Ireland and Society, Lecture One: Religion
Ireland and Society, Lecture One:  ReligionIreland and Society, Lecture One:  Religion
Ireland and Society, Lecture One: Religion
 
Presentación1
Presentación1Presentación1
Presentación1
 
ColdEezeAdCampaign
ColdEezeAdCampaignColdEezeAdCampaign
ColdEezeAdCampaign
 
Mary Rose Buyoc Mangahas CV
Mary Rose Buyoc Mangahas CVMary Rose Buyoc Mangahas CV
Mary Rose Buyoc Mangahas CV
 
Jordan Michael Shaver's Resumé
Jordan Michael Shaver's Resumé Jordan Michael Shaver's Resumé
Jordan Michael Shaver's Resumé
 
11.05.2016 r. wyniki Lokum Deweloper I kw. 2016 r.
11.05.2016 r. wyniki Lokum Deweloper I kw. 2016 r.11.05.2016 r. wyniki Lokum Deweloper I kw. 2016 r.
11.05.2016 r. wyniki Lokum Deweloper I kw. 2016 r.
 
Sally.Hosseini-R.2015
Sally.Hosseini-R.2015Sally.Hosseini-R.2015
Sally.Hosseini-R.2015
 
Finding the right stuff, an intro to Elasticsearch with Ruby/Rails
Finding the right stuff, an intro to Elasticsearch with Ruby/RailsFinding the right stuff, an intro to Elasticsearch with Ruby/Rails
Finding the right stuff, an intro to Elasticsearch with Ruby/Rails
 
GNCTR 2012 Sponsors
GNCTR 2012 SponsorsGNCTR 2012 Sponsors
GNCTR 2012 Sponsors
 
Randeep
RandeepRandeep
Randeep
 
Positive Thinking
Positive ThinkingPositive Thinking
Positive Thinking
 
Emerging Trends in Social Media 2013
Emerging Trends in Social Media 2013Emerging Trends in Social Media 2013
Emerging Trends in Social Media 2013
 
Perio esthetics
Perio estheticsPerio esthetics
Perio esthetics
 
Questionnaire on luxury brand shopping
Questionnaire on luxury brand shoppingQuestionnaire on luxury brand shopping
Questionnaire on luxury brand shopping
 
Twitter sentiment analysis
Twitter sentiment analysisTwitter sentiment analysis
Twitter sentiment analysis
 
Periodontal management of medically compromised paients/dental courses
Periodontal management of medically compromised paients/dental coursesPeriodontal management of medically compromised paients/dental courses
Periodontal management of medically compromised paients/dental courses
 

Similar to async makes your tests fun - acceptance testing with capybara

Websockets talk at Rubyconf Uruguay 2010
Websockets talk at Rubyconf Uruguay 2010Websockets talk at Rubyconf Uruguay 2010
Websockets talk at Rubyconf Uruguay 2010
Ismael Celis
 
Async. and Realtime Geo Applications with Node.js
Async. and Realtime Geo Applications with Node.jsAsync. and Realtime Geo Applications with Node.js
Async. and Realtime Geo Applications with Node.js
Shoaib Burq
 
Trying Continuous Delivery - pyconjp 2012
Trying Continuous Delivery - pyconjp 2012Trying Continuous Delivery - pyconjp 2012
Trying Continuous Delivery - pyconjp 2012
Toru Furukawa
 
Remote code-with-expression-language-injection
Remote code-with-expression-language-injectionRemote code-with-expression-language-injection
Remote code-with-expression-language-injection
Mickey Jack
 
【第一季第二期】Dive into javascript event
【第一季第二期】Dive into javascript event【第一季第二期】Dive into javascript event
【第一季第二期】Dive into javascript event
tbosstraining
 
Be Mean to Your Code - OWASP San Antonio
Be Mean to Your Code - OWASP San Antonio Be Mean to Your Code - OWASP San Antonio
Be Mean to Your Code - OWASP San Antonio
James Wickett
 

Similar to async makes your tests fun - acceptance testing with capybara (20)

Websockets talk at Rubyconf Uruguay 2010
Websockets talk at Rubyconf Uruguay 2010Websockets talk at Rubyconf Uruguay 2010
Websockets talk at Rubyconf Uruguay 2010
 
Async. and Realtime Geo Applications with Node.js
Async. and Realtime Geo Applications with Node.jsAsync. and Realtime Geo Applications with Node.js
Async. and Realtime Geo Applications with Node.js
 
Trying Continuous Delivery - pyconjp 2012
Trying Continuous Delivery - pyconjp 2012Trying Continuous Delivery - pyconjp 2012
Trying Continuous Delivery - pyconjp 2012
 
Remote code-with-expression-language-injection
Remote code-with-expression-language-injectionRemote code-with-expression-language-injection
Remote code-with-expression-language-injection
 
Be Mean to your Code with Gauntlt #txlf 2013
Be Mean to your Code with Gauntlt #txlf 2013Be Mean to your Code with Gauntlt #txlf 2013
Be Mean to your Code with Gauntlt #txlf 2013
 
【第一季第二期】Dive into javascript event
【第一季第二期】Dive into javascript event【第一季第二期】Dive into javascript event
【第一季第二期】Dive into javascript event
 
InterConnect: Server Side Swift for Java Developers
InterConnect:  Server Side Swift for Java DevelopersInterConnect:  Server Side Swift for Java Developers
InterConnect: Server Side Swift for Java Developers
 
Async Redux Actions With RxJS - React Rally 2016
Async Redux Actions With RxJS - React Rally 2016Async Redux Actions With RxJS - React Rally 2016
Async Redux Actions With RxJS - React Rally 2016
 
Be Mean to Your Code - OWASP San Antonio
Be Mean to Your Code - OWASP San Antonio Be Mean to Your Code - OWASP San Antonio
Be Mean to Your Code - OWASP San Antonio
 
Brining Harmony between Dev and Ops and Security Teams using Gauntlt at ISC2 ...
Brining Harmony between Dev and Ops and Security Teams using Gauntlt at ISC2 ...Brining Harmony between Dev and Ops and Security Teams using Gauntlt at ISC2 ...
Brining Harmony between Dev and Ops and Security Teams using Gauntlt at ISC2 ...
 
Dive into javascript event
Dive into javascript eventDive into javascript event
Dive into javascript event
 
RxSwift to Combine
RxSwift to CombineRxSwift to Combine
RxSwift to Combine
 
Atmosphere 2014
Atmosphere 2014Atmosphere 2014
Atmosphere 2014
 
Gauntlt Rugged By Example
Gauntlt Rugged By ExampleGauntlt Rugged By Example
Gauntlt Rugged By Example
 
Rugged by example with Gauntlt (Hacker Headshot)
Rugged by example with Gauntlt (Hacker Headshot)Rugged by example with Gauntlt (Hacker Headshot)
Rugged by example with Gauntlt (Hacker Headshot)
 
Node.js
Node.jsNode.js
Node.js
 
Javascript in Plone
Javascript in PloneJavascript in Plone
Javascript in Plone
 
Event Driven Javascript
Event Driven JavascriptEvent Driven Javascript
Event Driven Javascript
 
Websocket on Rails
Websocket on RailsWebsocket on Rails
Websocket on Rails
 
Burn down the silos! Helping dev and ops gel on high availability websites
Burn down the silos! Helping dev and ops gel on high availability websitesBurn down the silos! Helping dev and ops gel on high availability websites
Burn down the silos! Helping dev and ops gel on high availability websites
 

Recently uploaded

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Recently uploaded (20)

presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 

async makes your tests fun - acceptance testing with capybara

  • 1. async makes your tests fun Michael Reinsch
 michael@movingfast.io
 github / twitter: mreinsch
  • 3. scenario "publish event" do visit event_url(event) click_on "Publish Event" expect(event.reload).to be_published end
  • 4. scenario "publish event", js: true do visit event_url(event) click_on "Publish Event" expect(event.reload).to be_published end
  • 5. scenario "publish event", js: true do visit event_url(event) click_on "Publish Event" expect(event.reload).to be_published end
  • 6. scenario "publish event", js: true do visit event_url(event) click_on "Publish Event" expect(event.reload).to be_published end Failure/Error: expect(event.reload).to be_published
  • 11. scenario "publish event", js: true do visit event_url(event) click_on "Publish Event" expect(page).to have_content("Registration: Open") expect(event.reload).to be_published end
  • 12. scenario "publish event", js: true do visit event_url(event) click_on "Publish Event" expect(page).to have_content("Registration: Open") expect(event.reload).to be_published end
  • 13. scenario "publish event", js: true do visit event_url(event) click_on "Publish Event" expect(page).to have_content("Registration: Open") expect(event.reload).to be_published end Failure/Error: Unable to find matching line from backtrace ActiveRecord::StatementInvalid: PG::TRDeadlockDetected: ERROR: deadlock detected DETAIL: Process 7186 waits for AccessShareLock on relation 16570 of database 16396; blocked by process 7274. Process 7274 waits for AccessExclusiveLock on relation 17012 of database 16396; blocked by process 7186.
  • 15. # in spec/spec_helper.rb config.append_after(:each) do Rails.logger.debug("======= cleaning DB") DatabaseCleaner.clean end
  • 16. module RSpecLoggerListener extend self def start(notification) Rails.logger.info("nn====== Starting new test run") end def stop(notification) Rails.logger.info("nn====== Test run finished") end def example_started(notification) Rails.logger.info("nn====== START #{notification.example.full_description}") end def example_passed(notification) Rails.logger.info("====== PASSED #{notification.example.full_description}") end def example_failed(notification) Rails.logger.info("====== FAILED #{notification.example.full_description}") end def example_pending(notification) Rails.logger.info("====== PENDING #{notification.example.full_description}") end end RSpec.configuration.reporter.register_listener( RSpecLoggerListener, :start, :stop, :example_started, :example_passed, :example_failed, :example_pending) get it from: https://gist.github.com/mreinsch/2c8dbb01e51c32c3c5c8
  • 17. module CapybaraHelperMethods def wait_for_ajax counter = 0 while !finished_all_ajax_requests? counter += 1 sleep 0.2 raise "AJAX request took too long." if counter >= (Capybara.default_wait_time * 5) end end def finished_all_ajax_requests? active = page.evaluate_script <<-SCRIPT.strip.gsub(/s+/,' ') (function () { if (typeof jQuery != 'undefined') { return jQuery.active; } else { console.error("jQuery was undefined on " + document.URL + " - will retry..."); return -1; } })() SCRIPT active && active.zero? end end RSpec.configuration.include CapybaraHelperMethods, :type => :feature based on https://coderwall.com/p/aklybw/wait-for-ajax-with-capybara-2-0
  • 18. scenario "publish event", js: true do visit event_url(event) click_on "Publish Event" expect(page).to have_content("Registration: Open") expect(event.reload).to be_published wait_for_ajax end
  • 19. Beware of the async! Michael Reinsch
 michael@movingfast.io
 github / twitter: mreinsch