forked from freeciv/freeciv-web
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add automatic Javascript testing of Freeciv-web using CasperJS and Sl…
…imerJS.
- Loading branch information
1 parent
79899c0
commit dcb6337
Showing
3 changed files
with
207 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
/********************************************************************** | ||
CasperJS tests for Freeciv-web. | ||
***********************************************************************/ | ||
|
||
|
||
casper.test.begin('Test of Resin running on localhost port 8080.', 2, function suite(test) { | ||
casper.start("http://localhost:8080/", function() { | ||
test.assertHttpStatus(200); | ||
test.assertTitleMatch(/Freeciv-web/, 'Freeciv-web title is present'); | ||
}); | ||
|
||
casper.run(function() { | ||
test.done(); | ||
}); | ||
}); | ||
|
||
|
||
casper.test.begin('Test of Freeciv-proxy on port 7001.', 2, function suite(test) { | ||
casper.start("http://localhost:7001/status", function() { | ||
test.assertHttpStatus(200); | ||
test.assertTextExists('Freeciv WebSocket Proxy Status', | ||
'Test that Freeciv-proxy contains expected text.'); | ||
}); | ||
|
||
casper.run(function() { | ||
test.done(); | ||
}); | ||
}); | ||
|
||
|
||
casper.test.begin('Test of Freeciv-web frontpage on localhost port 80 (nginx).', 3, function suite(test) { | ||
casper.start("http://localhost", function() { | ||
test.assertHttpStatus(200); | ||
test.assertTitleMatch(/Freeciv-web/, 'Freeciv-web title is present'); | ||
test.assertExists('#single-button'); | ||
}); | ||
|
||
casper.run(function() { | ||
test.done(); | ||
}); | ||
}); | ||
|
||
casper.test.begin('Test that Metaserver is responding.', 2, function suite(test) { | ||
casper.start("http://localhost/meta/metaserver.php", function() { | ||
test.assertHttpStatus(200); | ||
test.assertTextExists('Freeciv-web Single-player games', | ||
'Test that Metaserver contains expected text.'); | ||
}); | ||
|
||
casper.run(function() { | ||
test.done(); | ||
}); | ||
}); | ||
|
||
|
||
casper.test.begin('Test of Freeciv-web frontpage', 3, function suite(test) { | ||
casper.start("http://localhost", function() { | ||
test.assertHttpStatus(200); | ||
test.assertTitleMatch(/Freeciv-web/, 'Freeciv-web title is present'); | ||
test.assertExists('#single-button'); | ||
}); | ||
|
||
casper.run(function() { | ||
test.done(); | ||
}); | ||
}); | ||
|
||
casper.test.begin('Test starting new Freeciv-web game', 10, function suite(test) { | ||
casper.start("http://localhost/webclient/?action=new", function() { | ||
test.assertHttpStatus(200); | ||
test.assertTitleMatch(/Freeciv-web/, 'Freeciv-web title is present'); | ||
test.assertExists('#username_req'); | ||
this.echo("Captured screenshot to be saved as screenshot-1.png"); | ||
this.capture('../../screenshot-1.png', undefined, { | ||
format: 'png', | ||
quality: 100 | ||
}); | ||
|
||
}); | ||
|
||
casper.then(function() { | ||
this.echo("Filling in username in new game dialog."); | ||
this.sendKeys('#username_req', 'CasperJS'); | ||
}); | ||
|
||
casper.thenEvaluate(function() { | ||
/* Starting new game automatically from Javascript.*/ | ||
if (validate_username()) { | ||
$("#dialog").dialog('close'); | ||
setTimeout("pregame_start_game();", 700); | ||
} | ||
}); | ||
|
||
casper.waitForText("Ok", function() { | ||
this.echo("Clicking Ok in Intro dialog."); | ||
this.clickLabel('Ok'); | ||
this.echo("Captured screenshot to be saved as screenshot-2.png"); | ||
this.capture('../../screenshot-2.png', undefined, { | ||
format: 'png', | ||
quality: 100 | ||
}); | ||
}); | ||
|
||
casper.then(function() { | ||
this.echo("Checking that JavaScript objects in browser memory are as expected."); | ||
|
||
test.assertEval(function() { | ||
return tileset['u.settlers'].length == 5 && tileset['f.shield.england'].length == 5; | ||
}, "Checks that tileset contains settlers and english flag."); | ||
|
||
test.assertEval(function() { | ||
return map['xsize'] > 0 | ||
&& map['ysize'] > 0 | ||
&& tiles[5]['x'] >= 0 | ||
&& tiles[5]['y'] >= 0 | ||
&& tiles[5]['terrain'] != null; | ||
}, "Checks properties of map and tiles."); | ||
|
||
|
||
test.assertEval(function() { | ||
return techs[1] != null | ||
&& techs[1]['name'] != null | ||
&& techs[1]['name'].length > 0 | ||
&& techs[1]['num_reqs'] > 0 | ||
&& techs[1]['req'].length == 2 | ||
&& techs[1]['req'][0] > 0 | ||
&& techs[1]['req'][1] > 0; | ||
}, "Checks some properties of the tech object."); | ||
|
||
test.assertEval(function() { | ||
return players[0] != null && players[0]['name'].length > 0 | ||
&& players[0]['username'].length > 0 | ||
&& players[0]['playerno'] >= 0 | ||
&& nations[players[0]['nation']] | ||
&& players[0]['love'].length > 0 | ||
&& players[0]['is_ready'] == true | ||
}, "Checks some properties of the player object."); | ||
|
||
test.assertEval(function() { | ||
return game_info['turn'] == 0 | ||
&& game_info['year'] == -4000 | ||
&& game_info['timeout'] == 0 | ||
&& game_info['gold'] > 0 | ||
&& game_info['aifill'] > 0 | ||
&& game_info['mapsize'] > 0; | ||
}, "Checks some properties of the game_info object."); | ||
|
||
test.assertEval(function() { | ||
return unit_types[0]['name'].length > 0 | ||
&& unit_types[0]['helptext'].length > 0 | ||
&& unit_types[0]['graphic_str'].length > 0 | ||
}, "Checks some properties of the unit_types object."); | ||
|
||
|
||
test.assertEval(function() { | ||
return nations[0]['adjective'].length > 0 | ||
&& nations[0]['graphic_str'].length > 0; | ||
}, "Checks some properties of the nations object."); | ||
|
||
}); | ||
|
||
casper.run(function() { | ||
this.echo("Tests are run successfully!"); | ||
test.done(); | ||
}); | ||
}); |