test-suite/lib/test_hlp.js
author Simon Descarpentries <sid@sopinspace.com>
Fri, 04 Apr 2014 18:49:35 +0200
changeset 625 eb52900a0bbf
parent 624 3dd70d01cec2
permissions -rw-r--r--
[Testsuite] Can create 3 texts
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
624
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
     1
// Test helpers for karma-e2e-dsl environment
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
     2
//	
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
     3
// https://github.com/winsonwq/karma-e2e-dsl
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
     4
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
     5
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
     6
exports.page_loading = function (url, title) {
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
     7
	test (url+' loads', dsl(function () {
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
     8
		// here we are in Karma page
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
     9
		browser.navigateTo (url);
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
    10
		expect (element ('title').text ()).toMatch (new RegExp (title,'m'));
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
    11
		// The same test agin vaniller javascript
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
    12
		element ('title').text (function (page_title) {
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
    13
			// here we got a value from the test iframe
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
    14
			// to display the tested value : console.log (page_title);
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
    15
			if (!(new RegExp (title, 'm').test (page_title))) throw 'got page '+page_title+' instead';
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
    16
		});
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
    17
	}));
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
    18
}
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
    19
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
    20
/** Test if it's possible to change lang to the specified :
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
    21
 *	c : lang code
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
    22
 *	l : help label
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
    23
 */
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
    24
exports.i18n = function (c, l) {
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
    25
	test ('to '+c, dsl(function () {
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
    26
		element ('#footer a[href="/i18n/setlang/'+c+'/"]').click ();
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
    27
		browser.navigateTo ('/');
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
    28
		expect (test_.elt ('#footer a[href="/help/"]').text ()).toMatch (new RegExp (l, 'm'));
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
    29
	}));
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
    30
}
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
    31
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
    32
/** Test if the selected DOM element is defined or has a given value : .val()
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
    33
 *	s : CSS selector
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
    34
 *	e : expected value, if omited, test existence
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
    35
 */
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
    36
exports.val = function (s, e) {
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
    37
	e = typeof e == 'undefined' ? '' : e; // .val() returns defined ? '' : undefined; // if no value
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
    38
	test (s+' is '+e, dsl(function () {
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
    39
		expect (test_.elt (s).val ()).toMatch (new RegExp (e, 'm'));
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
    40
	}));
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
    41
}
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
    42
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
    43
exports.exist = function (s) {
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
    44
	test_.val (s);
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
    45
}
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
    46
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
    47
/** Test if the selected DOM element has the given text : .text()
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
    48
 *	s : CSS selector
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
    49
 *	e : expected value
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
    50
 *	v : should we test a visible value ?
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
    51
 */
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
    52
exports.text = function (s, e, v) {
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
    53
	v = typeof v == 'undefined' ? true : v;
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
    54
	test (s+' has text '+e, dsl(function () {
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
    55
		expect (test_.elt (s, v).text ()).toBe (e);
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
    56
	}));
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
    57
}
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
    58
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
    59
/** Test if the selected DOM element .text() value match the given regexp
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
    60
 *	s : CSS selector
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
    61
 *	r : regexp to match
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
    62
 */
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
    63
exports.match = function (s, r) {
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
    64
	test (s+' text match '+r, dsl(function () {
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
    65
		expect (test_.elt (s).text ()).toMatch (r);
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
    66
	}));
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
    67
}
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
    68
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
    69
/** Count selector occurences
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
    70
 *	s : CSS selector
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
    71
 *	e : expected count
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
    72
 */
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
    73
exports.count = function (s, e) {
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
    74
	test (s+' count is '+e, dsl(function () {
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
    75
		expect (test_.elt (s).count ()).toBe (e);
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
    76
	}));
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
    77
}
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
    78
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
    79
/** Test Django form field presence
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
    80
 */
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
    81
exports.field = function (form_id, field_id, type, position, label, mandatory) {
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
    82
	test ('has a '+label+' form field', dsl(function () {
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
    83
		var s = '';
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
    84
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
    85
		switch (type) {
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
    86
			case 'textarea':s = 'textarea#'+field_id; break;
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
    87
			case 'select':	s = 'select#'+field_id; break;
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
    88
			default:		s = 'input#'+field_id+'[type="'+type+'"]';
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
    89
		}
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
    90
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
    91
		expect (test_.elt (s).val ()).toBeDefined ();
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
    92
		expect (test_.elt ('#'+form_id+' :input:eq('+position+')#'+field_id).val ()).toBeDefined ();
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
    93
		expect (test_.elt ('label[for='+field_id+']').text ()).toBe (label);
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
    94
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
    95
		if (mandatory)
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
    96
			expect (test_.elt ('label[for='+field_id+'] + span.required_star').val ()).toBeDefined ();
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
    97
	}));
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
    98
}
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
    99
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
   100
/**
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
   101
 * Fill form field
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
   102
 * s : form field id
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
   103
 * v : array containing the value to use
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
   104
 */
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
   105
exports.fill_field = function (s, v) {
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
   106
	test ('set '+s, dsl(function () {
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
   107
		input (s).enter (v[s]);
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
   108
	}));
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
   109
}
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
   110
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
   111
/**
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
   112
 * Submit a form
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
   113
 * s : selector of the submit button
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
   114
 */
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
   115
exports.submit = function (s) {
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
   116
	test ('submit '+s, dsl(function () {
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
   117
		test_.elt (s).click ();
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
   118
		browser.waitForPageLoad ();
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
   119
	}));
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
   120
}
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
   121
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
   122
/**
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
   123
 * Fails a test
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
   124
 */
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
   125
exports.fail = function () {
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
   126
	test ('must fail', dsl(function () {
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
   127
		throw 'have been programmed to fail now';
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
   128
	}));
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
   129
}
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
   130
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
   131
/**
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
   132
 * Inbrowser debugger statement
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
   133
 */
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
   134
exports.debug = function () {
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
   135
	test ('debugger', dsl(function (){
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
   136
		debugger; // not seen to work
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
   137
	}));
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
   138
}
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
   139
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
   140
/**
625
eb52900a0bbf [Testsuite] Can create 3 texts
Simon Descarpentries <sid@sopinspace.com>
parents: 624
diff changeset
   141
 * Have the browser waiting while you inspect what's going on
624
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
   142
 */
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
   143
exports.pause = function () {
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
   144
	test ('pause', dsl(function () {
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
   145
		browser.pause ();
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
   146
	}));
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
   147
}
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
   148
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
   149
/**
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
   150
 * Start back the testcases
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
   151
 */
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
   152
exports.resume = function () {
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
   153
	test ('resume', dsl(function (){
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
   154
		browser.resume ();
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
   155
	}));
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
   156
}
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
   157
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
   158
/** Ensure the given element is visible
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
   159
 *	s : CSS selector of the DOM element to check
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
   160
 *	v : should the element being visible
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
   161
 */
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
   162
exports.elt = function (s, v) {
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
   163
	return element (s + (v ? ':visible' : ''));
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
   164
}
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
   165
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
   166
/** Revive functions after a JSON.stringify which prevented their disappearence
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
   167
 * k : key in the object to revive functions in
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
   168
 * v : value
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
   169
 * 
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
   170
 * We keep only the string of the body part in order to use it to define a new function in tests files
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
   171
 * /!\ do NEVER minify this code ! /!\
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
   172
 *
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
   173
 */
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
   174
exports.reviveFunc = multilineString (function (k, v) {
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
   175
/*!	if (v && typeof v === 'string' && v.substr (0, 8) == 'function') { 
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
   176
		var a = v.indexOf ('{') + 1, // start function body 
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
   177
		b = v.lastIndexOf ('}'),	
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
   178
		c = v.indexOf ('(') + 1,	 // start args 
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
   179
		d = v.indexOf (')');		
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
   180
		return new Function (v.substring (c, d), v.substring (a, b)); 
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
   181
	}
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
   182
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
   183
	return v;*/
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
   184
});
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
   185
3dd70d01cec2 Divide tests.js in two distinct files, factorize helper functions in lib/test_hlp.js
Simon Descarpentries <sid@sopinspace.com>
parents:
diff changeset
   186
function multilineString (f) { return f.toString().replace(/^[^\/]+\/\*!?/, '').replace(/\*\/[^\/]+$/, ''); }