Giter Club home page Giter Club logo

botremote's Introduction

botremote

NPM NPM

Build Status

A node.js module providing the robot framework remote library interface. Also provide convenient remote library interface client.

Installation

Install robot framework first. Then:

$ npm install botremote

Example

examplelibrary.js:

'use strict';

var fs = require('promised-io/fs'),
    assert = require('assert'),
    Return = require('../lib/botremote').Return,
    Logger = require('../lib/botremote').Logger;

var lib = module.exports;

/**
 * Example of asynchronous keyword.
 *
 * You can implement asynchronous keywords just returning an A+ promise.
 * Promise can be resolved or rejected with respectively:
 *
 * - arbitrary return value, or
 * - an instance of `Error` if the keyword failed
 *
 * Just count items in given directory.
 *
 * @param path directory path to count item in.
 */
lib.countItemsInDirectory = function (path) {
    return fs.readdir(path).then(function (items) {
        return items.length;
    });
};
// The doc attribute is used for inspection on the command line of client and doc generation.
// It's optional and defaults to empty string when missing.
lib.countItemsInDirectory.doc = 'Returns the number of items in the directory specified by `path`.';

/**
 * Example of asynchronous keyword with log output.
 *
 * You can implement asynchronous keywords just returning an A+ promise.
 * Promise can be resolved or rejected with respectively:
 *
 * - {Return} Return value consists of return value as the first param and output log as the second param.
 * - arbitrary return value, or
 * - an instance of `Error` if the keyword failed
 *
 * Just count items in given directory.
 *
 * @param path directory path to count item in with output log in robot log.
 */
lib.countItemsInDirectoryWithOutput = function (path) {
    var logger = new Logger();
    logger.info('Start to read directory from path[%s].', path);
    return fs.readdir(path).then(
        function (items) {
            logger.debug('The items: [%s].', items.toString());
            return new Return(items.length, logger.getMsg());
        });
};
// The doc attribute is used for inspection on the command line of client and doc generation.
// It's optional and defaults to empty string when missing.
lib.countItemsInDirectoryWithOutput.doc = 'Returns the number of items in the directory specified by `path` with log output.';

/**
 * Example synchronous keyword.
 *
 * Any keyword which does not return an A+ promise is considered sync.
 * The following are considered successes:
 *
 * - the keyword returns `undefined` (that is doesn't return any value)
 * - the keyword return any other value
 *
 * While any thrown `Error` instance will lead the keyword failure.
 *
 * @param str1
 * @param str2
 */
lib.stringsShouldBeEqual = function (str1, str2) {
    console.log('Comparing \'%s\' to \'%s\'', str1, str2);
    assert.equal(str1, str2, 'Given strings are not equal');
};

/**
 *
 * Example of fail case with log output
 *
 * @returns {Return}
 */
lib.awfulKeyword = function () {
    var logger = new Logger();
    logger.info('Enter awful keyword.');
    logger.warn('Awful thing is going to happen.');
    return new Return('Awful return value', logger.getMsg(), new Error('Error happens because this is an awful keyword'));
};
lib.awfulKeyword.doc = 'This keyword will cause some terrible thing happen, please use this keyword carefully.';


// Run this keyword library if the library itself is called explicitly.
if (!module.parent) {
    var robot = require('../lib/botremote');
    var server = new robot.Server([lib], { host: 'localhost', port: 8270, allowStop: true });
}

remote_tests.txt:

*** Settings ***
Library    Remote    http://localhost:${PORT}

*** Variables ***
${HOST}    localhost
${PORT}    8270

*** Test Cases ***

Count Items in Directory
    ${items1} =    Count Items In Directory    ${CURDIR}
    ${items2} =    Count Items In Directory    ${TEMPDIR}
    Log    ${items1} items in '${CURDIR}' and ${items2} items in '${TEMPDIR}'

Count Items in Directory With Output
    ${items1} =    Count Items In Directory With Output    ${CURDIR}
    ${items2} =    Count Items In Directory With Output    ${TEMPDIR}
    Log    ${items1} items in '${CURDIR}' and ${items2} items in '${TEMPDIR}'

Do Awful Things
    Awful Keyword

Failing Example
    Strings Should Be Equal    Hello    Hello
    Strings Should Be Equal    not      equal

Run the remote server:

$ node example/examplelibrary.js

Then launch tests:

$ pybot example/remote_tests.txt

Using the client

The client is useful for testing keywords from the REPL:

> var lib = new require('./lib/botremote').Client({ host: 'localhost', port: 8270 })
> lib.stringsShouldBeEqual
{ [Function]
  args: [ 'str1', 'str2' ],
  docs: '' }
> lib.countItemsInDirectory
{ [Function]
  args: [ 'path' ],
  docs: 'Returns the number of items in the directory specified by `path`.' }
> lib.countItemsInDirectory(process.cwd(), function(e, v) { console.log(v) })
undefined
> { status: 'PASS',
  output: '',
  traceback: '',
  return: 14,
  error: '' }
> lib.stringsShouldBeEqual('bau', 'miao', function(e, v) { console.log(v) })
undefined
> { status: 'FAIL',
  output: '',
  traceback: 'AssertionError: Given strings are not equal\n    at Server.lib.stringsShouldBeEqual (/home/michele/sviluppo/node-robotremoteserver/example/examplelibrary.js:46:12)\n    at Server.runKeyword (/home/michele/sviluppo/node-robotremoteserver/lib/robotremote.js:112:26)\n    at Server.<anonymous> (/home/michele/sviluppo/node-robotremoteserver/lib/robotremote.js:43:21)\n    at Server.EventEmitter.emit (events.js:106:17)\n    at /home/michele/sviluppo/node-robotremoteserver/node_modules/xmlrpc/lib/server.js:42:14\n    at callback (/home/michele/sviluppo/node-robotremoteserver/node_modules/xmlrpc/lib/deserializer.js:65:7)\n    at Deserializer.onDone (/home/michele/sviluppo/node-robotremoteserver/node_modules/xmlrpc/lib/deserializer.js:92:12)\n    at SAXStream.EventEmitter.emit (events.js:92:17)\n    at Object.SAXStream._parser.onend (/home/michele/sviluppo/node-robotremoteserver/node_modules/xmlrpc/node_modules/sax/lib/sax.js:171:8)\n    at emit (/home/michele/sviluppo/node-robotremoteserver/node_modules/xmlrpc/node_modules/sax/lib/sax.js:325:33)',
  return: '',
  error: 'AssertionError: Given strings are not equal' }
>

License

Copyright (c) 2013, 2014 Michele Comignano [email protected]

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.

botremote's People

Contributors

akwangho avatar comick avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.