Giter VIP home page Giter VIP logo

gauge-js's Introduction

Gauge-JS

Actions Status Contributor Covenant

This project adds Javascript language plugin for gauge.

Getting started

Pre-requisite

Installation

gauge install js

Create a gauge-js project

gauge init js

Run tests

gauge run specs

Documentation

For other details refer the documentation here

Demos and examples

Plain Javascript

Run the following command to create a sample gauge template

$ gauge init js_simple

Taiko

Run the following command to create a sample Taiko template

$ gauge init js

Alternate Installation options

Install specific version

gauge install js --version <version>

Install from zip file

gauge install js --file gauge-js-<version>.zip

Build from Source

The plugin is authored in Javascript. Gauge is authored in golang. These are independent processes talking to each other over TCP on port GAUGE_INTERNAL_PORT (env variable) using Protobuf.

Pre-Requisites
Compiling
npm install
Run tests:
npm test
Installing from source
npm run installPlugin
Create package
npm run package

You can then install the offline zip archive created using

gauge install js --file gauge-js-<version>.zip

Copyright

Copyright 2018 ThoughtWorks, Inc.

gauge-js's People

Contributors

apoorva-ga avatar apoorvam avatar autumn-calhoun avatar chadlwilson avatar debashis9012 avatar dependabot-preview[bot] avatar dependabot[bot] avatar dtinth avatar ivanbportugal avatar kashishm avatar kaustavdm avatar luciferankon avatar negidharmendra avatar nehashri avatar nick-triller avatar nivedhasenthil avatar orangebean avatar renjithgr avatar riju91 avatar shubhamsc avatar sriv avatar yuqianma avatar zabil avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gauge-js's Issues

Getting a screenshot error

Expected behavior
When there is a failure in the test case, screenshot should get captured

Actual behavior
Error: spawnSync gauge_screenshot ENOENT

Steps to replicate

  • Run a gauge-js spec from VSCode with a step throwing error. We face this issue

Version

Gauge version: 0.9.4.nightly-2017-10-09
Commit Hash: 8ef345c

Plugins
-------
csharp (0.10.1)
html-report (4.0.2)
java (0.6.6.nightly-2017-09-14)
js (2.0.1)
ruby (0.4.2)
screenshot (0.0.1)
spectacle (0.1.2)
xml-report (0.2.0)

Problem with Gauge 0.8

Hi,

Since I updated from gauge 0.7 to gauge 0.8 tests are failing.

/home/txbj8305/.gauge/plugins/js/1.3.0/node_modules/protobufjs/dist/ProtoBuf.js:2901
                        throw(e);
                        ^

Error: Missing at least one required field for Message .gauge.messages.Message: messageType
    at Error (native)
    at T.ProtoBuf.Reflect.MessagePrototype.decode (/home/txbj8305/.gauge/plugins/js/1.3.0/node_modules/protobufjs/dist/ProtoBuf.js:3218:35)
    at Function.Message.decode (/home/txbj8305/.gauge/plugins/js/1.3.0/node_modules/protobufjs/dist/ProtoBuf.js:2896:37)
    at Object.exports.decode (/home/txbj8305/.gauge/plugins/js/1.3.0/src/message-codec.js:20:29)
    at Socket.messageHandler (/home/txbj8305/.gauge/plugins/js/1.3.0/src/connection.js:17:29)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:188:7)
    at readableAddChunk (_stream_readable.js:176:18)
    at Socket.Readable.push (_stream_readable.js:134:10)
    at TCP.onread (net.js:548:20)

  Error Message: Connection closed [127.0.0.1:50742] cause: EOF
  Stacktrace: 
  

  Error Message: write tcp 127.0.0.1:46843->127.0.0.1:50742: use of closed network connection
  Stacktrace: 
  
Successfully generated html-report to => /home/txbj8305/develop/workspace/HOME/gauge-test/reports/html-report
Specifications:	0 executed	0 passed	0 failed	0 skipped
Scenarios:	0 executed	0 passed	0 failed	0 skipped

Total time taken: 11ms

I think it's related to : getgauge/gauge-proto#3
Any clue ?

Expose a single global `gauge{}` object

Currently, all the functions are exposed globally. Let us avoid spamming the global namespace and expose a single gauge{} object with all the functions are methods of that object.

Also, as part of this, we should ensure that important globals like stepRegistry, hookRegistry etc. are not exposed to the test implementation code.

Warning: This will be a breaking change in the API. So, the documentation needs to be updated along with this.

Launching an extra empty browser with my test

Hello Community,
I am exploring the options of possibly implementing gauge test framework in my new project using JS and selenium-webdriver.

So far, I have been able to successfully initialize the project and add a very basic test that launches the URL in my browser and clicks on a button.

But I have run into a few issues which I am enlisting here:

  1. I have modularised my driver creation in a separate file I am calling driver.setup.js When the tests launch it launches 2 instances of the chrome browser, one of them launches my test and the other one is a na empty browser. How do I fix this? I have tried looking at the possibilities of why it would even happen but so far I cannot pin point at anything.

  2. My Driver wont quit:
    I am using the gauge hooks afterSuite to call driver.quit() but the chrome browsers just stay there and never quit even after my tests have passed and finished the execution.

My Folder Structure is :

src
    e2e
         env
         specs
         tests
            driver-setup.js
            steps.js
         package.json

The contents of my package.json are as follows:

{
  "name": "webdriver-tests",
  "version": "1.0.0",
  "description": "",
  "devDependencies": {
    "selenium-webdriver": "^3.4.0"
  }
}

Please help if possible.

Execution on windows is not starting.

Execution on Windows is failing with following error.

[CRITICAL] Failed to initialize. fork/exec index.js: %! (MISSING)is not a valid Win32 application.

Sandbox test implementation code

Currently, there is no sandboxing used by the JS runner. This means, test implementations can overwrite critical methods and variables, or worse, kill the gauge-js process itself by committing suicide.

We can use the nodejs vm API. It is stable since v0.12.x.

How to read custom env variables?

I'm using Gauge to write E2E tests for an Angular application using Typescript and Protractor. Gauge is run after transpiling typescript to javascript. Protractor is configured programmatically and I'd like to change such a configuration based on values of Gauge custom environment properties. I'm wondering if this could done in the Node.js way:

process.env.SOME_ENV_VAR

Assertion errors don't seem to show on the report

Generally speaking, I am going through @philipbeadle 's approach to running webdriver.io within gauge steps. Some of his work is here.

However, I am having trouble seeing assertion errors on the gauge report, even though they show up in the console. Here's what my project looks like:

package.json:

devDependencies {
    "chai": "^3.5.0",
    "chai-as-promised": "^5.2.0",
    "webdriverio": "^4.0.3",
    "webdriverjs-angular": "^0.1.3"
}

step_implementation.js:

var webdriver = require('webdriverjs-angular');

var options = {
    desiredCapabilities: {
        browserName: 'chrome'
    }
};

var chai = require('chai');
var chaiAsPromised = require('chai-as-promised');
var expect = chai.expect;
chai.Should();
var assert = require("assert");

gauge.step("Visit Google", function(done) {
    webdriver
        .remote(options)
        .init()
        .on('error', function(e) { // Sorta hacky, trying to get errors to show via emit
            gauge.message('This message never shows up');
            done('Assertion error: ' + JSON.stringify(e)); // I tried just passing 'e' here
        })
        .url('http://www.google.com/')
        .getTitle().then(function(title) {
            try {
                gauge.message('Verifying Page "' + title + '"');
                expect(title).to.equal('Google BLAH'); // Should fail, but shows up in the console, not on report.
                assert(title, 'Google BLAH'); // Doesn't even show on the console, let alone the report.
            } catch (e) { // I added this hacky try-catch to try to force gauge to fail, but I really shouldn't have to.
                gauge.message('OK... ' + JSON.stringify(e));
                this.emit('error', e);
            }
        })
        .end()
        .call(done);
});

So... any ideas?

Better Javascript Errors

It seems that if there's an error in the spec implementation Javascript itself, the Error Message and Stacktrace don't show up even if:

gauge --verbose specs

It looks like:

ฮป gauge specs
# English vowels
  ## Vowel counts in single word     F
    Failed Step: Vowels in English language are "aeiou".
    Error Message:
    Stacktrace:

  ## Vowel counts in single word      ## Vowel counts in multiple word     F
    Failed Step: Vowels in English language are "aeiou".
    Error Message:
    Stacktrace:

This of course is where example.spec (in the spec folder of course) is:

English vowels
=====================

This is an executable specification file. This file follows markdown syntax.
Every heading in this file denotes a scenario. Every bulleted point denotes a step.

To execute this specification, run

    gauge specs


* Vowels in English language are "aeiou".

Vowel counts in single word
---------------------------

tags: single word

* The word "gauge" has "3" vowels.


Vowel counts in multiple word
-----------------------------

This is the second scenario in this specification

Here's a step that takes a table

* Almost all words have vowels
     |Word  |Vowel Count|
     |------|-----------|
     |Gauge |3          |
     |Mingle|2          |
     |Snap  |1          |
     |GoCD  |1          |
     |Rhythm|0          |

And, example.js (in the tests folder) is:

/* globals gauge, beforeScenario */
"use strict";
var assert = require("assert");
var vowels = ["a", "e", "i", "o", "u"];
var numberOfVowels = function(word) {
    var vowelArr = word.split("").filter(function(elem) {
        return vowels.indexOf(elem) > -1;
    });
    return vowelArr.length;
};

// --------------------------
// Gauge step implementations
// --------------------------
gauge("Vowels in English language are <vowels>.", function(vowelsGiven) {
    assert.equal(vowelsGiven, vowels.join(""));
    javascriptErrorHere
});
gauge("The word <word> has <number> vowels.", function(word, number) {
    assert.equal(number, numberOfVowels(word));
});
gauge("Almost all words have vowels <table>", function(table) {
    table.rows.forEach(function(row) {
        assert.equal(numberOfVowels(row.cells[0]), parseInt(row.cells[1]));
    });
});

// ---------------
// Execution Hooks
// ---------------
beforeScenario(function() {
    assert.equal(vowels.join(""), "aeiou");
});
beforeScenario(function() {
    assert.equal(vowels[0], "a");
}, {
    tags: ["single word"]
});

Implement refactoring

Gauge has a support for refactoring code. We need to implement that in the JS runner.

console.log does not print output in Windows

On Windows, adding a console.log does not print anything in gauge's output. This is likely to be related to the way the runner spawns subprocess and may be linked to sandbox as well.

Refactoring is broken after deprecating `gauge.step`

Steps to replicate :

  • gauge init js
  • gauge refactor 'The word "gauge" has "3" vowels.' 'ord "gauge" has "3" vowels.'

The out put show is

1 specifications changed.

0 concepts changed.

1 files in code changed.

but the step in js code is node changed.

Trace: ReferenceError: exports is not defined

exports.Test = Test;

The above line throws error when run using gauge and gauge-js but the file perfectly runs using node

node tests/test.js

But if I change the previous code to following, then it works.

module.exports = {
    Test: test
}

Step alias implementation looks broken

Just noticed that step aliases, aka, "Multiple Step Names" are not working with the current HEAD.

Steps to reproduce

test.spec

# Test spec

## Test scenario

* I am a step
* I am also a step

step_implementation.js

gauge.step(["I am a step", "I am also a step"], function () {
  // do something
});

Running these says:

$ gauge specs/
[ValidationError] /tmp/gauge-sample-js/specs/test.spec:5: Step implementation not found => 'I am a step'
[ValidationError] /tmp/gauge-sample-js/specs/test.spec:6: Step implementation not found => 'I am also a step'
Successfully generated html-report to => /tmp/gauge-sample-js/reports/html-report
Specifications: 0 executed  0 passed    0 failed    1 skipped
Scenarios:  0 executed  0 passed    0 failed    1 skipped

Total time taken: 12ms

Does gaugeJs have ES6 support?

I am attempting to write Jest/Enzyme tests in Gauge and I need to integrate Gauge into DEV repo. I also need to make sure that my gauge tests understands node modules written in ES6.
So, my question is:
Is there support for ES6 constructs with Gauge? Or we need to transpile tests as well as node modules?

Provide suggestions for unimplemented steps

Proposed behavior
If there are unimplemented steps, running from the command line should show a suggestion for the unimplemented steps refer getgauge/gauge#748 for more details

Acceptance criteria

  • should get the suggestion while running from the command line

Test cases

  • should get the suggestion from the command line
  • should not get the suggestion in the IDE

AssertionError in hooks crash runner

Sample implementation:

gauge.hooks.beforeScenario(function () {
  assert.equal("a", "b");
});

Output:

# Specification Heading
  ## Vowel counts in single word
assert.js:89
  throw new assert.AssertionError({
  ^
AssertionError: 'a' == 'b'
    at Object.gauge.hooks.beforeScenario.tags (step_implementation.js:41:10)
    at runFnAsync (/Users/kaustavd/.gauge/plugins/js/1.0.1/src/test.js:63:11)
    at Test.run (/Users/kaustavd/.gauge/plugins/js/1.0.1/src/test.js:69:16)
    at Object.executeHook [as hook] (/Users/kaustavd/.gauge/plugins/js/1.0.1/src/executor.js:98:68)
    at executeHook (/Users/kaustavd/.gauge/plugins/js/1.0.1/src/message-processor.js:44:26)
    at executeBeforeScenarioHook (/Users/kaustavd/.gauge/plugins/js/1.0.1/src/message-processor.js:65:15)
    at MessageProcessor.getResponseFor (/Users/kaustavd/.gauge/plugins/js/1.0.1/src/message-processor.js:149:40)
    at null.<anonymous> (/Users/kaustavd/.gauge/plugins/js/1.0.1/src/gauge.js:17:22)
    at emitOne (events.js:77:13)
    at emit (events.js:169:7)


Unable to connect to plugin Html Report 2.0.1. proto: required field "SuiteExecutionResult.SuiteResult.SpecResults.ProtoSpec.Items.Scenario.PreHookFailure.StackTrace" not set

Specifications: 1 executed  0 passed    1 failed    0 skipped
Scenarios:  1 executed  0 passed    1 failed    1 skipped

Total time taken: 11ms

Implement step aliases

Step aliases, aka, multiple step names let you create one test implementation that is shared by multiple step texts. See how multiple step names work in ruby.

For example, the step implementation call can also be:

gauge(["Create a user <username>", "Create another user <username>"], function (username) {
  // do cool stuff
});

Important points:

  • The first argument to the step implementation function can be either a string or an array of strings.
  • There can be n number of aliases per implementation.

Export `step` and all the hooks in the global scope

gauge.step("a sample step", function() {});
step("a sample step", function() {});

Both the above usages should work and same applies to all the hooks as well.

The other test runners like Mocha and Jasmine also have describe and it in global scope.

Are promises implemented in the steps?

If so whats the syntax? I'd like to use the steps like we can with mocha and other asynch test runners :)

gauge.step("Vowels in English language are <vowels>.", function(vowelsGiven) {
  return webdriverjsAngular
    .remote(options)
    .init()
    .url('http://www.google.com')
    .getTitle().should.eventually.be.equal('WebdriverIO');
});

Then this step would wait for the browser to spin and navigate to google and then check the title before moving on :)

Cheers
Phil

Problem installing from source

01:36 john@UX303LB:~/repos/git/gauge-js(master)$ npm run installPlugin
> [email protected] installPlugin /home/john/repos/git/gauge-js
> node ./scripts/install.js

Installed gauge-js v0.1.1

However this doesn't seem to result in a usable plugin:

01:37 john@UX303LB:~/tmp/gauge-js$ gauge --init js
[INFO] Compatible js plugin is not installed
[INFO] Installing plugin => js ...
[CRITICAL] Failed to initialize. Failed to install plugin js . Invalid plugin : Could not download js-install.json file. File does not exist. 

01:38 john@UX303LB:~/tmp/gauge-js$ ls ~/.gauge/plugins/js/
0.1.1

Support async operations in hooks

While discussing in #31, I figured that we have not yet implemented async support for hooks. What we need is, say:

gauge.hooks.beforeScenario(function (done) {
  setTimeout(function () { 
    assert.equal(vowels[0], "a"); 
    done(); }, 
  2000);
});

How to use module.exports?

Hi :)
How do i use module.exports so i can set up things like a common instance of a browser driver. I'd like to do this.

var driver;
module.exports = function () {
  if (!driver) {
    driver = require('webdriverjs-angular');
    var options = {
      desiredCapabilities: {
        browserName: 'chrome'
      },
      ngRoot: 'body' // main application selector
    };
    console.log('test');
    driver
      .remote(options)
      .init()
      .url('http://127.0.0.1:8080/').then(function () {
      return driver;
    });
  } else {
    return driver
      .url('http://127.0.0.1:8080/').then(function () {
        return driver;
      });
  }
};

But I keep getting

driver.js:2
module.exports = function () {
^
ReferenceError: module is not defined
    at driver.js:2:1
    at ContextifyScript.Script.runInNewContext (vm.js:38:15)
    at Object.exports.runInNewContext (vm.js:69:17)
    at VM.run (/Users/PhilBeadle/.gauge/plugins/js/1.1.0/src/vm.js:19:6)
    at VM.runFile (/Users/PhilBeadle/.gauge/plugins/js/1.1.0/src/vm.js:24:8)
    at /Users/PhilBeadle/.gauge/plugins/js/1.1.0/src/impl-loader.js:9:8
    at Array.forEach (native)
    at Object.loadImpl [as load] (/Users/PhilBeadle/.gauge/plugins/js/1.1.0/src/impl-loader.js:7:68)
    at run (/Users/PhilBeadle/.gauge/plugins/js/1.1.0/src/gauge.js:11:15)
    at Object.<anonymous> (/Users/PhilBeadle/.gauge/plugins/js/1.1.0/src/gauge.js:26:3)

Cheers
Phil

Using Protractor's ExpectedConditions

I'm using Gauge in my project and I need to use Protractor's ExpectedConditions inside a step.

But no matter what I do, it is always undefined.

Am I doing something wrong?

import { Gauge } from './../interfaces/gauge';
import { SiteMap } from './../structure/site-map';
import * as protractor from 'protractor';

declare var gauge: Gauge;

let driver: webdriver.WebDriver = gauge.protractor.driver;
let browser: protractor.ProtractorBrowser = gauge.protractor.browser;
let element: protractor.ElementHelper = gauge.protractor.element;
let by: protractor.ProtractorBy = gauge.protractor.by;
let expect: Chai.ExpectStatic = gauge.expect;
let siteMap: SiteMap = gauge.siteMap;

let EC = protractor.ExpectedConditions; // undefined

Take screenshot on failure

Language runners can trigger gauge_screenshot on a step/hook failure and send that data back to gauge in the execution result. Need to implement this.

Debugging?

Is there a way to debug the step implementation? i.e. Something like the Nodejs chrome dev tools debugger?

Separate out documentation

The README is getting too long, because gauge-js has so many features now ๐Ÿ˜‰

Should we break it down into multiple pages somewhere? If yes, where is the best place to put it?

tests directory should be renamed to specs

when using other gauge plugins initializing a plugin will create a 'step_impl' or 'step_implementations' directory where step definitions are stored. When initializing the js plugin it creates a 'tests' directory which seems inconsistent with the plugin eco-system. I am also able to rename that directory to just 'steps' since 'step_implementations' is so long. It would be nice if the plugin eco-system could settle on a common name.

Does autocomplete work?

I dont seem to get autocomplete, I started typing

  • The word

in the vanilla project but nothing came up. I expected to see the option for the implemented step :)

aync test not failing

Hi,

I have some aync test, when the test/assertion fails it is not recognized as failure in console or in reports. any thoughts?.

Below is the sample test.
// --------------------------
// Gauge step implementations
// --------------------------

gauge.step('User can get latest plan', function(done) {
setTimeout(function() {
try {
var driver = new Driver.Driver('http://localhost:80');
driver
.checkLatestPlan()
.then(res => {
done();
assert.equal(true, false);
})
.catch(err => {
console.error(err);
});
} catch (e) {
done(e);
}
}, 5000);
});

console output

Specification Heading

Plan Socket Connection Initiated

Socket connection Established
{ AssertionError: true == false
at driver.checkLatestPlan.then.res (tests\acceptance-test.js:20:19)
at process._tickCallback (internal/process/next_tick.js:103:7)
name: 'AssertionError',
actual: true,
expected: false,
operator: '==',
message: 'true == false',
generatedMessage: true }
P

Successfully generated html-report to => D:\workspace\bumblebee\bumblebee-integration-tests\gauge\reports\html-report
Specifications: 1 executed 1 passed 0 failed 0 skipped
Scenarios: 1 executed 1 passed 0 failed 0 skipped

Versions:
Gauge version: 0.8.4
Plugins

html-report (4.0.0)
js (2.0.0)

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.