test-suite/tests/000_test_helpers.js
changeset 636 a8ab808d33c3
parent 633 44634d19db32
equal deleted inserted replaced
635:57d3834c5c01 636:a8ab808d33c3
    27 		browser.navigateTo ('/');
    27 		browser.navigateTo ('/');
    28 		expect (elt ('#footer a[href="/help/"]').text ()).toMatch (new RegExp (l, 'm'));
    28 		expect (elt ('#footer a[href="/help/"]').text ()).toMatch (new RegExp (l, 'm'));
    29 	}));
    29 	}));
    30 }
    30 }
    31 
    31 
    32 /** Test if the selected DOM element is defined or has a given value : .val()
    32 /** Test if the selected DOM element .text() value match the given regexp
       
    33  *	s : CSS selector
       
    34  *	r : regexp to match
       
    35  */
       
    36 function test_match (s, r) {
       
    37 	test (s+' text match '+r, dsl(function () {
       
    38 		expect (elt (s).text ()).toMatch (r);
       
    39 	}));
       
    40 }
       
    41 
       
    42 /** Test if the selected DOM element has a given value : .val()
    33  *	s : CSS selector
    43  *	s : CSS selector
    34  *	e : expected value, if omited, test existence
    44  *	e : expected value, if omited, test existence
    35  */
    45  */
    36 function test_val (s, e) {
    46 function test_val (s, e) {
    37 	e = typeof e == 'undefined' ? '' : e; // .val() returns defined ? '' : undefined; // if no value
    47 	e = typeof e == 'undefined' ? '' : e; // .val() returns defined ? '' : undefined; // if no value
    38 	test (s+' is '+e, dsl(function () {
    48 	test (s+' is '+e, dsl(function () {
    39 		expect (elt (s).val ()).toMatch (new RegExp (e, 'm'));
    49 		expect (elt (s).val ()).toMatch (new RegExp (e, 'm'));
    40 	}));
    50 	}));
    41 }
    51 }
    42 
    52 
       
    53 /**
       
    54  *
       
    55  */
    43 function test_exist (s) {
    56 function test_exist (s) {
    44 	test_val (s);
    57 	test_val (s);
    45 }
    58 }
    46 
    59 
    47 /** Test if the selected DOM element has the given text : .text()
    60 /** Test if the selected DOM element has the given text : .text()
    51  */
    64  */
    52 function test_text (s, e, v) {
    65 function test_text (s, e, v) {
    53 	v = typeof v == 'undefined' ? true : v;
    66 	v = typeof v == 'undefined' ? true : v;
    54 	test (s+' has text '+e, dsl(function () {
    67 	test (s+' has text '+e, dsl(function () {
    55 		expect (elt (s, v).text ()).toBe (e);
    68 		expect (elt (s, v).text ()).toBe (e);
    56 	}));
       
    57 }
       
    58 
       
    59 /** Test if the selected DOM element .text() value match the given regexp
       
    60  *	s : CSS selector
       
    61  *	r : regexp to match
       
    62  */
       
    63 function test_match (s, r) {
       
    64 	test (s+' text match '+r, dsl(function () {
       
    65 		expect (elt (s).text ()).toMatch (r);
       
    66 	}));
    69 	}));
    67 }
    70 }
    68 
    71 
    69 /** Count selector occurences
    72 /** Count selector occurences
    70  *	s : CSS selector
    73  *	s : CSS selector
   107 		input (s).enter (v[s]);
   110 		input (s).enter (v[s]);
   108 	}));
   111 	}));
   109 }
   112 }
   110 
   113 
   111 /**
   114 /**
   112  * Click somewhere
   115  * Click on something
   113  * s : selector of the item to click on
   116  * s : selector of the item to click on
       
   117  * w : should we wait for a page to load in the browser after the click
   114  * v : is the element visible or not
   118  * v : is the element visible or not
   115  */
   119  */
   116 function test_click (s, v) {
   120 function test_click (s, w, v) {
   117     test ('click '+s, dsl(function () {
   121 	var t = 'click '+ w ? 'to submit form ' : '';
   118         elt (s, v).click ();
   122 	test (t+s, dsl(function () {
   119     }));
   123 		elt (s, v).click ();
       
   124 		if (w)
       
   125 			browser.waitForPageLoad ();
       
   126 	}));
   120 }
   127 }
   121 
   128 
   122 /**
   129 /**
   123  * Submit a form
   130  * Send submit event to the given form
   124  * s : selector of the submit button
   131  * s : selector of the form to submit
   125  */
   132  */
   126 function test_submit (s) {
   133 function test_submit (s) {
   127 	test ('submit '+s, dsl(function () {
   134 	test ('send submit event to '+s, dsl(function () {
   128 		elt (s).click ();
   135 		elt (s).submit ();
   129 		browser.waitForPageLoad ();
   136 		browser.waitForPageLoad ();
   130 	}));
   137 	}));
   131 }
   138 }
       
   139 
   132 
   140 
   133 /**
   141 /**
   134  * Reload a page
   142  * Reload a page
   135  */
   143  */
   136 function test_reload () {
   144 function test_reload () {