discourse/spec/phantom_js/smoke_test.js

139 lines
2.9 KiB
JavaScript
Raw Normal View History

/*global phantom:true */
2013-02-20 20:07:22 -05:00
console.log('Starting Smoke Test');
var system = require('system');
if(system.args.length !== 2) {
console.log("expecting phantomjs {smoke_test.js} {base_url}");
phantom.exit(1);
}
var page = require('webpage').create();
2013-02-21 00:01:18 -05:00
page.waitFor = function(desc, fn, timeout, after) {
2013-02-20 20:07:22 -05:00
var check,start,promise;
start = +new Date();
promise = {};
check = function() {
var r;
try {
r = page.evaluate(fn);
}
2013-02-20 20:07:22 -05:00
catch(err) {
// next time
}
2013-02-21 00:01:18 -05:00
var diff = (+new Date()) - start;
2013-02-20 20:07:22 -05:00
if(r) {
2013-02-21 00:01:18 -05:00
console.log("PASSED: " + desc + " " + diff + "ms" );
after(true);
2013-02-20 20:07:22 -05:00
} else {
2013-02-21 00:01:18 -05:00
if(diff > timeout) {
console.log("FAILED: " + desc + " " + diff + "ms");
after(false);
2013-02-20 20:07:22 -05:00
} else {
setTimeout(check, 50);
}
}
};
check();
};
2013-02-21 00:01:18 -05:00
var actions = [];
var test = function(desc, fn) {
actions.push({test: fn, desc: desc});
};
var navigate = function(desc, fn) {
actions.push({navigate: fn, desc: desc});
};
var run = function(){
var allPassed = true;
var done = function() {
if(allPassed) {
console.log("ALL PASSED");
2013-02-20 20:07:22 -05:00
} else {
2013-02-21 00:01:18 -05:00
console.log("SMOKE TEST FAILED");
2013-02-20 20:07:22 -05:00
}
2013-02-21 00:01:18 -05:00
phantom.exit();
2013-02-20 20:07:22 -05:00
};
2013-02-21 00:01:18 -05:00
var performNextAction = function(){
if(actions.length === 0) {
done();
}
else{
var action = actions[0];
actions = actions.splice(1);
if(action.test) {
page.waitFor(action.desc, action.test, 10000, function(success){
allPassed = allPassed && success;
performNextAction();
});
}
2013-02-21 00:01:18 -05:00
else if(action.navigate) {
console.log("NAVIGATE: " + action.desc);
page.evaluate(action.navigate);
performNextAction();
}
}
};
performNextAction();
};
2013-02-20 20:07:22 -05:00
2013-02-21 00:01:18 -05:00
page.runTests = function(){
2013-02-20 20:07:22 -05:00
test("at least one topic shows up", function() {
return $('.topic-list tbody tr').length > 0;
2013-02-21 00:01:18 -05:00
});
test("expect a log in button", function(){
return $('.login-button').text().trim() === 'Log In';
2013-02-21 00:01:18 -05:00
});
navigate("navigate to first topic", function(){
2013-02-21 00:37:17 -05:00
Em.run.later(function(){
2014-04-10 02:57:23 -04:00
if ($('.main-link > a:first').length > 0) {
$('.main-link > a:first').click(); // topic list page
} else {
$('.featured-topic a.title:first').click(); // categories page
}
2013-02-21 00:37:17 -05:00
}, 500);
2013-02-21 00:01:18 -05:00
});
test("at least one post body", function(){
return $('.topic-post').length > 0;
2013-02-21 00:01:18 -05:00
});
2013-02-21 00:01:18 -05:00
navigate("navigate to first user", function(){
2013-02-21 00:37:17 -05:00
// for whatever reason the clicks do not respond at the begining
// defering
Em.run.later(function(){
// Remove the popup action for testing
$('.topic-meta-data a:first').data('ember-action', '');
$('.topic-meta-data a:first').focus().click();
2013-02-21 00:37:17 -05:00
},500);
2013-02-21 00:01:18 -05:00
});
2013-10-16 16:01:41 -04:00
test("has details",function(){
return $('#poster-expansion .names').length === 1;
2013-02-21 00:01:18 -05:00
});
run();
};
page.open(system.args[1], function (status) {
console.log("Opened " + system.args[1]);
page.runTests();
2013-02-20 20:07:22 -05:00
});