Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Initial commit

  • Loading branch information...
commit 08cff46de49545dd01a62c48fa336167e01a1760 0 parents
@nathanoehlman authored
2  .gitignore
@@ -0,0 +1,2 @@
+.DS_STORE
+node_modules
0  README
No changes.
37 app.js
@@ -0,0 +1,37 @@
+
+/**
+ * Module dependencies.
+ */
+
+var express = require('express')
+ , routes = require('./routes');
+
+var app = module.exports = express.createServer();
+
+// Configuration
+
+app.configure(function(){
+ app.set('views', __dirname + '/views');
+ app.set('view engine', 'jade');
+ app.use(express.bodyParser());
+ app.use(express.methodOverride());
+ app.use(app.router);
+ app.use(express.static(__dirname + '/public'));
+});
+
+app.configure('development', function(){
+ app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
+});
+
+app.configure('production', function(){
+ app.use(express.errorHandler());
+});
+
+// Routes
+
+app.get('/', routes.index);
+app.get('/authors', routes.authors);
+app.get('/books', routes.books);
+
+app.listen(3000);
+console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env);
14 package.json
@@ -0,0 +1,14 @@
+{
+ "name": "selenium-example",
+ "version": "0.0.1",
+ "private": true,
+ "dependencies": {
+ "express": "2.5.8",
+ "jade": ">= 0.0.1"
+ },
+ "devDependencies": {
+ "mocha": "*",
+ "chai": "*",
+ "webdriverjs": "*"
+ }
+}
8 public/stylesheets/style.css
@@ -0,0 +1,8 @@
+body {
+ padding: 50px;
+ font: 14px "Lucida Grande", Helvetica, Arial, sans-serif;
+}
+
+a {
+ color: #00B7FF;
+}
16 routes/index.js
@@ -0,0 +1,16 @@
+
+/*
+ * GET home page.
+ */
+
+exports.index = function(req, res){
+ res.render('index', { title: 'Library' })
+};
+
+exports.authors = function(req, res) {
+ res.render('authors', { title: 'Authors' })
+}
+
+exports.books = function(req, res) {
+ res.render('books', { title: 'Books' })
+}
62 tests/page_test.js
@@ -0,0 +1,62 @@
+var expect = require('chai').expect,
+ webdriverjs = require("webdriverjs"),
+ client = webdriverjs.remote();
+
+describe('Run Selenium tests', function() {
+
+ before(function(done) {
+ // Add some helper commands
+ client.addCommand('hasText', function(selector, text, callback) {
+ this.getText(selector, function(result) {
+ expect(result.value).to.have.string(text);
+ callback();
+ });
+ });
+ client.addCommand('waitUntilVisible', function(element, callback) {
+ var self = this;
+ function checkElement() {
+ self.isVisible(element, function(result) {
+ if (result === true) {
+ callback();
+ } else {
+ setTimeout(checkElement, 500);
+ }
+ });
+ }
+ checkElement();
+ });
+ done();
+ });
+
+ beforeEach(function(done) {
+ // Navigate to the URL for each test
+ client.init();
+ client.url('http://localhost:3000', done);
+ });
+
+ it('should be able to navigate betwen the pages', function(done) {
+ this.timeout(10000);
+ client
+ .hasText('#title', 'Library')
+ .click('#authors')
+ .waitUntilVisible("#authorList", function() {
+ client
+ .hasText('#author1', 'Patrick Rothfuss')
+ .click('#back')
+ .waitUntilVisible('#books', function() {
+ client
+ .click('#books')
+ .waitUntilVisible('#bookList', function() {
+ client.hasText('book1', "Wise Man's Fear");
+ done();
+ });
+ });
+ });
+ });
+
+ afterEach(function(done) {
+ client.end();
+ done();
+ });
+
+});
36 tests/simple_test.js
@@ -0,0 +1,36 @@
+var expect = require('chai').expect,
+ webdriverjs = require("webdriverjs"),
+ client = webdriverjs.remote();
+
+describe('Run Selenium tests', function() {
+
+ before(function(done) {
+ // Add some helper commands
+ client.addCommand('hasText', function(selector, text, callback) {
+ this.getText(selector, function(result) {
+ expect(result.value).to.have.string(text);
+ callback();
+ });
+ });
+ done();
+ });
+
+ beforeEach(function(done) {
+ // Navigate to the URL for each test
+ client.init();
+ client.url('http://localhost:3000', done);
+ });
+
+ it('should be able to view the home page', function(done) {
+ this.timeout(10000);
+ client.hasText('#title', 'Library');
+ done();
+
+ });
+
+ afterEach(function(done) {
+ client.end();
+ done();
+ });
+
+});
9 views/authors.jade
@@ -0,0 +1,9 @@
+h1#title= title
+
+ul#authorList
+ li#author1 Patrick Rothfuss
+ li#author2 William Shakespeare
+ li#author3 Eric Flint
+ li#author4 George Orwell
+
+a#back(href='/') Back
9 views/books.jade
@@ -0,0 +1,9 @@
+h1#title= title
+
+ul#bookList
+ li#book1 Wise Man's Fear
+ li#book2 Hamlet
+ li#book3 1632
+ li#book4 1984
+
+a#back(href='/') Back
7 views/index.jade
@@ -0,0 +1,7 @@
+h1#title= title
+p Welcome to the Library
+
+p
+ a#authors(href='/authors') Authors
+p
+ a#books(href='/books') Books
6 views/layout.jade
@@ -0,0 +1,6 @@
+!!!
+html
+ head
+ title= title
+ link(rel='stylesheet', href='/stylesheets/style.css')
+ body!= body
Please sign in to comment.
Something went wrong with that request. Please try again.