CasperJS - Functional Testing For Your Magento Store

casperjs magento functional testing

It is very important to be careful when you change something on your website. Make certain that everything is correct and cannot break any functionality. And only after countercheck, release it on the live store. The key steps are customer registration process, customer log in to the account, adding different products to the shopping cart, checkout process and so on. It is necessary to check all mentioned steps for each change made for the website.

The process of testing website functionality is time-consuming. However, now you have the opportunity to accelerate and enhance this process by automating all actions. The functional testing is an imitation of the real user’s behaviour on the online store. Consequently, it is possible to find any critical problem with the help of automated tests and fix it before deployment to a live version. There are a lot of existent solutions for the functional testing, but we have decided to point out one of the most popular among ecommerce representatives from absolutely different countries (the UK, Germany, the USA, Australia) – CasperJS. So, let’s start from its definition. 

CasperJS and Magento

CasperJS is an open source testing utility written in JavaScript that helps to ease the process of defining a full navigation scenario of actions as well as provides a wide range of useful functions and methods.

Having a great experience in testing, we can state with full confidence that CasperJS works with the websites based on Magento platform without any problems. To start using CasperJS, we have to install PhantomJS and CasperJS to the local computer. The process of  installation is not complicated and suits Mac, Linux, Windows. You can find the guidance on CasperJS official website.

And now, we offer you to review the tests for Magento websites. The necessary data for our functional tests we can took from the project presented on Magento Hackathon in 2014. Also, we will use the tests created to demonstrate you how CasperJS works. So, we prepared few tests for Magento online stores with sample data. They will help us to check all necessary place and steps.

To verify how the tests work, you just have to instal CasperJS on your local computer. At the beginning you need next things: local environment together with demo Magento site (version 1.9.2.2) as well as with sample data and command line interface. Then you have to create a folder with a configuration file (config.js) inside. There, all necessary data will be located.

// Configuration and some useful methods

 

/**

* Debug/Verbose

* ----------------------------------------------------------------------------

*/

var debug_mode = !!casper.cli.get('verbose');

if (debug_mode) {

   debug_mode = true;

   casper.options.verbose = true;

   casper.options.logLevel = 'debug';

}

var colorizer = require('colorizer').create('Colorizer');

 

/**

* The view

* ----------------------------------------------------------------------------

*/

 

// The viewport size

casper.options.viewportSize = {

   width: 1200,

   height: 900

};

casper.options.waitTimeout = 15000;

/**

* The HTTP responses

* ----------------------------------------------------------------------------

*/

casper.options.httpStatusHandlers = {

   200:  function(self, resource) {

       this.echo(resource.url + " is OK (200)", "INFO");

   },

   400:  function(self, resource) {

       this.echo(resource.url + " is nok (400)", "INFO");

   },

   404: function(self, resource) {

       this.echo("Resource at " + resource.url + " not found (404)", "COMMENT");

   },

   302: function(self, resource) {

       this.echo(resource.url + " has been redirected (302)", "INFO");

   }

};

 

/**

* Login credentials

* ----------------------------------------------------------------------------

*/

var login_user_firstname      = 'FirstName';

var login_user_lastname       = 'LastName';

var login_user_middlename   = 'MiddleName';

var login_user_username      = casper.cli.get("email");

if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(login_user_username)) {

   login_user_username

else {

   casper.die('Please enter valid email or add email to command line  --email="yourmail@example.com" ');

}

 

var login_user_password        = 'PassWord';

var login_user_password_bad = "badpassword";

 

var user_address_company    = 'Sam Ecommerce';

var user_address_street         = '16243 Ivy Lake Dr.';

var user_address_city            = 'Dnepropetrovsk';

var user_address_region        = 'Florida';

var user_address_postcode    = '33556';

var user_address_telephone   = '1234567890';

var user_address_fax             = '12345678';

var user_address_coundry      = 'United States';

 

/**

* Product credentials

* ----------------------------------------------------------------------------

*/

var prod_url_simple = 'madison-overear-headphones.html';

var prod_name_simple = 'Madison Overear Headphones';

var prod_url_conf ='men/new-arrivals/chelsea-tee.html';

var prod_name_conf = 'Chelsea Tee';

 

/* Utils, XPath, FileSystem

* ----------------------------------------------------------------------------

*/

var utils   = require('utils');

var x       = casper.selectXPath;

var fs      = require('fs');

 

/**

* URLs

* ----------------------------------------------------------------------------

*/

var base_url = casper.cli.get("base_url");

if (!/\/$/.test(base_url)) {

   // We have not trailing slash: add it

   base_url = base_url + '/';

}

 

// Done for the test file

// ----------------------------------------------------------------------------

casper.test.done();

 

/**

* Tear down and set up

* ----------------------------------------------------------------------------

*/

 

// Tear down:

// - reset captures counter

casper.test.tearDown(function () {

 

   // Reset captures counter

   captures_counter = 0;

});

 

// Set up: nothing

casper.test.setUp(function () {});

 

/**

* Steps

* ----------------------------------------------------------------------------

*/

casper.on("load.failed", function() {

   casper.capturePage();

});

casper.on("load.finished", function() {

   casper.printTitle();

   casper.capturePage();

});

casper.on("fill", function() {

   casper.capturePage();

});

casper.on("mouse.down", function() {

   casper.capturePage();

});

casper.on("mouse.move", function() {

   casper.capturePage();

});

casper.on("mouse.move", function() {

   casper.capturePage();

});

casper.on("step.complete", function() {

   casper.capturePage();

});

casper.on("step.error", function() {

   casper.capturePage('error');

});

casper.on("http.status.500", function() {

   casper.capturePage('500');

});

casper.on("http.status.404", function() {

   casper.capturePage('404');

});

/**

* Tools and cool methods :)

* ----------------------------------------------------------------------------

*/

// Clear cookies

casper.clearCookies = function () {

   casper.test.info("Clear cookies");

   casper.page.clearCookies();

};

 

// Print the current page title

casper.printTitle = function () {

   this.echo('### ' + casper.getTitle() + ' ###', 'INFO_BAR');

};

// Capture the current test page

var captures_counter = 0;

casper.capturePage = function (debug_name) {

   var directory = 'captures/' + casper.test.currentSuite.name;

   if (captures_counter > 0) {

       var previous = directory + '/step-' + (captures_counter-1) + '.jpg';

       if (debug_name) {

           var current = directory + '/step-' + captures_counter + '-' + debug_name + '.jpg';

       } else {

           var current = directory + '/step-' + captures_counter + '.jpg';

       }

       casper.capture(current);

       // If previous is same as current (and no debug_name), remove current

       if (!debug_name && fs.isFile(previous) && fs.read(current) === fs.read(previous) && fs.isFile(current)) {

           fs.remove(current);

           captures_counter--;

           casper.log('Capture removed because same as previous', 'warning');

       }

   } else {

       // We remove the directory to cleanup

       fs.removeTree(directory);

   }

   captures_counter++;

};

  

And now, we will write our first test to verify the registration process. Filling in all the necessary fields, we will check the registration page. Also, we will create new customer and test the logout process. For that end, we need to create a JavaScript file in the already created folder and add the below cited code:

casper.test.begin('001 Registration new customer ', function suite() {

 

   casper.start(function () {

       this.open(base_url);

       this.test.assertHttpStatus(200);

       this.test.comment('Open home page');

   });

   casper.thenOpen(base_url +'customer/account/create/', function(){

       this.test.comment('Open and check registration customer page');

       this.test.assertHttpStatus(200);

       this.test.assertUrlMatch(base_url +'customer/account/create/', 'You on the registration page');

       this.test.assertSelectorHasText('div.page-title', 'Create an Account', 'Page title - is present');

       this.test.comment('Check form input fields');

       this.test.assertExist('#firstname', 'First name input - is present');

       this.test.assertExist('#lastname', 'Last name input - is present');

       this.test.assertExist('#middlename', 'Middle name input - is present');

       this.test.assertExist('#password', 'Password input - is present');

       this.test.assertExist('#confirmation', 'Password confirmation name input - is present');

       this.test.assertExist('#email_address', 'E-mail input - is present');

       this.test.assertExist('#is_subscribed', 'Subscription checkbox - is present');

       this.test.assertExist('#form-validate div.buttons-set button.button', 'Submit button - is present');

       this.test.pass('Opened and checked registration customer page');

   });

   casper.then(function(){

       this.test.comment('Fill and submit registration form');

       this.fill('form#form-validate', {

           'firstname': login_user_firstname,

           'middlename': login_user_middlename,

           'lastname': login_user_lastname,

           'email': login_user_username,

           'password': login_user_password,

           'confirmation': login_user_password,

           'is_subscribed': true

       }, false);

       this.click('#form-validate div.buttons-set button.button');

       this.wait(400);

   });

   casper.then(function(){

       try {

           this.test.assertSelectorDoesntHaveText('li.error-msg span',

           'There is already an account with this email address.'

           + 'If you are sure that it is your email address,' );

       }

       catch(e){

           casper.die(this.getElementInfo('li.error-msg span').text);

       }

       this.waitForUrl(base_url + 'customer/account/index/');

       this.test.pass('Fill and submit registration form');

   });

 

   casper.then(function(){

       this.test.comment('Check successful registration and Logout');

       this.test.assertHttpStatus(200);

       this.test.assertUrlMatch(base_url + 'customer/account/index/', 'You on the My account page');

       this.test.assertSelectorHasText('div.dashboard li.success-msg',

       'Thank you for registering with Madison Island.', 'Success msg - is present');

       this.test.pass('Registration successful');

   });

 

   casper.then(function(){

       this.test.comment('Check customer logout');

       this.test.assertSelectorHasText('#header-account div.links', 'Log Out', 'Log Out link - is present');

       this.clickLabel('Log Out', 'a');

       this.waitForUrl(base_url + 'customer/account/logoutSuccess/');

   });

   casper.then(function(){

       this.test.assertHttpStatus(200);

       this.test.assertUrlMatch(base_url + 'customer/account/logoutSuccess/', 'You on the logout success page');

       this.test.assertSelectorHasText('div.col-main div.page-title', 'You are now logged out',

       'You are now logged out');

       this.test.assertSelectorHasText('div.col-main p',

       'You have logged out and will be redirected to our homepage in 5 seconds.',

       'You have logged out and will be redirected to our homepage in 5 seconds.')

       this.test.pass('You have successfully logged out');

   });

 

   casper.run(function () {

           this.test.done();

       }

   )

});

The net result is that you will see the next output in your command line interface:

leandry@machine:~/sites/testsautomatisation/casperjs/sample/tests (master)$ casperjs --pre=config.js test --base_url="

http://mage.sam-ecommerce.com/" 

testsautomatisation/casperjs/sample/tests/config.js

Test file: tests/main_functionality/001_registration.js

# Registration new customer

http://mage.sam-ecommerce.com/customer/account/create/ is OK (200)

### Create New Customer Account ###

# Open and check registration customer page

PASS HTTP status code is: 200

PASS You on the registartion page

PASS Page title - is present

# Check from input fields

PASS First name input - is present 

PASS Last name input - is present 

PASS Middle name input - is present 

PASS Password input - is present

PASS Password confirmation name input - is present

PASS E-mail input - is present

PASS Subscription checkbox - is present

PASS Submit button - is present

PASS Opened and checked registration customer page

# Fill and submit registration form

http://mage.sam-ecommerce.com/customer/account/createpost/  

Fill and submit registration form

# Check successful registration and Logout

PASS HTTP status code is: 200

PASS You on the My account page

PASS Success msg - is present

PASS Registration successful

# Check customer logout

PASS Log Out link - is present

http://mage.sam-ecommerce.com/customer/account/logout/ has been redirected (302)

http://mage.sam-ecommerce.com/customer/account/logoutSuccess/ is OK (200)

### Magento Commerce ###

PASS HTTP status code is: 200

PASS You on the logout success page

PASS You are now logged out

PASS You have logged out and will be redirected to our homepage in 5 seconds.

PASS You have successfully logged out

PASS 24 tests executed in 7.398s, 24 passed, 0 failed, 0 dubious, 0 skipped.

Moreover, you can find the automatically created screenshots in the folder “capture”.

The second test is “02_add_product_to_cart.js”. We use it to add a product to the cart. This test checks the product view page, add the product to the shopping cart functionality and shopping cart page.

casper.test.begin('002 Add product to cart and check shopping cart', function suite() {

 casper.start(function () {

       this.open(base_url);

       this.test.assertHttpStatus(200);

       this.test.comment('Open home page');

   });

   casper.thenOpen(base_url + prod_url_simple, function(){

       this.test.assertHttpStatus(200);

       this.test.comment('Open simple product page ('+ prod_name_simple + ')');

       this.test.info('Current location is ' + this.getCurrentUrl());

       this.test.assertSelectorExist('div.add-to-cart-buttons button.btn-cart', 'Add to cart btn - is present');

       this.test.assertSelectorHasText('div.product-shop div.product-name span.h1', prod_name_simple,

       'Product name - is present');

       this.test.assertSelectorExist('div.product-shop div.price-box span.price', 'Product price - is present');

       this.test.assertSelectorExist('#qty', 'Qty input field - is present');

       this.test.pass('Product page have been opened successfully');

   });

   casper.thenClick('div.add-to-cart-buttons button.btn-cart', function(){

       this.waitForUrl(base_url + 'checkout/cart/');

       this.test.info('Current location is ' + this.getCurrentUrl());

       this.test.assertHttpStatus(200);

       this.test.assertSelectorHasText('ul.messages li.success-msg', prod_name_simple

       +' was added to your shopping cart.', 'Success msg - is present');

       this.test.assertElementCount('#shopping-cart-table tbody tr', 1, '1 expected products have found ');

       this.test.assertExist(

       'div.page  div.cart-totals-wrapper button.button.btn-proceed-checkout.btn-checkout',

       'Checkout button - is present');

       this.test.assertExist('#discount-coupon-form', 'Discount coupon form - is present');

       this.test.assertExist('div.cart-forms div.shipping', 'ESTIMATE SHIPPING AND TAX form - is present');

       this.test.assertExist('#shopping-cart-totals-table', 'Totals table is present');

       this.test.pass('Shopping cart opened successfully');

   });

   casper.thenOpen(base_url + prod_url_conf, function(){

       this.test.assertHttpStatus(200);

       this.test.comment('Open configurable product page ('+ prod_url_conf + ')');

       this.test.info('Current location is ' + this.getCurrentUrl());

       this.test.assertSelectorExist('div.add-to-cart-buttons button.btn-cart', 'Add to cart btn - is present');

       this.test.assertSelectorHasText('div.product-shop div.product-name span.h1', prod_name_conf,

       'Product name - is present');

       this.test.assertSelectorExist('div.product-shop div.price-box span.price', 'Product price - is present');

       this.test.assertSelectorExist('#qty', 'Qty input field - is present');

       this.test.comment('Set options and add product to the cart');

       this.test.assertExist('#product-options-wrapper', 'Product options - is present');

       //              Click on white color swatch

       this.test.assertExist('#configurable_swatch_color', 'Color swatch - is present');

       this.click('#configurable_swatch_color li.option-white a span.swatch-label');

       this.test.assertSelectorExist('#configurable_swatch_color li.option-white.selected',

       'Color swatch has been selected');

       //              Click on L size

       this.test.assertExist('#configurable_swatch_size', 'Side swatch - is present');

       this.test.assertSelectorExist('#configurable_swatch_size li.option-s.not-available',

       'S size is not available for the white color swatch');

       this.click('#configurable_swatch_size li.option-l a span.swatch-label');

       this.test.assertSelectorExist('#configurable_swatch_size li.option-l.selected');

       //fill monogram field

       this.sendKeys('#options_3_text', 'Sam test');

       var test_msg = this.evaluate(function() {

           return jQuery("#options_3_text").val();

       });

       this.test.assertEqual(test_msg, "Sam test", "Found expected text within the textarea");

       //select test custom option

       this.evaluate(function(){

           //jQuery('#select_2').val(1);

           document.querySelector('#select_2').selectedValue = 1; //Value - 1 = model 1 +$59.00

       });

   });

   casper.thenClick('div.add-to-cart-buttons button.btn-cart', function(){

       this.waitForUrl(base_url + 'checkout/cart/');

       this.test.info('Current location is ' + this.getCurrentUrl());

       this.test.assertHttpStatus(200);

       this.test.assertSelectorHasText('ul.messages li.success-msg', prod_name_conf

       +' was added to your shopping cart.', 'Success msg - is present');

       this.test.assertElementCount('#shopping-cart-table tbody tr', 2, '2 expected products have found ');

       this.test.assertExist(

       'div.page  div.cart-totals-wrapper button.button.btn-proceed-checkout.btn-checkout',

       'Checkout button - is present');

       this.test.assertExist('#discount-coupon-form', 'Discount coupon form - is present');

       this.test.assertExist('div.cart-forms div.shipping', 'ESTIMATE SHIPPING AND TAX form - is present');

       this.test.assertExist('#shopping-cart-totals-table', 'Totals table is present');

       this.test.pass('Shopping cart opened successfully');

   });

   casper.thenClick('#empty_cart_button', function(){

      this.test.comment('Click empty cart button');

       this.test.assertSelectorHasText('div.page div.page-title  h1', 'Shopping Cart is Empty',

       'Shopping Cart is Empty');

       this.test.assertSelectorHasText('div.page div.cart-empty',

       'You have no items in your shopping cart.',

       'You have no items in your shopping cart.');

   });

 

   casper.run(function () {

           this.test.done();

       }

   )

});

# 002 Add product to cart and check shopping cart

http://mage.sam-ecommerce.com/madison-overear-headphones.html is OK (200)

### Madison Overear Headphones ###

PASS HTTP status code is: 200

# Open simple product page (Madison Overear Headphones)

Current location is http://mage.sam-ecommerce.com/madison-overear-headphones.html

PASS Add to cart btn - is present

PASS Product name - is present

PASS Product price - is present

PASS Qty input field - is present

PASS Product page have been opened successfully

http://mage.sam-ecommerce.com/checkout/cart/add/uenc/aHR0cDovL21hZ2UuYXR3aXguY29tL21hZGlzb24tb3Zl

cmVhciloZWFkcGhvbmVzlm0bWw_X19fU0lEPVU,/product/398/form_key/bOWzJVyRVjWqvFZO/ has

been redirected (302)

http://mage.sam-ecommerce.com/checkout/cart/ is OK (200)

### Shopping cart ###

Current location is http://mage.sam-ecommerce.com/checkout/cart/ 

PASS  HTTP status code is: 200

PASS Success msg  - is present

PASS 1 expected products have found

PASS Checkout button - is present

PASS Discount coupon form - is present

PASS ESTIMATE SHIPPING AND TAX form - is present

PASS Totals table - is present

PASS Shopping cart opened successfully 

http://mage.sam-ecommerce.com/men/new-arrivals/chelsea-tee.html is OK (200)

### Chelsea Tee - New Arrivals - Men ###

PASS  HTTP status code is: 200

# Open configurable product page (men/new-arrivals/chelsea-tee.html)

Current location is http://mage.sam-ecommerce.com/men/new-arrivals/chelsea-tee.html

PASS Add to cart btn - is present

PASS Product name - is present

PASS Product price - is present

PASS Qty input field - is present

# Set options and add product to the cart

PASS Product options - is present

PASS Color swatch - is present

PASS Color swatch has been selected

PASS Side swatch - is present

PASS S size is not available for the white color swatch

PASS Find an element matching: #configurable_swatch_size li.option-l.selected

PASS Found expected text within the textarea

http://mage.sam-ecommerce.com/checkout/cart/add/uenc/aHR0cDovL21hZ2UuYXR3aXguY29tL21lbi9uZXctYXJ

yaXZhbHMvY2hlbHNlYS10ZWuaHRtbD9fX19TSUQ9VQ,,/product/410/form_key/bOWzJVyRVjWqvFZO/ 

has been redirected (302)

http://mage.sam-ecommerce.com/checkout/cart/ is OK (200) 

### Shopping cart ###

Current location is http://mage.sam-ecommerce.com/checkout/cart/ 

PASS  HTTP status code is: 200

PASS Success msg  - is present

PASS 2 expected products have found

PASS Checkout button - is present

PASS Discount coupon form - is present

PASS ESTIMATE SHIPPING AND TAX form - is present

PASS Totals table - is present

PASS Shopping cart opened successfully 

http://mage.sam-ecommerce.com/checkout/cart/updatePost/ has been redirected (302)

http://mage.sam-ecommerce.com/checkout/cart/ is OK (200) 

### Shopping cart ###

# Click empty cart button

PASS Shopping Cart is Empty

PASS You have no items in your shopping cart

PASS 36 tests executed in 10.526s, 36 passed, 0 failed, 0 dubious, 0 skipped.

The next test “03_checkout.js” is written for checkout. It checks the add a simple product to the cart functionality, how checkout page opens and all the stages of order creation. 

casper.test.begin('003 Checkout - Guest - One Page checkout ', function suite() {

   casper.start(function () {

       this.open(base_url);

       this.test.assertHttpStatus(200);

       this.test.comment('Open home page');

   });

   //fast add simple product to the cart without check any additional functionality

   casper.thenOpen(base_url + 'madison-8gb-digital-media-player.html', function(){

       this.test.comment('fast add simple product to the cart without check any additional functionality');

       this.test.assertHttpStatus(200);

       this.test.info('Current location is ' + this.getCurrentUrl());

       this.click('div.add-to-cart-buttons button.btn-cart');

       this.waitForUrl(base_url + 'checkout/cart/');

   });

   //Checkout Method

   casper.thenClick('div.cart div.cart-totals button.btn-proceed-checkout.btn-checkout', function(){

       this.test.comment('check Checkout Method step');

       this.test.assertUrlMatch(base_url+'checkout/onepage/');

       this.test.assertExist('#checkout-step-login',  'Checkout method step - is present');

       this.test.assertExist('#login-email', 'E-mail in;ut field - is present');

       this.test.assertExist('#login-password',  'Password input field - is present');

       this.test.assertExist('#login-form a.f-left',  'Forgot Pass link - is present');

       this.test.assertExist('#checkout-step-login button.button''Login submit button - is present');

       this.test.assertExist('input[value="guest"]',  'Checkout as Guest radio button - is present');

       this.test.assertExist('input[value="register"]',  'Registration and Checkout radio btn - is present');

       this.test.assertExist('#onepage-guest-register-button',  'Continue button - is present');

       this.evaluate(function() {

           document.getElementById('login:guest').checked = true;

           checkout.setMethod();

       });

   });

   casper.thenClick('#onepage-guest-register-button', function(){

       this.test.comment('Submit Continue as a Guest ');

       this.test.assertExist('#checkout-progress-wrapper',  'Progress bar - is present');

       this.waitUntilVisible('li#opc-billing', function(){

           this.test.assertExists('input[name="billing[firstname]"]',  'First name input - is present');

           this.test.assertExists('input[name="billing[middlename]"]', 'Middle name input - is present');

           this.test.assertExists('input[name="billing[lastname]"]',  'Last name input - is present');

           this.test.assertExists('input[name="billing[company]"]',  'Company input - is present');

           this.test.assertExists('input[name="billing[email]"]',  'E-mail input - is present');

           this.test.assertExists('input[name="billing[street][]"]',  'Street input - is present');

           this.test.assertExists('input[name="billing[city]"]',  'City input - is present');

           this.test.assertExists('select[name="billing[region_id]"]', 'State select - is present');

           this.test.assertExists('input[name="billing[postcode]"]',  'Zip code input - is present');

           this.test.assertExists('select[name="billing[country_id]"]''Country select input - is present');

           this.test.assertExists('input[name="billing[telephone]"]',  'Phone input - is present');

           this.test.assertExists('input[name="billing[fax]"]',  'Fax input - is present');

           this.test.assertExists('input[name="billing[use_for_shipping]"]''Ship to radio btn  - is present');

           this.fill('form#co-billing-form', {

               'billing[firstname]' : login_user_firstname,

               'billing[middlename]' : login_user_middlename,

               'billing[lastname]' : login_user_lastname,

               'billing[company]' : user_address_company,

               'billing[email]' : login_user_username,

               'billing[street][]' : user_address_street,

               'billing[city]' : user_address_city,

               'billing[postcode]' : user_address_postcode,

               'billing[telephone]' : user_address_telephone,

               'billing[fax]' : user_address_fax

           }, false);

           this.evaluate(function(){

               document.querySelector('select[name="billing[country_id]"]').selectedValue = 'US'; //value  - us = USA

               document.querySelector('select[name="billing[region_id]"]').selectedIndex = 18;//id = 18 = florida

               document.getElementById('billing:use_for_shipping_yes').checked = true;

           });

       });

   });

   casper.thenClick('#billing-buttons-container button.button', function(){

       this.test.comment('Submit Billing informationt');

       this.waitUntilVisible('#checkout-step-shipping_method', function () {

           this.test.assertExist('#s_method_flatrate_flatrate', 'Flat Rate shipping is available');

           this.evaluate(function(){

               document.getElementById('s_method_flatrate_flatrate').checked = true;

           });

       })

   });

   casper.thenClick('#shipping-method-buttons-container button.button', function () {

      this.test.comment('Submit Shipping method');

       this.waitUntilVisible('#checkout-step-payment', function(){

           this.test.assertExist('#dt_method_cashondelivery');

           //this.test.click('#payment-buttons-container > button.button');

       })

   });

   casper.thenClick('#payment-buttons-container > button.button', function () {

      this.test.comment('Submit Payment');

       this.waitUntilVisible('#checkout-step-review', function () {

           this.test.assertExists('#checkout-review-table');

           this.test.pass('Order Grand total -> '

          + this.getElementInfo('#checkout-review-table tr.last td.a-right.last span.price').text);

           this.click('#review-buttons-container button.btn-checkout');

       });

   });

   casper.waitForUrl(base_url + 'checkout/onepage/success', function () {

       this.test.assertHttpStatus(200);

       this.test.assertExists('.checkout-onepage-success', 'Success page is present');

       this.test.pass('The order has been placed successfully');

       this.test.comment(this.getElementInfo('div.page > div.main-container.col1-layout  p:nth-child(4)').text)

   });

   casper.run(function () {

           this.test.done();

       }

   )

});

Test file: /Users/leandry/sites/testsautomatisation/casperjs/sample/tests/config.js

Test file: tests/main_functionality/003_checkout.js

#003 Checkout - Guest - One Page checkout

http://mage.sam-ecommerce.com/madison-8gb-digital-media-player.html is OK (200)

### Madison 8GB Digital Media Player ###

# fast add simple product to the cart without check any additional functionality 

PASS HTTP status code is: 200

Current location is http://mage.sam-ecommerce.com/madison-8gb-digital-media-player.htm

http://mage.sam-ecommerce.com/checkout/cart/add/uenc/aHR0cDovL21hZ2UuYXR3aXguY29tL21

hZGlzb24tOGdiLWRpZ210YWwtbWVkaWEtcGxheWVyLh0bWwX19fU0lEPVU,/product/399/form_key/

xZaN9o3rdQYyT9fR/ has been redirected (302)

http://mage.sam-ecommerce.com/checkout/cart/ is Ok (200) 

### Shopping cart ###

http://mage.sam-ecommerce.com/checkout/openpage/  is OK (200)

### Checkout ###

# check Checkout Method step

PASS Current url matches the provided pattern

PASS Checkout method step - is present

PASS E-mail in;ut field - is present

PASS Password input field - is present

PASS Forgot Pass link - is present

PASS Login submit button - is presen

PASS Checkout as Guest radio button - is present

PASS Registration and Checkout radio btn - is present

PASS Continue button - is present

# Submit Continue as a Guest

PASS Progress bar 

PASS First name input - is present

PASS Middle name input - is present

PASS Last name input - is present

PASS Company input - is present

PASS E-mail input - is present

PASS Street input - is present

PASS City input - is present

PASS State select - is present

PASS Zip code input - is present

PASS Country select input - is present

PASS Phone input - is present

PASS Fax input - is present

PASS Ship to radio btn - is present

# Submit Billing information

PASS Flate Rate shipping is available

# Submit Shipping method

PASS Find an element matching: #dt_method_cashondelivery

# Submit Payment

PASS Find an element matching: #checkout-review-table

PASS Order Grand total -> $167.38

http://mage.sam-ecommerce.com/checkout/openpage/  is OK (200)

### Magento Commerce ###

PASS HTTP status code is: 200

PASS Success page is present

PASS The order has been placed successfully

# Your order # is: 145000013.

PASS 31 tests executed in 26.875s, 31 passed, 0 failed, 0 dubious, 0 skipped.

It is necessary to launch a command from the folder with all tests to run this test.

casperjs --pre=config.js test --base_url="http://magento.store.url" --email="yourmail@example.com" test_name.js

Remember that you have to change “–base_url” and “–email” parameters to your data and after enter a test script name.

Below, the additional information regarding all used parameters is presented:

––pre=config.js – file with methods and CasperJS configurations such as selecting the browser resolution, a level of the debug mode, login credentials, pages screenshot, cookies cleaner, timeout setter etc.

––base_url – URL of testing Magento website.

––email – e-mail used in customer forms.

––verbose – it runs a debugger (the debug level can be set in the config file).

TEST_NAME.js – name of your test script.

We have launched all tests by using Terminal on Mac OS X. Also, you can find all the tests on GitHub. We hope that this guidance will ease the testing process. If you have any additional questions, our Sam Ecommerce Magento development team will be happy to answer them! More information regarding Magento and Magento 2 development you can find here:

Comments (1):
Posted on Wednesday, September 14, 2016 by :
I think this is one of the most important info for me. And i am glad rediang your article. But should remark on some general things, The web site style is great, the articles is really nice : D. Good job, cheers
Leave a comment:
*Your comment will be published after approval by site administrator.