Added functionnal test for front office : home, register, login, cart
This commit is contained in:
@@ -1,3 +1,107 @@
|
||||
//LOCAL = ton pc
|
||||
var thelia2_base_url = 'http://www.thelia2.dev/index_dev.php/';
|
||||
casper.test.done(0);
|
||||
// LOCAL = ton pc
|
||||
|
||||
var system = require('system');
|
||||
|
||||
var thelia2_base_url = '';
|
||||
|
||||
|
||||
if (casper.cli.has('thelia2_base_url')){
|
||||
thelia2_base_url = casper.cli.get('thelia2_base_url');
|
||||
casper.test.comment('CasperJS will use Thelia on : '+ thelia2_base_url);
|
||||
} else if (system.env.thelia2_base_url){
|
||||
thelia2_base_url = system.env.thelia2_base_url;
|
||||
casper.test.comment('CasperJS will use Thelia (ENV) on : '+ thelia2_base_url);
|
||||
} else {
|
||||
thelia2_base_url = 'http://dev.thelia.net/index_dev.php/';
|
||||
casper.test.comment('CasperJS will use fallback URL for tests : '+ thelia2_base_url);
|
||||
casper.test.comment('If you want to use custom URL just set the environment variable `thelia2_base_url`');
|
||||
}
|
||||
|
||||
var screenshot_dir = 'tests/functionnal/casperjs/screenshot/';
|
||||
|
||||
|
||||
casper.options.viewportSize = {width: 1024, height: 768};
|
||||
|
||||
var viewports = [
|
||||
{
|
||||
'name': 'samsung-galaxy_y-portrait',
|
||||
'viewport': {width: 240, height: 320}
|
||||
},
|
||||
{
|
||||
'name': 'samsung-galaxy_y-landscape',
|
||||
'viewport': {width: 320, height: 240}
|
||||
},
|
||||
{
|
||||
'name': 'iphone5-portrait',
|
||||
'viewport': {width: 320, height: 568}
|
||||
},
|
||||
{
|
||||
'name': 'iphone5-landscape',
|
||||
'viewport': {width: 568, height: 320}
|
||||
},
|
||||
{
|
||||
'name': 'htc-one-portrait',
|
||||
'viewport': {width: 360, height: 640}
|
||||
},
|
||||
{
|
||||
'name': 'htc-one-landscape',
|
||||
'viewport': {width: 640, height: 360}
|
||||
},
|
||||
{
|
||||
'name': 'nokia-lumia-920-portrait',
|
||||
'viewport': {width: 240, height: 320}
|
||||
},
|
||||
{
|
||||
'name': 'nokia-lumia-920-landscape',
|
||||
'viewport': {width: 320, height: 240}
|
||||
},
|
||||
{
|
||||
'name': 'google-nexus-7-portrait',
|
||||
'viewport': {width: 603, height: 966}
|
||||
},
|
||||
{
|
||||
'name': 'google-nexus-7-landscape',
|
||||
'viewport': {width: 966, height: 603}
|
||||
},
|
||||
{
|
||||
'name': 'ipad-portrait',
|
||||
'viewport': {width: 768, height: 1024}
|
||||
},
|
||||
{
|
||||
'name': 'ipad-landscape',
|
||||
'viewport': {width: 1024, height: 768}
|
||||
},
|
||||
{
|
||||
'name': 'desktop-standard-vga',
|
||||
'viewport': {width: 640, height: 480}
|
||||
},
|
||||
{
|
||||
'name': 'desktop-standard-svga',
|
||||
'viewport': {width: 800, height: 600}
|
||||
},
|
||||
{
|
||||
'name': 'desktop-standard-hd',
|
||||
'viewport': {width: 1280, height: 720}
|
||||
},
|
||||
{
|
||||
'name': 'desktop-standard-sxga',
|
||||
'viewport': {width: 1280, height: 1024}
|
||||
},
|
||||
{
|
||||
'name': 'desktop-standard-sxga-plus',
|
||||
'viewport': {width: 1400, height: 1050}
|
||||
},
|
||||
{
|
||||
'name': 'desktop-standard-uxga',
|
||||
'viewport': {width: 1600, height: 1200}
|
||||
},
|
||||
{
|
||||
'name': 'desktop-standard-wuxga',
|
||||
'viewport': {width: 1920, height: 1200}
|
||||
},
|
||||
|
||||
];
|
||||
|
||||
;
|
||||
|
||||
casper.test.done();
|
||||
|
||||
@@ -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();
|
||||
|
||||
15
tests/functionnal/casperjs/exe/front/10_home.js
Normal file
15
tests/functionnal/casperjs/exe/front/10_home.js
Normal 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();
|
||||
});
|
||||
|
||||
});
|
||||
111
tests/functionnal/casperjs/exe/front/20_register.js
Normal file
111
tests/functionnal/casperjs/exe/front/20_register.js
Normal 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();
|
||||
});
|
||||
|
||||
});
|
||||
71
tests/functionnal/casperjs/exe/front/30_login.js
Normal file
71
tests/functionnal/casperjs/exe/front/30_login.js
Normal 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();
|
||||
});
|
||||
|
||||
});
|
||||
51
tests/functionnal/casperjs/exe/front/40_cart.js
Normal file
51
tests/functionnal/casperjs/exe/front/40_cart.js
Normal 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();
|
||||
});
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user