2014-12-04

Screenshots with Mocha-PhantomJS

Today I wondered whether you can take screenshots in your mocha-phantomjs tests. Within 15 minutes I found out that my colleagues at Reaktor had already solved the problem in their own fork. So I took a look and with some help got screenshots working in the open-source application I'm working on for the Board of Education in Finland. Then I made a pull request and now I'm telling you how to make screenshots work.
So, in your test code, write a helper for generating a screenshot on demand:
function takeScreenshot() {
  if (window.callPhantom) {
    var date = new Date()
    var filename = "target/screenshots/" + date.getTime()
    console.log("Taking screenshot " + filename)
    callPhantom({'screenshot': filename})
  }
}
In this function you decide where to put the screenshots and how to name them. In my case, I'm putting them undertarget/screenshots.
If you want to generate a screenshot for each test failure you just add the following into your test code.
  afterEach(function () {
    if (this.currentTest.state == 'failed') {
      takeScreenshot()
    }
  })
And next time you run your mocha-phantomjs tests, KABOOM, you have screenshots. Good times!
Update: A couple of days later, version 3.5.2 with screenshot support was released!

101 comments:

  1. Replies
    1. IEEE Final Year Project centers make amazing deep learning final year projects ideas for final year students Final Year Projects for CSE to training and develop their deep learning experience and talents.

      IEEE Final Year projects Project Centers in India are consistently sought after. Final Year Students Projects take a shot at them to improve their aptitudes, while specialists like the enjoyment in interfering with innovation.

      corporate training in chennai corporate training in chennai

      corporate training companies in india corporate training companies in india

      corporate training companies in chennai corporate training companies in chennai

      I have read your blog its very attractive and impressive. I like it your blog. Digital Marketing Company in Chennai

      Delete
  2. Thank you for allowing me to read it, welcome to the next in a recent article. And thanks for sharing the nice article, keep posting or updating news article.
    Block Chain Training in Bangalore

    Block Chain Training in tambaram

    Block Chain Training in chennai

    Block Chain Training in annanagar

    Block Chain Training in pune

    Block Chain Training in velachery

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. Great post. Needed to write simple word that Thanks for suggestions. Keep it up! best sap simple finance online training institute in hyderabad

    ReplyDelete
  5. Wow it is really wonderful and awesome thus it is very much useful for me to understand many concepts and helped me a lot. it is really explainable very well and i got more information from your blog.

    rpa training in chennai | rpa training in chennai
    rpa training in pune | rpa online training | rpa training in bangalore

    ReplyDelete
  6. Really you have done great job,There are may person searching about that now they will find enough resources by your post

    java training in jayanagar | java training in electronic city

    java training in chennai | java training in USA

    ReplyDelete
  7. It is amazing and wonderful to visit your site.Thanks for sharing this information,this is useful to me...
    python training in tambaram | python training in annanagar | python training in jayanagar

    ReplyDelete
  8. Great thoughts you got there, believe I may possibly try just some of it throughout my daily life.
    Online DevOps Certification Course - Gangboard
    Best Devops Training institute in Chennai

    ReplyDelete
  9. A very nice guide. I will definitely follow these tips. Thank you for sharing such detailed article. I am learning a lot from you.

    rpa training in electronic-city | rpa training in btm | rpa training in marathahalli | rpa training in pune

    ReplyDelete
  10. Nice blog..! I really loved reading through this article. Thanks for sharing such an amazing post with us and keep blogging...Well written article Thank You for Sharing with Us pmp training institute in chennai | pmp training in chennai | pmp training class in chennai | pmp training near me | pmp training courses online | pmp training fee

    ReplyDelete
  11. Mình đã tìm thấy các thông tin cần thiết ở đây, cảm ơn bạn. Mình cũng muốn giới thiệu về một Công ty dịch thuật uy tín - Công ty cổ phần dịch thuật miền trung - MIDtrans có văn phòng chính tại địa chỉ 02 Hoàng Diệu, TP Đồng Hới, tỉnh Quảng Bình có Giấy phép kinh doanh số 3101023866 cấp ngày 9/12/2016 là đơn vị chuyên cung cấp dịch vụ dịch thuật, phiên dịch dành các cá nhân. Hệ thống thương hiệu và các Công ty dịch thuật con trực thuộc: công ty dịch thuật hcm - dịch thuật sài gòn 247 , địa chỉ 47 Điện Biên Phủ, Phường Đakao, Quận 1 TP HCM, dịch thuật buôn mê thuột, đăk lăk : địa chỉ 100 , Lê lợi, TP Buôn Mê Thuột là nhà cung ứng dịch vụ dịch thuật uy tín hàng đầu tại Đăk Lăk; viet translate : dịch vụ dịch thuật cho người nước ngoài có nhu cầu, giao diện tiếng Anh dễ sử dụng; dịch thuật công chứng bình thạnh : nhà cung ứng dịch vụ dịch vụ dịch thuật phiên dịch hàng đầu tại Quận Bình Thạnh, TP HCM; dịch thuật đà nẵng midtrans : Địa chỉ 54 Đinh Tiên Hoàng, Quận Hải Châu, TP Đà Nẵng chuyên cung cấp dịch vụ dịch thuật công chứng, dịch thuật chuyên ngành tại Đà Nẵng; dịch thuật hà nội midtrans : địa chỉ 101 Láng Hạ, Đống Đa, Hà Nội là nhà cung ứng dịch vụ biên dịch, phiên dịch chuyên nghiệp tại địa bàn Hà Nội. Chúng tôi chuyên cung cấp các dịch vụ biên dịch và phiên dịch, dịch thuật công chứng chất lượng cao hơn 50 ngôn ngữ khác nhau như tiếng Anh, Nhật, Hàn, Trung, Pháp, Đức, Nga, Tây Ban Nha, Bồ Đào Nha, Ý, Ba Lan, Phần Lan, Thái Lan, Hà Lan, Rumani, Lào, Campuchia, Philippin, Indonesia, La Tinh, Thụy Điển, Malaysia, Thổ Nhĩ Kỳ..vv... Dịch thuật MIDtrans tự hào với đội ngũ lãnh đạo với niềm đam mê, khát khao vươn tầm cao trong lĩnh vực dịch thuật, đội ngũ nhân sự cống hiến và luôn sẵn sàng cháy hết mình. Chúng tôi phục vụ từ sự tậm tâm và cố gắng từ trái tim những người dịch giả.Tự hào là công ty cung cấp dịch thuật chuyên ngành hàng đầu với các đối tác lớn tại Việt nam trong các chuyên ngành hẹp như: y dược (bao gồm bệnh lý), xây dựng (kiến trúc), hóa chất, thủy nhiệt điện, ngân hàng, tài chính, kế toán. Các dự án đã triển khai của Công ty dịch thuật chuyên nghiệp MIDtrans đều được Khách hàng đánh giá cao và đạt được sự tín nhiệm về chất lượng biên phiên dịch đặc biệt đối với dịch hồ sơ thầu , dịch thuật tài liệu tài chính ngân hàng, dịch thuật tài liệu y khoa đa ngữ chuyên sâu. Đó là kết quả của một hệ thống quản lý chất lượng dịch thuật chuyên nghiệp, những tâm huyết và kinh nghiệm biên phiên dịch nhiều năm của đội ngũ dịch giả của chúng tôi. Hotline: 0947688883. email: info@dichthuatmientrung.com.vn . Các bạn ghé thăm site ủng hộ nhé. Cám ơn nhiều

    ReplyDelete
  12. Thanks for the post! There is useful information https://writeanessayfor.me/

    ReplyDelete
  13. Good blog explanation
    Sanjary Kids is one of the best play school and preschool in Hyderabad,India. Give your child the best preschool experience by choosing the best playschool of Hyderabad in Abids. we provide programs like Play group,Nursery,Junior KG,Senior KG,and provides Teacher Training Program.
    Preschool teacher training course in hyderabad

    ReplyDelete
  14. Wow it is really wonderful and awesome thus it is very much useful for me to understand many concepts and helped me a lot. it is really explainable very well and i got more information from your blog.
    Selenium online training

    ReplyDelete
  15. Good blog information of the topic

    Sanjary Academy is the best Piping Design institute in Hyderabad, Telangana. It is the best Piping design Course in India and we have offer professional Engineering Courses like Piping design Course, QA/QC Course, document controller course, Pressure Vessel Design Course, Welding Inspector Course, Quality Management Course and Safety Officer Course.
    Piping Design Course
    Piping Design Course in Hyderabad ­
    Piping Design Course in India­

    ReplyDelete
  16. Great informative and understandable blog

    Pressure Vessel Design Course is one of the courses offered by Sanjary Academy in Hyderabad. We have offer professional Engineering Course like Piping Design Course,QA/QC Course,document Controller course,pressure Vessel Design Course,Welding Inspector Course, Quality Management Course, Safety officer course.
    Welding Inspector Course
    Safety officer course
    Quality Management Course
    Quality Management Course in India

    ReplyDelete
  17. Nice post. Thanks for sharing the valuable information. it’s really helpful. Who want to learn this blog most helpful. Keep sharing on updated posts…
    Selenium online training
    Selenium certification training
    Selenium online course
    Selenium training course

    ReplyDelete
  18. Hi,
    Good job & thank you very much for the new information, i learned something new. Very well written. It was sooo good to read and usefull to improve knowledge. Who want to learn this information most helpful. One who wanted to learn this technology IT employees will always suggest you take python training in bangalore. Because python course in Bangalore is one of the best that one can do while choosing the course.

    ReplyDelete
  19. Nice Information
    Yaaron Studios is one of the rapidly growing editing studios in Hyderabad. We are the best Video Editing services in Hyderabad. We provides best graphic works like logo reveals, corporate presentation Etc. And also we gives the best Outdoor/Indoor shoots and Ad Making services.
    Best video editing services in Hyderabad,ameerpet
    Best Graphic Designing services in Hyderabad,ameerpet­
    Best Ad Making services in Hyderabad,ameerpet­

    ReplyDelete
  20. Thanks for sharing
    "Sanjary Academy provides excellent training for Piping design course. Best Piping Design Training Institute in Hyderabad,
    Telangana. We have offer professional Engineering Course like Piping Design Course,QA / QC Course,document Controller
    course,pressure Vessel Design Course, Welding Inspector Course, Quality Management Course, #Safety officer course."
    Piping Design Course in India­
    Piping Design Course in Hyderabad
    Piping Design Course in Hyderabad
    QA / QC Course
    QA / QC Course in india
    QA / QC Course in Hyderabad

    ReplyDelete
  21. For Blockchain training in Bangalore, Visit:
    Blockchain training in Bangalore

    ReplyDelete
  22. Visit for Blockchain training in Bangalore:- Blockchain training in Bangalore

    ReplyDelete
  23. thanks for sharing such a wonderful information from this post
    digital marketing

    ReplyDelete
  24. I just loved your article on the beginners guide to starting a blog.If somebody take this blog article seriously in their life, he/she can earn his living by doing blogging.thank you for thizs article. best blockchain online training

    ReplyDelete
  25. This comment has been removed by the author.

    ReplyDelete
  26. This comment has been removed by the author.

    ReplyDelete
  27. I think you did an awesome job explaining it. Sure beats having to research it on my own. Thanks
    Devi Ahilya Vishwa Vidhyalaya BCOM 1st, 2nd & Final Year TimeTable 2020

    ReplyDelete
  28. Thanks for Sharing This Article.It is very so much valuable content. I hope these Commenting lists will help to my website
    blockchain online training
    best blockchain online training
    top blockchain online training

    ReplyDelete
  29. Thanks for Sharing This Article.It is very so much valuable content. I hope these Commenting lists will help to my website
    blockchain online training

    ReplyDelete
  30. Feeling so good to read your information's in the blog.
    thanks for sharing your ideas with us and add more info.
    Top 10 Makeup Artists in Kolkata

    ReplyDelete
  31. Thanks for Sharing This Article.It is very so much valuable content. fue turkey

    ReplyDelete
  32. This site helps to clear your all query.
    This is really worth reading. nice informative article.bsc 1st year result
    mg university bcom result

    ReplyDelete
  33. I found your blog on Google and read a few of your other posts too, it is very informative and also influencing me to read more of yours. You have done an exceptional job by adding your hardwork and dedication to it. I am a big fan of art and craft. I just added you to my bookmarks and recommending your blog to my social profiles too. Just like the other budding bloggers i have started my blog, You can support me by visiting my site for more paper airplane related information and knowledge, Keep up the great work Look forward to reading more from you in the future. Thanks in anticipation.
    how to make a paper airplane that flies far and straight | classic dart paper airplane | how to make a good paper | nakamura lock paper airplane instructions | best paper airplane design for distance and accuracy | best paper airplane design for distance and speed | Boomerang paper airplane instructions | Zazoom internet | Eagle paper airplane | how to make a paper airplane that flies far and straight step by step | 4 aerodynamic forces | Paper airplane templates for distance | the eagle paper airplane | best paper plane in the world | How to make a successful paper airplane

    ReplyDelete
  34. https://www.offernutra.com/vietnam/glucoactive/

    https://www.offernutra.com/usa/keto-3ds-reviews/

    https://www.offernutra.com/usa/viromax-ultra/

    https://www.offernutra.com/usa/green-galaxy-cbd-oil/

    https://www.offernutra.com/usa/bodycor-keto/

    ReplyDelete
  35. This was answered by Keto Advanced Fat Burner while I came through that storm marvelous. Fortunately, we'll assume you're ready to give up on the notion of Keto Advanced Fat Burner. It is a record amount. This gives Keto Advanced Fat Burner less of a chance to have more Keto Advanced Fat Burner. That's the moment to go for it. Don't believe us? That is elementary to do.




    Keto Advanced Fat Burner

    ReplyDelete
  36. Thank you for posting this Article! lessburn focuses on providing top-notch Business Information, Business Support andDigital Marketing Services to all companies ranging from budding startups to large multinational organizations across the globe.

    ReplyDelete