Permalink
Browse files

Initial commit

  • Loading branch information...
0 parents commit 64681e153dc8bedecb6443e34433079997f59998 @sebv committed Apr 25, 2012
Showing with 470 additions and 0 deletions.
  1. +3 −0 .gitignore
  2. +58 −0 Cakefile
  3. +22 −0 LICENSE.txt
  4. +105 −0 README.markdown
  5. +1 −0 index.coffee
  6. +6 −0 index.js
  7. +39 −0 lib/soda-sync.coffee
  8. +67 −0 lib/soda-sync.js
  9. +22 −0 package.json
  10. +5 −0 test/mocha.opts
  11. +57 −0 test/soda-sync-test.coffee
  12. +85 −0 test/soda-sync-test.js
@@ -0,0 +1,3 @@
+node_modules
+.DS_Store
+workdir
@@ -0,0 +1,58 @@
+{execFile, spawn, exec} = require 'child_process'
+
+task 'compile', 'Compile All coffee files', ->
+ compileAll()
+
+task 'compile:watch', 'Compile All coffee files and watch for changes', ->
+ compileAll true
+
+task 'clean', 'Remove all js files', ->
+ cleanAllJs()
+
+task 'test', 'Run All tests', ->
+ testDir 'test'
+
+task 'grep:dirty', 'Lookup for debugger and console.log in code', ->
+ grepDirty()
+
+compileAll = (watch = false) ->
+ compileCoffee ['lib','test'], ['index.coffee'], watch
+
+cleanAllJs = ->
+ cleanJs ['lib','test'], ['index.js']
+
+compileCoffee = (dirs , files , watch = false) ->
+ params = ['--compile']
+ params.push('--watch') if watch
+ params = params.concat dirs
+ params = params.concat files
+ _spawn 'coffee', params
+
+testDir = (dir) ->
+ execFile 'find', [ dir ] , (err, stdout, stderr) ->
+ files = (stdout.split '\n').filter( (name) -> name.match /.+\-test.coffee/ )
+ params = ['-R', 'spec', '--colors'].concat files
+ _spawn 'mocha', params
+
+cleanJs = (dirs , files) ->
+ execFile 'find', dirs.concat(files) , (err, stdout, stderr) ->
+ _files = (stdout.split '\n').filter( (name) -> name.match /.+\.js/ )
+ _spawn 'rm', _files, false
+
+grepDirty = (dirs , word) ->
+ execFile 'find', [ '.' ] , (err, stdout, stderr) ->
+ files = (stdout.split '\n')\
+ .filter( (name) -> not name.match /\/node_modules\//)\
+ .filter( (name) -> not name.match /\/\.git\//)\
+ .filter( (name) ->
+ ( name.match /\.js$/) or
+ (name.match /\.coffee$/ ) )
+ _spawn 'grep', (['console.log'].concat files), false
+ _spawn 'grep', (['debugger'].concat files), false
+
+_spawn = (cmd,params,exitOnError=true) ->
+ proc = spawn cmd, params
+ proc.stdout.on 'data', (buffer) -> process.stdout.write buffer.toString()
+ proc.stderr.on 'data', (buffer) -> process.stderr.write buffer.toString()
+ proc.on 'exit', (status) ->
+ process.exit(1) if exitOnError and status != 0
@@ -0,0 +1,22 @@
+(The MIT License)
+
+Copyright (c) 2012 Seb Vincent
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+'Software'), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,105 @@
+# soda-sync
+
+Synchronous Version of the [soda](http://github.com/LearnBoost/soda.git)
+selenium client.
+
+The Selenium methods in the 'tested' list below work, most of others methods
+probably work, but as I am testing this as I am using it, they may be some
+bugs. If it the case please open an issue.
+
+
+## install
+
+```
+npm install soda-sync
+```
+
+
+## usage (coffeescript)
+
+
+```coffeescript
+{soda,Soda} = require '../lib/soda-sync'
+
+browser = soda.createClient(
+ host: "localhost"
+ port: 4444
+ url: "http://www.google.com"
+ browser: "firefox"
+ mode: 'sync'
+)
+
+Soda with:browser, ->
+ @session()
+ @open '/'
+ @type 'q', 'Hello World'
+ @click 'btnG'
+ @waitForElementPresent 'css=#topstuff'
+ title = @getTitle()
+ console.log "Got title=", title
+ @testComplete()
+```
+
+
+## to avoid repeating 'with: browser'
+
+
+```coffeescript
+{soda,Soda} = require '../lib/soda-sync'
+
+browser = soda.createClient(
+ host: "localhost"
+ port: 4444
+ url: "http://www.google.com"
+ browser: "firefox"
+ mode: 'sync'
+)
+Soda = Soda with:browser
+
+Soda ->
+ @session()
+ @open '/'
+
+Soda ->
+ @type 'q', 'Hello World'
+ @click 'btnG'
+
+Soda ->
+ @waitForElementPresent 'css=#topstuff'
+ title = @getTitle()
+ console.log "Got title=", title
+
+Soda ->
+ @testComplete()
+```
+
+
+## modes
+
+check [make-sync](http://github.com/sebv/node-make-sync) for more details.
+Probably best to use the 'sync' mode.
+
+```coffeescript
+mode: 'sync'
+mode: 'async'
+
+mode: ['mixed']
+mode: ['mixed','args']
+
+mode: ['mixed','fibers']
+```
+
+
+## tested
+
+soda
+ createClient
+
+browser
+ session
+ open
+ type
+ click
+ waitForElementPresent
+ getTitle
+ testComplete
@@ -0,0 +1 @@
+module.exports = require './lib/soda-sync'

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -0,0 +1,39 @@
+soda = require("soda")
+{MakeSync,Sync} = require 'make-sync'
+
+buildOptions = (mode) ->
+ mode = 'sync' if not mode?
+ {
+ mode: mode
+ exclude: ['enqueue','command','emit','commandPath']
+ }
+
+sodaSync =
+ createClient: (options) ->
+ browser = soda.createClient options
+ if(options?.mode?)
+ MakeSync browser, (buildOptions options.mode)
+ browser.queue = null # necessary cause soda is doing weird stuff
+ browser # in the 'chain' getter
+
+cleanArgs = (ctx, cb) ->
+ if typeof ctx is 'function'
+ cb = ctx
+ ctx = null
+ ctx = ctx?.with if ctx?.with?
+ [ctx,cb]
+
+Soda = (ctx, cb) ->
+ [ctx,cb] = cleanArgs ctx, cb
+ if cb? then Sync ->
+ cb.apply ctx, []
+ if ctx
+ # we return another function preconfigured for this browser
+ (ctx2, cb2) ->
+ debugger
+ [ctx2,cb2] = cleanArgs ctx2, cb2
+ ctx2 = ctx if not ctx2?
+ Soda ctx2, cb2
+
+exports.Soda = Soda
+exports.soda = sodaSync

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -0,0 +1,22 @@
+{
+ "name": "soda-sync"
+ , "version": "0.0.1"
+ , "description": "sync version of soda using fibers to write good looking test"
+ , "keywords": ["selenium","soda","test","fibers", "sync",""]
+ , "author": "Seb Vincent <seb.vincent@gmail.com>"
+ , "---repository": { "type": "git", "url": "git@github.com:sebv/node-make-sync.git" }
+ , "main": "./index"
+ , "engine": "node >= 0.6.1"
+ , "scripts": {
+ "test": "cake test"
+ }
+ , "dependencies": {
+ "soda": "latest",
+ "make-sync": "latest"
+ }
+ , "devDependencies" : {
+ "coffee-script" : "latest"
+ , "mocha" : "latest"
+ , "should": "latest"
+ }
+}
@@ -0,0 +1,5 @@
+--compilers coffee:coffee-script
+--ui bdd
+--reporter spec
+-t 20000
+--bail
@@ -0,0 +1,57 @@
+should = require 'should'
+{soda,Soda} = require '../lib/soda-sync'
+
+describe "soda-sync", ->
+ browser = null;
+ it "create client", (done) ->
+ browser = soda.createClient (
+ host: "localhost"
+ port: 4444
+ url: "http://www.google.com"
+ browser: "firefox"
+ mode: 'sync'
+ )
+ Soda = Soda with:browser
+ done()
+
+ describe "step by step run", ->
+ it "open session", (done) ->
+ Soda ->
+ @session()
+ done()
+ it "opens page", (done) ->
+ Soda ->
+ @open '/'
+ done()
+ it "types something", (done) ->
+ Soda ->
+ @type 'q', 'Hello World'
+ done()
+ it "clicks button", (done) ->
+ Soda ->
+ @click 'btnG'
+ done()
+ it "waits", (done) ->
+ Soda ->
+ @waitForElementPresent 'css=#topstuff'
+ done()
+ it "checks title", (done) ->
+ Soda ->
+ @getTitle().toLowerCase().should.include 'hello world'
+ done()
+ it "finishes test", (done) ->
+ Soda ->
+ @testComplete()
+ done()
+
+ describe "all at once", ->
+ it "should work", (done) ->
+ Soda ->
+ @session()
+ @open '/'
+ @type 'q', 'Hello World'
+ @click 'btnG'
+ @waitForElementPresent 'css=#topstuff'
+ @getTitle().toLowerCase().should.include 'hello world'
+ @testComplete()
+ done()
Oops, something went wrong.

0 comments on commit 64681e1

Please sign in to comment.