Added functionnal test for front office : home, register, login, cart

This commit is contained in:
Julien Chanseaume
2014-08-11 11:28:23 +02:00
parent 94cc1ea516
commit 473402bf88
8 changed files with 395 additions and 11 deletions

View File

@@ -17,4 +17,4 @@ var thelia2_content_image_list_url = thelia2_base_url + 'admin/content/update/1'
casper.test.comment('Variables are set');
casper.test.done(0);
casper.test.done();

View File

@@ -0,0 +1,15 @@
casper.test.comment('== Front Homepage ==');
casper.test.begin('Front Homepage', 2, function suite(test) {
casper.start(thelia2_base_url, function() {
test.assertTitle("", "Thelia 2 homepage title is the one expected");
test.assertExists('form#form-search', "main search form is found");
this.capture(screenshot_dir + 'front/10_home.png');
});
casper.run(function() {
test.done();
});
});

View File

@@ -0,0 +1,111 @@
casper.test.comment('== Register ==');
casper.test.begin('Register', 15, function suite(test) {
var newEmail = '';
casper.start(thelia2_base_url + "register", function() {
test.assertTitle("Register - Thelia V2", "title is the one expected");
test.assertExists('form#form-register', "register form is found");
this.capture(screenshot_dir + 'front/20_register.png');
casper.test.comment('== Register blank account');
this.fill('form#form-register', {
'thelia_customer_create[title]': '',
'thelia_customer_create[firstname]': '',
'thelia_customer_create[lastname]': '',
'thelia_customer_create[email]': '',
'thelia_customer_create[phone]': '',
'thelia_customer_create[cellphone]': '',
'thelia_customer_create[company]': '',
'thelia_customer_create[address1]': '',
'thelia_customer_create[address2]': '',
'thelia_customer_create[zipcode]': '',
'thelia_customer_create[city]': '',
'thelia_customer_create[country]': '',
'thelia_customer_create[password]': '',
'thelia_customer_create[password_confirm]': '',
'thelia_customer_create[newsletter]': ''
}, true);
});
casper.then(function() {
casper.test.comment('== Register thelia account');
this.capture(screenshot_dir + 'front/20_register-ko.png');
test.assertExists('.group-title.has-error', 'title can not be empty');
test.assertExists('.group-firstname.has-error', 'firstname can not be empty');
test.assertExists('.group-lastname.has-error', 'lastname can not be empty');
test.assertExists('.group-email.has-error', 'email can not be empty');
test.assertExists('.group-address1.has-error', 'address1 can not be empty');
test.assertExists('.group-zip.has-error', 'zipcode can not be empty');
test.assertExists('.group-city.has-error', 'city can not be empty');
test.assertExists('.group-password.has-error', 'password can not be empty');
test.assertExists('.group-password_confirm.has-error', 'password confirm can not be empty');
newEmail = Math.random().toString(36).substr(2,7) + '@thelia.net';
this.fill('form#form-register', {
'thelia_customer_create[title]': 1,
'thelia_customer_create[firstname]': 'thelia',
'thelia_customer_create[lastname]': 'thelia',
'thelia_customer_create[email]': 'test@thelia.net',
'thelia_customer_create[phone]': '',
'thelia_customer_create[cellphone]': '',
'thelia_customer_create[company]': 'OpenStudio',
'thelia_customer_create[address1]': '4 rue Rochon',
'thelia_customer_create[address2]': '',
'thelia_customer_create[zipcode]': '63000',
'thelia_customer_create[city]': 'Clermont-Ferrand',
'thelia_customer_create[country]': 64,
'thelia_customer_create[password]': 'thelia',
'thelia_customer_create[password_confirm]': 'thelia',
'thelia_customer_create[newsletter]': ''
}, false);
this.click('form#form-register button[type="submit"]');
});
casper.wait(1000, function(){
test.assertSelectorHasText('.group-email .help-block', 'This email already exists.');
this.fill('form#form-register', {
'thelia_customer_create[email]': newEmail,
'thelia_customer_create[password]': 'thelia',
'thelia_customer_create[password_confirm]': 'thelia'
}, false);
this.click('form#form-register button[type="submit"]');
});
casper.wait(2000, function() {
this.capture(screenshot_dir + 'front/20_register-ok.png');
test.assertSelectorHasText('h1#main-label', 'My Account');
test.assertExists('a.logout', 'Logout button exists');
casper.test.comment('== Logout');
this.click('a.logout');
});
casper.wait(2000, function() {
test.assertExists('a.login', 'Login button exists');
});
casper.run(function() {
test.done();
});
});

View File

@@ -0,0 +1,71 @@
casper.test.comment('== Login ==');
casper.test.begin('Login', 5, function suite(test) {
casper.start(thelia2_base_url + "login", function() {
test.assertTitle("Login - Thelia V2", "title is the one expected");
test.assertExists('form#form-login', "login form is found");
this.capture(screenshot_dir + 'front/30_login.png');
casper.test.comment('== Login with a bad account');
this.fill('form#form-login', {
'thelia_customer_login[account]': "1"
}, false);
});
casper.then(function(){
casper.evaluate(function(username, password) {
document.querySelector('#email').value = username;
document.querySelector('#password').disabled = false;
document.querySelector('#password').value = password;
}, 'chuck-norris@thelia.net', 'thelia');
this.capture(screenshot_dir + 'front/30_login-ko-0.png');
this.click('form#form-login button[type="submit"]');
});
casper.wait(2000, function(){
this.capture(screenshot_dir + 'front/30_login-ko.png');
test.assertSelectorHasText('form#form-login .alert-danger', 'Wrong email or password. Please try again');
casper.test.comment('== Login with a good account');
casper.evaluate(function(username, password) {
document.querySelector('#email').value = username;
document.querySelector('#password').disabled = false;
document.querySelector('#password').value = password;
}, 'test@thelia.net', 'azerty');
this.click('form#form-login button[type="submit"]');
});
casper.wait(2000, function(){
this.capture(screenshot_dir + 'front/30_login-ok.png');
test.assertExists('a.logout', 'Logout button exists');
casper.test.comment('== Logout');
this.click('a.logout');
});
casper.wait(2000, function(){
test.assertExists('a.login', 'Login button exists');
});
casper.run(function() {
test.done();
});
});

View File

@@ -0,0 +1,51 @@
casper.test.comment('== Cart ==');
casper.test.begin('Cart', 4, function suite(test) {
var productUrl = '';
casper.start(thelia2_base_url, function() {
casper.viewport(1280, 1024)
productUrl = this.getElementAttribute('a.product-info', 'href');
this.echo("product : " + productUrl);
casper.thenOpen(productUrl, function() {
this.echo(this.getTitle());
});
});
casper.wait(2000, function(){
this.capture(screenshot_dir + 'front/40_product.png');
this.click("#pse-submit");
});
casper.wait(2000, function() {
this.captureSelector(screenshot_dir + 'front/40_added-to-cart.png', '.bootbox');
test.assertSelectorHasText('.bootbox h3', 'The product has been added to your cart');
});
casper.then(function(){
this.thenOpen(thelia2_base_url + "cart", function() {
this.echo(this.getTitle());
test.assertExists("#cart .table-cart", "Cart table exists");
test.assertElementCount("#cart .table-cart tbody tr", 2, "Cart contains 1 product")
var link = this.getElementInfo('#cart .table-cart tbody tr a.thumbnail');
//require('utils').dump(link);
test.assertTruthy( link.attributes.href == productUrl, "This is the right product in cart");
this.capture(screenshot_dir + 'front/40_cart.png');
});
});
casper.run(function() {
test.done();
});
});