Giter Site home page Giter Site logo

manakel166 / node-robotremoteserver Goto Github PK

View Code? Open in Web Editor NEW

This project forked from comick/node-robotremoteserver

0.0 2.0 0.0 50 KB

A node.js module providing the robot framework remote library interface

License: MIT License

JavaScript 90.21% RobotFramework 9.79%

node-robotremoteserver's Introduction

robotremote

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 robotremote

Example

Just little example with main features. Test folder contains better extensive examples for more features.

examplelibrary.js:

'use strict';

var readdir = require('promise').denodeify(require('fs').readdir),
    robot = require('../lib/robotremote'),
    assert = require('assert');

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 readdir(path).then(function (files) {
        return files.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 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.
 *
 * Each keyword also have the output writer, which enables logging at various levels.
 * Here warn level is showed as an example.
 * All robot levels are supported including messages with timestamp through timestamp`Level` function.
 * See http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#logging-information
 *
 * @param str1
 * @param str2
 */
lib.stringsShouldBeEqual = function (str1, str2) {
    this.output.warn('Comparing \'%s\' to \'%s\'', str1, str2);
    assert.equal(str1, str2, 'Given strings are not equal');
};


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

remote_tests.robot:

*** 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}'

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.robot

Using botclient.js:

The botclient.js command line utility can be useful to test keywords of any compliant running robot remote server.

An example session with the example keywords library follows:

$ node ./bin/botclient.js localhost 8270
Connected to remote server at "localhost:8270"
Available keywords: stopRemoteServer, countItemsInDirectory, stringsShouldBeEqual
localhost:8270> keywords.countItemsInDirectory
{ [Function]
  args: [ 'path' ],
  docs: 'Returns the number of items in the directory specified by `path`.' }
localhost:8270> keywords.stringsShouldBeEqual
{ [Function]
  args: [ 'str1', 'str2' ],
  docs: '' }
localhost:8270> keywords.stringsShouldBeEqual('ciao', 'ciao').done(console.log)
undefined
localhost:8270> { output: '*WARN* Comparing \'ciao\' to \'ciao\'\n',
  status: 'PASS',
  return: '' }

Keywords are available in context in the keywords dictionary. When called they return an A+ promise.

License

Copyright (c) 2013, 2014, 2015, 2016 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.

node-robotremoteserver's People

Contributors

comick avatar

Watchers

 avatar  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.