So sánh nhỏ giữa Behat vs Casper trong Drupal 7 năm 2015

So sánh nhỏ giữa Behat vs Casper trong Drupal 7 năm 2015

In my previous blog post Behat - The Right Way I made a statement that I think Behat was a better choice for writing tests even for the frontend. Some good arguments were raised in favor of CasperJS.

@amitaibu @juampy72 it boils down to this: I'm a frontend dev. Writing PHP is something I avoid whenever possible.

— Chris Ruppel (@rupl) November 19, 2014

I believe my comparison was wrong in the sense it was lacking the key point to Behat's stength for us. It's not really about "Behat vs. Casper". The proper comparison should have been "Behat vs. Casper - With a Drupal backend"

Behat vs. Casper

And here's the key difference: With Behat you can interact with Drupal's API even when testing using PhantomJS. That is a lot of testing power!

CasperJS knows your site from the browser side. It has no knowledge of the internals of your Drupal site. If you would like to access a node with the title "My article", you would probably hardcode the URL in your test:

var casper = require('casper').create();

casper.start('http://example.com/content/my-article', function() {
  this.echo(this.getTitle());
});

In Behat on the other hand you could write:

When I visit content "New article"

This would be translated to some code that will query Drupal to find the node by its title, and then redirect there.

PhantomJS

This is obviously just a simple example. Changing variables, clearing cache,cleaning up before or after each scenario are easily done using Drupal's API via Behat, while still providing you the full capabilities of PhantomJS. Features like such as taking a screenshot of the page after a failed step - to see exactly what PhantomJS "sees".

Even though Behat is written in PHP we can mimic the functions CasperJS provides, such as waiting for an element to appear.

Boilerplate code

I think by now you know that part of The Gizra Way practices is providing a working example that you can try yourself, right?

Here's an example repository you can clone into any existing Drupal installation. Follow the README to setup the system - it shouldn't take too long and it's worth the effort.

The single test in the repo is looking for a node with the title "New article". Assuming your site doesn't have such a node, executing the test with./bin/behat will result with a failing test.

Go ahead and add a new content called "New article".

Congrats, your PhantomsJS test now works.

Now add step that will fail, e.g.

Then I wait for text "behat" to "appear"

The test will fail, and Behat will create a screenshot that you can look at, and understand why it failed. Nice, huh?

Bạn thấy bài viết này như thế nào?: 
Average: 5 (1 vote)
Ảnh của Tommy Tran

Tommy owner Express Magazine

Drupal Developer having 9+ year experience, implementation and having strong knowledge of technical specifications, workflow development. Ability to perform effectively and efficiently in team and individually. Always enthusiastic and interseted to study new technologies

  • Skype ID: tthanhthuy

Bình luận (0)

 

Add Comment

Filtered HTML

  • Các địa chỉ web và email sẽ tự động được chuyển sang dạng liên kết.
  • Các thẻ HTML được chấp nhận: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Tự động ngắt dòng và đoạn văn.

Plain text

  • No HTML tags allowed.
  • Các địa chỉ web và email sẽ tự động được chuyển sang dạng liên kết.
  • Tự động ngắt dòng và đoạn văn.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.

Tìm kiếm bất động sản

 

Advertisement

 

jobsora

Dich vu khu trung tphcm

Dich vu diet chuot tphcm

Dich vu diet con trung

Quảng Cáo Bài Viết

 
Một số ý kiến làm đẹp photoblog on Drupal

Một số ý kiến làm đẹp photoblog on Drupal

The information below is somewhat obsolete and kept just for archiving purposes. It's recommended to check new blog post to get better idea how to make a nice photoblog on Drupal today.

Docker làm virtualization cho Project Development và Testing trong Drupal

Docker làm virtualization cho Project Development và Testing trong Drupal

Docker has quickly become the favorite virtualization tool for many people including myself.

Ý tưởng Lumia Smartwatch từ đồng hồ truyền thống

Ý tưởng Lumia Smartwatch từ đồng hồ truyền thống

Trang Blog của Nokia vừa đăng tải đoạn video giới thiệu mẫu concept mới của chiếc Nokia Smartwatch do nhà thiết kế Omar Pirela thực hiện lấy cảm hứng từ những chiếc đồng hồ truyền thống.

Công ty diệt chuột T&C

 

Diet con trung