Coder Social home page Coder Social logo

k3po.js's Introduction

Build Status Sauce Test Status

Sauce Test Status

K3PO for JavaScript

k3po.js is used to run K3po Scripts against JavaScript libraries in both the browser and node modules.

It consists of

  1. Control Transport Factory which provides communication protocol for contacting k3po driver
  2. Control.js, a k3po control protocol that is used by talk to the K3po Driver via a Transport that provides an API for starting/stopping k3po scripts
  3. BrowserRunner, which provides a mechanism for running javascript test functions in a browser
  4. mocha-k3po.js, a mocha plugin that can control k3po scripts as part of the test framework, and run them in browser or locally via configuration

The K3po driver is launched prior to tests via grunt-k3po plugin

Examples

Test code is written using a mocha extension

![overview](https://raw.github.com/k3po/k3po.js/develop/design.jpg)


### Building

1. install grunt-k3po plugin (needed as it is not officiall released yet).  `npm install <directory of grunt-plugin>`
=======
var chai = require('chai');
var WebSocket = require('websocket').w3cwebsocket;

describe('WsClient', function () {

    // configure k3po settings, such as script root on where to load scripts
    k3poConfig.scriptRoot('org/kaazing/specification/utils');
    
    // configure browser settings, such as origin, and resource libraries to load, here it
    // is chai, which is used as an assert in the test
    browserConfig.origin('http://localhost:8080').addResource("http://chaijs.com/chai.js");

    // everything inside function will be executed in the runtime environment, which can be a browser
    it('full.feature.test/server', function (done) {

        var echoText = "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345";
        var ws = new WebSocket("ws://localhost:8080/echo");
        ws.onopen = function () {
            k3po.notify("CLIENT_READY_TO_READ");
            k3po.await("SERVER_READY_TO_READ").then(function () {
                ws.send(echoText);
            });
        };

        ws.onmessage = function (event) {
            chai.assert.equal(event.data, echoText);
            ws.close();
        };

        ws.onclose = ws.onerror = function () {
            done();
        };
    });
}

Configuration via Grunt

// configure k3po driver to run prior to tests
  k3po: {
      start: {
          options: {
              goal: "start"
          }
      },
      stop: {
          options: {
              goal: "stop"
          }
      },
      daemon: {
          options: {
              goal: "start",
              daemon: false
          }
      }
  },
  
  // configure mocha to run using mocka-k3po extension
  
  mochaTest: {
  
  // configure to run in node
  testMochaK3po: {
    options: {
            reporter: 'spec',
            ui: 'mocha-k3po',
            require: 'lib/testFrameworks/mocha-k3po.js',
            captureFile: "build/testMochaK3po.txt"
        },
        src: ['test/testFrameworks/mocha-k3po*.js']
    },
    
  // configure to run in browser
    testMochaK3poBrowserSupport: {
        options: {
            reporter: 'spec',
            ui: 'mocha-k3po',
            require: 'lib/testFrameworks/mocha-k3po.js',
            captureFile: "build/testMochaK3po.txt",
            browser: {
                desiredCapabilities: {
                    // browser capabilities are documented at http://webdriver.io/
                    browserName: 'firefox'
                }
            }
        },
        src: ['test/testFrameworks/mocha-k3po*.js']
    }
  }
  
  // Note: due to mocha bug, tests can't be ran twice in a row via grunt due to global state that is not cleaned, 
  // so you will need multiple grunt profiles
    grunt.registerTask('default', ['k3po:start', 'mochaTest:testMochaK3po']);
    grunt.registerTask('firefox', ['k3po:start', 'mochaTest:testMochaK3poBrowserSupport']);

Building

  1. npm install
  2. grunt

Debugging the browser

By default the browser closes after the test, in case of test failures you can pass the debug flag to the browser configuration as shown to keep it open. This allows access to the browser javascript console.

browser: {
    desiredCapabilities: {
        browserName: 'firefox'
    },
    debug: true
}

k3po.js's People

Contributors

dpwspoon avatar tmontgomery avatar

Stargazers

 avatar

Watchers

Robin Zimmermann avatar James Cloos avatar Peter Moskovits avatar Akram  Yakubov avatar Shuaib Yunus avatar Vanessa Wang avatar  avatar TenefitOps avatar Doru-Mihai Muntean avatar  avatar Sanjev Moganadas avatar Jitendra Kotamraju avatar  avatar Brennan Gaunce avatar Chao Sun avatar Sanjay Saxena avatar Rich Cullen avatar Kris McQueen avatar Satish Badugu avatar  avatar apirvu avatar  avatar  avatar  avatar  avatar

k3po.js's Issues

Custom mocha reporter to update SauceLabs build status

Right now the test failures are reported in the command line output and the Sauce Labs builds do not have a success/failed status.

In order to report JavaScript test results to Sauce Labs a custom reporter will need to be implemented.

Some useful links:

Travis build failure on IE 10 and Safari

The Travis builds for Safari and Internet Explorer 10 are failing with:

  2) WsClient echo.from.ws.server:
      AssertionError: '# This script is used for loading a browser origin page\n\naccept http://localhost:8080/\naccepted\nconnected\nread method "GET == '# This script is used for loading a browser origin page\n\naccept http://localhost:8080/\naccepted\nconnected\nread method "GET
      + expected - actual

       read method "GET"
       read version "HTTP/1.1"
       read header "Host" "localhost:8080"
      -read header "Upgrade" /(?i:websocket)/
      -# commented out as of now because bug: https://github.com/k3po/k3po/issues/53
      -# read header "Connection" /(?i:Upgrade)/
      -read header "Sec-WebSocket-Key" /(?<readKey>[a-zA-Z0-9+\/=]{24})/
      -read header "Sec-WebSocket-Version" "13"
      -
      -write status "101" "Switching Protocols"
      -write version "HTTP/1.1"
      -write header "Upgrade" "websocket"
      -write header "Connection" "Upgrade"
      -write header "Sec-WebSocket-Accept" ${ws:handshakeHash(readKey)}
      -write notify SERVER_READY_TO_READ
      -
      -read [0x81 0xfd] ([0..4] :readMask)
      -read option mask ${readMask}
      -read ([0..125] :server125)
      -read option mask [0x00 0x00 0x00 0x00]
      -read await CLIENT_READY_TO_READ
      -
      -write [0x81 0x7d] ${server125}
      +Missing HTTP header: Upgrade

      at assertResults (lib/testFrameworks/mocha-k3po.js:121:28)
      at Context.<anonymous> (lib/testFrameworks/mocha-k3po.js:173:21)
Warning: Task "mochaTest:testMochaK3poSauceBrowserSupport" failed.� Use --force to continue.
Aborted due to warnings.
The command "grunt sauceTest" exited with 3.

please find full logs here:

k3po start task fails on Travis CI with could not resolve maven dependencies

on Travis CI the build is failing(sometimes) because of the k3po:start task failing to complete

Running "k3po:start" (k3po) task
resolving parent: org.kaazing:k3po.parent:3.0.0-alpha-5
resolving parent: org.kaazing:k3po.parent:3.0.0-alpha-5
resolving parent: org.kaazing:community:2.15
resolving parent: org.kaazing:community:2.15
resolving parent: org.kaazing:community:2.15
resolving parent: org.kaazing:k3po.parent:3.0.0-alpha-5
resolving parent: org.kaazing:community:2.15
resolving parent: org.kaazing:k3po.parent:3.0.0-alpha-5
resolving parent: org.kaazing:community:2.15
resolving parent: de.odysseus.juel:juel-parent:2.2.7
resolving parent: de.odysseus.juel:juel-parent:2.2.7
resolving parent: com.fasterxml:oss-parent:4
resolving parent: com.fasterxml:oss-parent:4
resolving parent: org.sonatype.oss:oss-parent:7
resolving parent: org.sonatype.oss:oss-parent:7
resolving parent: org.sonatype.oss:oss-parent:7
resolving parent: org.antlr:antlr4-master:4.2.2
resolving parent: org.sonatype.oss:oss-parent:7
resolving parent: org.sonatype.oss:oss-parent:7
resolving parent: com.fasterxml:oss-parent:4
resolving parent: org.sonatype.oss:oss-parent:7
resolving parent: org.antlr:antlr4-master:4.2.2
resolving parent: org.sonatype.oss:oss-parent:7
resolving parent: org.sonatype.oss:oss-parent:7
could not resolve maven dependencies [ [Error: Unencoded <
  Line: 372
  Column: 41
  Char: ] ]

The failure should also cause the grunt task to fail; current behavior is:

The command "grunt sauceTest" exited with 0.

please find full log here

Some grunt tasks don't cause hard failures resulting in Travis builds false positives

Some Travis builds report false success when some of the grunt tasks fail but the return code is still 0.

so far this problem occurred when the k3po:start(build log) and the mochaTest:testMochaK3poSauceBrowserSupport(build log) tasks.

Running "mochaTest:testMochaK3poSauceBrowserSupport" (mochaTest) task
RuntimeError: ERROR The test with session id aa5224f147a341d5a6613fce840dbf60 has already finished, and can't receive further commands
You can learn more at https://saucelabs.com/jobs/aa5224f147a341d5a6613fce840dbf60
For help, please check https://docs.saucelabs.com/reference/troubleshooting-common-error-messages 
    at timeoutsAsyncScript(0) - BrowserRunner.js:27:33
    at init() - BrowserRunner.js:27:26 
The command "grunt sauceTest" exited with 0.
Running "k3po:start" (k3po) task
resolving parent: org.kaazing:k3po.parent:3.0.0-alpha-5
resolving parent: org.kaazing:k3po.parent:3.0.0-alpha-5
resolving parent: org.kaazing:community:2.15
resolving parent: org.kaazing:community:2.15
resolving parent: org.kaazing:community:2.15
resolving parent: org.kaazing:k3po.parent:3.0.0-alpha-5
resolving parent: org.kaazing:community:2.15
resolving parent: org.kaazing:k3po.parent:3.0.0-alpha-5
resolving parent: org.kaazing:community:2.15
resolving parent: de.odysseus.juel:juel-parent:2.2.7
resolving parent: de.odysseus.juel:juel-parent:2.2.7
resolving parent: com.fasterxml:oss-parent:4
resolving parent: com.fasterxml:oss-parent:4
resolving parent: org.sonatype.oss:oss-parent:7
resolving parent: org.sonatype.oss:oss-parent:7
resolving parent: org.sonatype.oss:oss-parent:7
resolving parent: org.antlr:antlr4-master:4.2.2
resolving parent: org.sonatype.oss:oss-parent:7
resolving parent: org.sonatype.oss:oss-parent:7
resolving parent: com.fasterxml:oss-parent:4
resolving parent: org.sonatype.oss:oss-parent:7
resolving parent: org.antlr:antlr4-master:4.2.2
resolving parent: org.sonatype.oss:oss-parent:7
resolving parent: org.sonatype.oss:oss-parent:7
could not resolve maven dependencies [ [Error: Unencoded <
  Line: 372
  Column: 41
  Char: ] ]
The command "grunt sauceTest" exited with 0.

k3po start task fails on Travis CI with Uncaught Error: Invalid dependency state. Missing pomXml.

on Travis CI the build is failing(sometimes) because of the k3po:start task failing to complete

Running "k3po:start" (k3po) task
resolving parent: org.kaazing:k3po.parent:3.0.0-alpha-5
resolving parent: org.kaazing:k3po.parent:3.0.0-alpha-5
resolving parent: org.kaazing:community:2.15
resolving parent: org.kaazing:community:2.15
resolving parent: org.kaazing:community:2.15
resolving parent: org.kaazing:k3po.parent:3.0.0-alpha-5
resolving parent: org.kaazing:community:2.15
resolving parent: org.kaazing:k3po.parent:3.0.0-alpha-5
resolving parent: de.odysseus.juel:juel-parent:2.2.7
resolving parent: org.kaazing:community:2.15
resolving parent: org.sonatype.oss:oss-parent:7
resolving parent: de.odysseus.juel:juel-parent:2.2.7
resolving parent: com.fasterxml:oss-parent:4
resolving parent: com.fasterxml:oss-parent:4
resolving parent: org.sonatype.oss:oss-parent:7
resolving parent: org.sonatype.oss:oss-parent:7
  1) "after each" hook
  11 passing (974ms)
  1 failing
  1) Control "after each" hook:
     Uncaught Error: Invalid dependency state. Missing pomXml. org.sonatype.oss:oss-parent:7
      at Dependency.getParent (node_modules/node-java-maven/lib/dependency.js:56:11)
      at node_modules/node-java-maven/index.js:218:24
      at Parser.<anonymous> (node_modules/xml2js/lib/xml2js.js:484:18)
      at Parser.exports.Parser.Parser.parseString (node_modules/xml2js/lib/xml2js.js:494:16)
      at Parser.parseString (node_modules/xml2js/lib/xml2js.js:7:59)
      at Object.exports.parseString (node_modules/xml2js/lib/xml2js.js:535:19)
      at loadFile (node_modules/node-java-maven/index.js:213:14)
      at node_modules/node-java-maven/index.js:208:16
Warning: Task "mochaTest:testBase" failed.� Use --force to continue.
Aborted due to warnings.
The command "grunt sauceTest" exited with 3.

please find full log here

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.