Skip to content
This repository has been archived by the owner on May 1, 2020. It is now read-only.

Commit

Permalink
Add support for Taxi
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelerz committed May 15, 2015
1 parent 2b7f762 commit 43512c7
Show file tree
Hide file tree
Showing 4 changed files with 152 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ v0.10.1
* Add support for Node 0.12
* Add support for IO.js
* Add support for css selectors for getElement/getElements/hasElement as fall-back
* Add support for Taxi

v0.10.0 - 02/24/15
* Add getElements method to base page-object
Expand Down
25 changes: 15 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,17 @@ var hodman = require('hodman');
The following example sets-up the page-object system and creates an example page-object for a login page.

```javascript
var cabbie = require('cabbie');
var taxi = require('taxi');
var hodman = require('hodman');

// Initialize the selenium client. In this case, it is "cabbie".
var driver = cabbie('http://127.0.0.1:4444/wd/hub',
// Initialize the selenium client. In this case, it is "taxi".
var driver = taxi('http://127.0.0.1:4444/wd/hub',
{ browserName: 'firefox' }, // With firefox
{ mode: cabbie.MODE_SYNC }); // In sync-mode
{ mode: taxi.MODE_SYNC }); // In sync-mode

// Create driver-adapter for the page-objects to have a consistent interface
// for all supported selenium clients.
var driverAdapter = new hodman.driverAdapters.Cabbie(driver);
var driverAdapter = new hodman.driverAdapters.Taxi(driver);

// Assign the driver-adapter to the page-object sub-system
hodman.BaseObject.DRIVER_ADAPTER = driverAdapter;
Expand Down Expand Up @@ -547,19 +547,20 @@ I am in good company with this since Jason Huggins, the creator of Selenium and
The driver-adapter will give the page-objects a consistent way of accessing low-level Selenium elements and functions.

The following adapters for Selenium clients are available:
* ```cabbie``` (https://github.com/ForbesLindesay/cabbie)
* ```taxi``` (https://github.com/preceptorjs/taxi)
* ```cabbie``` (https://github.com/ForbesLindesay/taxi / https://github.com/marcelerz/cabbie)

Hodman exposes all standard driver-adapter with ```hodman.driverAdapters```:

```javascript
var cabbie = require('cabbie');
var taxi = require('taxi');
var hodman = require('hodman');

var driver = cabbie('http://127.0.0.1:4444/wd/hub',
var driver = taxi('http://127.0.0.1:4444/wd/hub',
{ browserName: 'firefox' }, // With firefox
{ mode: cabbie.MODE_SYNC }); // In sync-mode
{ mode: taxi.MODE_SYNC }); // In sync-mode

var driverAdapter = new hodman.driverAdapters.Cabbie(driver);
var driverAdapter = new hodman.driverAdapters.Taxi(driver);
```

Should your favorite Selenium client not be available, then please request it in the issues tab or implement your own adapter by using the exposed abstract ```DriverAdapter``` object as base-class:
Expand Down Expand Up @@ -622,6 +623,10 @@ The following third-party libraries are used by this module:
* mocha: https://github.com/visionmedia/mocha
* yuidocjs: https://github.com/yui/yuidoc
###Optional-Dependecies:
* taxi: https://github.com/preceptorjs/taxi
* cabbie-alpha: https://github.com/ForbesLindesay/cabbie / https://github.com/marcelerz/cabbie
##License
The MIT License
Expand Down
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ module.exports = {
// Driver-adapters
DriverAdapter: require('./lib/driverAdapter/driverAdapter'),
driverAdapters: {
"Cabbie": require('./lib/driverAdapter/cabbieAdapter')
"Cabbie": require('./lib/driverAdapter/cabbieAdapter'),
"Taxi": require('./lib/driverAdapter/taxiAdapter')
},

// Page-Objects
Expand Down
134 changes: 134 additions & 0 deletions lib/driverAdapter/taxiAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
// Copyright 2014-2015, Yahoo! Inc.
// Copyrights licensed under the Mit License. See the accompanying LICENSE file for terms.

var sleep = require('sleep.js');

var DriverAdapter = require('./driverAdapter');

/**
* @class TaxiAdapter
* @extends DriverAdapter
*/
var TaxiAdapter = DriverAdapter.extend(

{
/**
* Initializes the driver-adapter
*
* @method initialize
*/
initialize: function () {
// Nothing by default
},


/**
* Get the driver
*
* @method getDriver
* @return {Browser}
*/
getDriver: function () {
return this.driver;
},


/**
* Gets the current url of the session window
*
* @method getCurrentUrl
* @return {string}
*/
getCurrentUrl: function () {
return this.getPageContext().navigator().getUrl();
},

/**
* Gets the current page context
*
* @method getPageContext
* @return {Element}
*/
getPageContext: function () {
return this.getDriver().browser().activeWindow();
},

/**
* Navigates to the supplied url
*
* @method navigateTo
* @param {string} url
*/
navigateTo: function (url) {
return this.getPageContext().navigator().navigateTo(url);
},

/**
* Number of milliseconds to wait before moving on
*
* @method sleep
* @param {int} waitInMs
*/
sleep: function (waitInMs) {
return sleep(waitInMs);
},

/**
* Takes a screenshot of the current session window
*
* @method takeScreenshot
* @return {Buffer}
*/
takeScreenshot: function () {
return this.getPageContext().takeScreenshot();
},

/**
* Executes JavaScript code
*
* @method executeScript
* @param {string} code
* @param {string[]} [args]
* @return {*}
*/
executeScript: function (code, args) {
return this.getPageContext().execute(code, args);
},

/**
* Gets the first element that applies to the supplied selector with the selector-type
*
* @method getElement
* @param {object} context
* @param {string} selector
* @param {string} [selectorType='css selector']
* @return {Element}
*/
getElement: function (context, selector, selectorType) {
return context.getElement(selector, selectorType);
},

/**
* Gets all elements that apply to the supplied selector with the selector-type
*
* @method getElements
* @param {object} context
* @param {string} selector
* @param {string} [selectorType='css selector']
* @return {Element[]}
*/
getElements: function (context, selector, selectorType) {
return context.getElements(selector, selectorType);
}
},

{
/**
* @property TYPE
* @type {string}
* @static
*/
TYPE: 'TaxiAdapter'
});

module.exports = TaxiAdapter;

0 comments on commit 43512c7

Please sign in to comment.