introducing a wrapper around windmill-js that adds support for macros in order to make it easier to make gridworks-specific UI testing a lot more compact (this is a tiny bit more verbose than the previuos method, but it allows us to group waits with actions and assertions which wasn't possible before, so it's a good price to pay).

git-svn-id: http://google-refine.googlecode.com/svn/trunk@709 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
Stefano Mazzocchi 2010-05-11 17:17:34 +00:00
parent f341fa8db2
commit 668b763f6b
2 changed files with 115 additions and 76 deletions

View File

@ -5,62 +5,64 @@ var test_facets = new function() {
//go back //go back
//}; //};
// test opening Food project // test opening Food project
this.test_open_project = [ test = newTest();
action("click", { link: "Food" } ), assert (test, "assertText", { jquery: '("h1")[0]', validator: "Welcome to Gridworks" });
action("waits.forPageLoad", { timeout: "20000" } ), this.test_home_page = test;
assert("gw_row_count", "7413" )
]; // make sure the dataset was loaded properly
test = newTest();
action (test, "click", { link: "Food" });
wait (test, "forPageLoad", { timeout: "20000" });
assert (test, "rowCount", "7413" );
this.test_open_project = test;
// create text facet from 1st word of Short Description column // create text facet from 1st word of Short Description column
this.test_create_text_facet = [ test = newTest();
action('click', { jquery: '(".column-header-layout tr:contains(\'Shrt_Desc\') .column-header-menu")[0]' } ), action (test, 'click', { jquery: '(".column-header-layout tr:contains(\'Shrt_Desc\') .column-header-menu")[0]' });
action('mouseOver', { jquery: '("td:contains(\'Facet\')")[0]' } ), action (test, 'mouseOver', { jquery: '("td:contains(\'Facet\')")[0]' });
action("gw_wait4menuitem", { name: 'Custom Text Facet' } ), wait (test, "forMenuItem", { name: 'Custom Text Facet' });
action("click", { jquery: '(".menu-item:contains(\'Custom Text Facet\')")[0]' } ), action (test, "click", { jquery: '(".menu-item:contains(\'Custom Text Facet\')")[0]' });
action("type", { jquery: '(".expression-preview-code")[0]', text: "value.split(',')[0]" } ), action (test, "type", { jquery: '(".expression-preview-code")[0]', text: "value.split(',')[0]" });
action("waits.forElement", { jquery: '("td:contains(\'value.split\')")[0]' } ), wait (test, "forElement", { jquery: '("td:contains(\'value.split\')")[0]' });
action("click", { jquery: '("button:contains(\'OK\')")[0]' } ), action (test, "click", { jquery: '("button:contains(\'OK\')")[0]' });
action("gw_wait4ajaxend"), //doesn't help yet, since ajax_in_progress isn't yet reliable wait (test, "forAjaxEnd");
action("waits.forElement", { jquery: '("a.facet-choice-label")[0]' } ), assert (test, "expectedTopFacetValue", "ABALONE");
assert("gw_expected_top_value","ABALONE") this.test_facet = test;
];
// sort the facet by count and test the result // sort the facet by count and test the result
this.test_sort_text_facet = [ test = newTest();
action("click", { jquery: '(".ui-button-text:contains(\'count\')")[0]' } ), action (test, "click", { jquery: '(".ui-button-text:contains(\'count\')")[0]' });
action("waits.forElement", { jquery: '(".ui-state-active .ui-button-text:contains(\'count\')")[0]' } ), //wait til count is the active sort wait (test, "forElement", { jquery: '(".ui-state-active .ui-button-text:contains(\'count\')")[0]' }); // wait til count is the active sort
assert("gw_expected_top_value","BEEF") assert (test, "expectedTopFacetValue", "BEEF");
]; this.test_sort_text_facet = test;
// filter down to BEEF // filter down to BEEF
this.test_fitler_text_facet = [ test = newTest();
action("click", { jquery: '("a.facet-choice-label")[0]' } ), action (test, "click", { jquery: '("a.facet-choice-label")[0]' });
action("waits.forElement", { jquery: '(".viewPanel-summary-row-count")[0]' } ), wait (test, "forElement", { jquery: '(".viewPanel-summary-row-count")[0]' });
assert("gw_row_count", "457") assert (test, "rowCount", "457");
]; this.test_fitler_text_facet = test;
// create numeric filter from Water column // create numeric filter from Water column
this.test_create_numeric_facet = [ test = newTest();
action("click", { jquery: '(".column-header-layout tr:contains(\'Water\') .column-header-menu")[0]' } ), action (test, "click", { jquery: '(".column-header-layout tr:contains(\'Water\') .column-header-menu")[0]' });
action('mouseOver', { jquery: '("td:contains(\'Facet\')")[0]' } ), action (test, "mouseOver", { jquery: '("td:contains(\'Facet\')")[0]' });
action("gw_wait4menuitem", { name: 'Numeric Facet' } ), wait (test, "forMenuItem", { name: 'Numeric Facet' });
action("click", { jquery: '(".menu-item:contains(\'Numeric Facet\')")[0]' } )//, action (test, "click", { jquery: '(".menu-item:contains(\'Numeric Facet\')")[0]' });
//TODO: (How) can I run a JSUnit assert w/in an object? // TODO: What to wait on, to know we're ready to do the following assert? Talk to dfhuynh.
//function () { jum.assertTrue( $(".facet-panel span:contains(\'Water\')").length ); } //assert (test, function() {
]; // jum.assertTrue($(".facet-panel span:contains(\'Water\')").length > 0);
//});
this.test_create_numeric_facet = test;
// filter out BEEF with lower water content // filter out BEEF with lower water content
this.test_filter_numeric_facet = [ test = newTest();
action("gw_wait4ajaxend"), wait (test, "forAjaxEnd");
action("waits.forElement", { jquery: '((".slider-widget-draggable.left"))[0]' } ), wait (test, "forElement", { jquery: '((".slider-widget-draggable.left"))[0]' }),
action("dragDropElem", { jquery: '((".slider-widget-draggable.left"))[0]', pixels: '150, 0' } )//, action (test, "dragDropElem", { jquery: '((".slider-widget-draggable.left"))[0]', pixels: '150, 0' });
// TODO: What to wait on, to know we're ready to do the following assert? Talk to dfhuynh. // TODO: What to wait on, to know we're ready to do the following assert? Talk to dfhuynh.
//assert("gw_row_count", "153") //assert (test, "rowCount", "153");
]; this.test_filter_numeric_facet = test;
}; };

View File

@ -1,48 +1,85 @@
var test = [];
function newTest() {
return [];
}
windmill.macros = {};
// ---------------------- actions extensions ---------------------------- // ---------------------- actions extensions ----------------------------
var actions = windmill.jsTest.actions; function action(test, what, params) {
if (typeof what == "function") {
function action(what,params) { test.push(what);
params = params || {}; } else if (what in windmill.macros.actions) {
return { windmill.macros.actions[what](params);
method : what, } else {
params : params test.push({
}; method: what,
params: params
});
}
} }
windmill.macros.actions = {};
actions.gw_wait4ajaxend = function () { windmill.macros.actions.clickColumnHeader = function (test,params) {
return action("waits.forElement", { jquery: '("body[ajax_in_progress=\'false\']")[0]' } ); action(test,"click", { jquery: '(".column-header-layout tr:contains("' + params.column_name + '") .column-header-menu")[0]'} );
}; };
actions.gw_wait4menuitem = function (params) { // ---------------------- wait extensions -------------------------------
return action("waits.forElement", { jquery: '(".menu-item:contains(\"' + params.name + '\")")[0]' } );
function wait(test, what, params) {
if (typeof what == "function") {
test.push(what);
} else if (what in windmill.macros.waits) {
windmill.macros.waits[what](test,params);
} else {
test.push({
method: "waits." + what,
params: params
});
}
}
windmill.macros.waits = {};
windmill.macros.waits.forAjaxEnd = function (test) {
wait(test,"forElement", { jquery: '("body[ajax_in_progress=\'false\']")[0]' } );
}; };
actions.gw_click_column_header = function (params) { windmill.macros.waits.forMenuItem = function (test,params) {
return action("click", { jquery: '(".column-header-layout tr:contains("' + params.column_name + '") .column-header-menu")[0]'} ); wait(test,"forElement", { jquery: '(".menu-item:contains(\'' + params.name + '\')")[0]' } );
}; };
// ---------------------- asserts extensions ---------------------------- // ---------------------- asserts extensions ----------------------------
var asserts = windmill.controller.asserts; function assert(test, what, params) {
if (typeof what == "function") {
function assert(what,params) { test.push(what);
return function() { } else if (what in windmill.macros.asserts) {
windmill.controller.asserts[what](params); windmill.macros.asserts[what](test,params);
}; } else {
test.push({
method: "asserts." + what,
params: params
});
}
} }
//TODO: is there a way to make the assert wait first, rather than putting this before each call of the assert?, windmill.macros.asserts = {};
asserts.gw_row_count = function (count) {
//action("waits.forElement", { jquery: '(".viewPanel-summary-row-count")[0]' } ); // doesn't work bc waits can't go inside functions windmill.macros.asserts.rowCount = function (test, count) {
asserts.assertText( { jquery: '(".viewPanel-summary-row-count")[0]', validator: count } ); wait(test,"forElement", { jquery: '(".viewPanel-summary-row-count")[0]' } );
assert(test,"assertText", { jquery: '(".viewPanel-summary-row-count")[0]', validator: count } );
}; };
asserts.gw_expected_top_value = function (expected_value) { windmill.macros.asserts.expectedTopFacetValue = function (test, expected_value) {
// action("waits.forElement", { jquery: '("a.facet-choice-label")[0]' } ); // doesn't work bc waits can't go inside functions wait(test, "forElement", { jquery: '("a.facet-choice-label")[0]' } );
asserts.assertEquals(expected_value, $.trim($("a.facet-choice-label")[0].text)); assert(test, function() {
jum.assertEquals(expected_value, $.trim($("a.facet-choice-label")[0].text));
});
}; };
// ----------------------- register tests --------------------------- // ----------------------- register tests ---------------------------