node-soda-sync
Note: API change in version 1.0.0, see below.
A synchronous version of soda using node-fibers.
Remote testing with Sauce Labs also works.
install
npm install soda-sync
usage (coffeescript)
# Assumes that the selenium server is running sodaSync = require 'soda-sync' sodaSynccreateClient host: "localhost" port: 4444 url: "http://www.google.com" browser: "firefox" sync -> @session @open '/' @type 'q''Hello World' @click 'btnG' @waitForElementPresent 'css=#topstuff' title = @getTitle consolelog "Got title="title @testComplete
All the methods from soda / Selenium are available.
The browser methods must be called within a sync block which holds the fiber environment. The sync block context is set to the Soda browser so that the browser methods may be accessed using '@'.
upgrade to V1
API was simplified below are the main changes:
- 1/ require:
sodaSync = require 'soda-sync'
- 2/ createClient:
{browser,sync} = sodaSync.createClient(...
- 3/ Soda becomes sync
- 4/ SodaCan becomes can (see can section below)
- 5/ mode options have been disabled.
Sauce Labs example
Remote testing with Sauce Labs, works the same as with soda.
sodaSync = require 'soda-sync' # configure your sauce account here username = '<USERNAME>'access_key = '<ACCESS-KEY>' sodaSynccreateSauceClient url: "http://www.google.com" username: username "access-key": access_key os: "Linux" browser: "firefox" "browser-version": "3." "max-duration": 300 name: "soda-sync sauce example"browseron 'command' consolelog ' \x1b[33m%s\x1b[0m: %s'cmdargsjoin', ' sync -> @session @open '/' @type 'q''Hello World' @click 'btnG' @waitForElementPresent 'css=#topstuff' consolelog @getTitle browsersetContext "sauce:job-info={\"passed\": true}" @testComplete consolelog browserjobUrl
Soda can
can is a wrapper around Soda, making it easy to integrate with test frameworks.
The example below is using the mocha test framework. The 'done' callback is managed within the Soda can.
The 'with' parameter is a function returning the browser evaluated each time the block is opened.
'pre' methods may be specified globally or locally. They are called before the can block starts, without switching context (In Mocha, it can be used to configure timeouts).
# Assumes that the selenium server is running should = require 'should'sodaSync = require 'soda-sync' describe "can"-> browser = null can = sodaSynccan : -> browser : -> @timeout 60000 # optional global pre it "create client" sodaSynccreateClient host: "localhost" port: 4444 url: "http://www.google.com" browser: "firefox" done describe "can without pre"-> it "should work"can -> @session @open '/' @getTitletoLowerCaseshouldinclude 'google' @testComplete describe "can with pre"-> it "should work"can : -> @timeout 30000 # local pre -> @session @open '/' @getTitletoLowerCaseshouldinclude 'google' @testComplete
to retrieve the browser currently in use
The current browser is automatically stored in the Fiber context. It can be retrieved with the soda.current() function.
This is useful when writing test helpers.
# Assumes that the selenium server is running sodaSync = require 'soda-sync' sodaSynccreateClient host: "localhost" port: 4444 url: "http://www.google.com" browser: "firefox" = -> sodaSynccurrentopen '/' sync -> @session openRoot @testComplete
JavaScript
This module is designed with CoffeeScript in mind, but you could
initialize browser and sync like in the following example, then use browser
or this
instead of @
in the sync/can blocks:
var sodaSync = ;var client = sodaSync browser = clientbrowser sync = clientsync;
Selenium server
Download the Selenium server here.
To start the server:
java -jar selenium-server.jar