Giter Site home page Giter Site logo

mmendesas / walnutjs Goto Github PK

View Code? Open in Web Editor NEW
16.0 6.0 10.0 12.82 MB

A framework that helps you build your e2e tests easily using the BDD style

Home Page: https://mmendesas.github.io/walnutjs/

License: MIT License

JavaScript 96.97% Gherkin 3.03%
automation ui-testing bdd-style cucumber es6 e2e-tests nodejs selenium

walnutjs's Introduction

walnutjs

walnutjs is a collection of generic steps for interact with web-applications.

You can easily simulate user interactions using a business-readable way. You only need to write some feature files using the Gherkin syntax and plan your tests with BDD (Behavior Driven Development) pattern.

Enjoy It!

https://nodei.co/npm/walnutjs.png?downloads=true&downloadRank=true&stars=true

CircleCI Npm version License contributions welcome

Usage: walnut [options]

Walnut Framework - Automated BDD Tests for Web Applications

Options:
  -V, --version              output the version number
  -c, --config <path>        path to JSON config file
  -t, --tags <tagName>       name of tag to run (default: [])
  -m, --execMethod <method>  execution method [e.g runOnlyAPI]
  -h, --help                 output usage information

Please see our wiki DOCs for more details.

Getting Started

These instructions will give you a sample feature file to show you how easy is to make your own tests

Prerequisites

Before continue, check that you have completed the following requirements:

  • java - Java runtime environment - tested on 1.8.0_211
  • nodejs - A javascript runtime - tested on v10.16.0
  • selenium webserver:

Setup the project

  1. Start by creating a simple nodejs project and add walnutjs to it:

    mkdir my-app && cd my-app
    npm init -y
    npm i --save walnutjs
  2. Setting up a walnut-config.js file inside rootFolder based on this file

  3. Create a folder structure like that:

    > my-app
        > test
            > features
                sample.feature
            > step-defs
                custom-steps.js
            > locators
                locators.json
            > params
                params.json

    You can create these folders above on your own, just be sure to indicate the correct paths inside walnut-config.js file.

  4. Add the folowing content to locators.json file:

    {
        "containers":[
            {
                "name": "GoogleHome",
                "locators":[
                    { "key": "SearchInput", "type": "name", "value": "q" },
                    { "key": "SearchButton", "type": "p:xpath", "value": "//input[@value='{0}']" }
                ]
            }
        ]
    }
  5. Add the following content to sample.feature file:

    Feature: First test with walnutjs
    
        @simple_web
        Scenario: I want see the Google Page
            Given user navigates to 'http://www.google.com'
            When user fills 'GoogleHome-SearchInput' by replacing text with 'led zeppelin wikipedia'
            And user clicks on 'GoogleResult-SearchButton'
  6. Before execution check that selenium webserver was started correctly. For this sample we will use webdriver-manager

    webdriver-manager start
    ...
    10:15:57.230 INFO [SeleniumServer.boot] - Selenium Server is up and running on port 4444
  7. Define a single start script in your package.json:

     "scripts": {
        "start": "walnut",
      }
  8. Execute your script

    npm start

    You can also run using $(npm bin)/walnut on your terminal

More details

Review this project boilerplate to get more insights and this documentation to see more details.

Running the tests

Just run the following command inside the root folder:

  • test: npm run test
  • coverage: npm run coverage

Built With

  • nodejs - A JavaScript runtime
  • cucumber - tool for running automated tests written in plain language
  • selenium-webdriver - The official Webdriver Javascript bindings from the Selenium project.

Authors

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License.

walnutjs's People

Contributors

andreakiosakai avatar dependabot[bot] avatar guilhermegregio avatar mmendesas avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

walnutjs's Issues

Parameters File

Fazer a leitura de dados de um arquivo externo de parâmetros

Error: ReferenceError: describe is not defined

I'm getting the following error when I try to run, after I updated walnutjs to version 1.0.51:

protractor protractor.conf.js

root@236b04767951:/bdd# protractor protractor.conf.js [13:55:01] I/launcher - Running 1 instances of WebDriver [13:55:01] I/local - Starting selenium standalone server... [13:55:02] I/local - Selenium standalone server started at http://172.17.0.2:45820/wd/hub [13:55:03] E/launcher - Error: ReferenceError: describe is not defined at Object.<anonymous> (/bdd/node_modules/walnutjs/src/support/config.test.js:14:1) at Module._compile (module.js:573:30) at Object.Module._extensions..js (module.js:584:10) at Module.load (module.js:507:32) at tryModuleLoad (module.js:470:12) at Function.Module._load (module.js:462:3) at Module.require (module.js:517:17) at require (internal/module.js:11:18) at /bdd/node_modules/cucumber/lib/cucumber/cli/support_code_loader.js:63:29 at Array.forEach (<anonymous>) [13:55:03] E/launcher - Process exited with error code 100

Method that validates value in response body needs a minor fix

/**
* Validates a value in specific node in JSON response.body
/
this.Then(/^(api) the JSON response key '(.
)' should have value (equals to|not equals to|which contains|which not contains|which starts with|which ends with) '(.*)'$/, function(keyPath, comparissonType, expectedValue, callback) {
var _this = this;
keyPath = helperCommon.getTreatedValue(keyPath);
expectedValue = helperCommon.getTreatedValue(expectedValue);

    //get value from JSON using JSONPATH
    jsonparser.init(trest.response.body);
    var jsonValue = jsonparser.getValue(keyPath)[0] || '<path not found>';

    //compare
    var compareRes = helperCommon.compare(jsonValue, comparissonType, expectedValue);
    if (!compareRes.result) {
        _this.handleError(compareRes.msg, callback);
    } else {
        _this.delayCallback(callback);
    }
});

The problem happens when the value returned from the given key path is 0 or false. In these cases, it will return

isPresentAndDisplayed para lista de elementos

Ao utilizar o getElementFinderAll do element helpers não é possível passar para o isPresentAndDisplayed. Seria interessante ter um método auxiliar para fazer um forEach na lista de elementos resolvendo a promise all.

Ex:

function isPresentAndDisplayedAll(elements) {
  const isPresents = [];
  elements.each(el => {
    isPresents.push(this.isPresentAndDisplayed(el))
  });

  return $q.all(isPresents);
}

Error: Multiple step definitions match

Ao utilizar o step abaixo:

/^the '(.+)-(.+)' has value (equals to|not equals to|which contains|which not contains) '(.*)'$/

Apresenta o seguinte erro:

Multiple step definitions match:
       /^the '(.+)-(.+)' has value (equals to|not equals to|which contains|which not contains) '(.*)'$/ - node_modules/walnutjs/src/step_defs/validation.js:94
       /^the '(.+)' has value (equals to|not equals to|which contains|which not contains) '(.*)'$/      - node_modules/walnutjs/src/step_defs/validation.js:306

[BUG] - Error in method

When I try to execute a simple script using node version: 6.11.2 this exception appears:

node_modules/walnutjs/src/support/hooks.js:29 Object.entries is not a function
TypeError: node_modules/walnutjs/src/support/hooks.js:29 Object.entries is not a function

Step to fill with JS

Create a step definition for fill fields using pure Javascript like the example below:

document.getElementById("fromDate").value = 2017-11-28

Problema de leitura dos locators

Esta ocorrendo este erro:

E/launcher - node_modules/walnutjs/src/support/hooks.js:12 Locators File Not Found

Quando o projeto esta numa estrutura de pasta um pouco maior.

Por exemplo ao rodar em
C:\projeto -> rodou normal
C:\projeto\subprojeto\projeto-e2e -> aqui deu o erro acima

Erro no tonumber

A expressão tonumber esta se comportando de forma incorreta exemplo:

tonumber('11.750,80|d') // => 11.750

O correto seria 11750.80

Também não existe forma de mudar a precisão de casas decimais e tem problema para formatos diferentes de valores por exemplo valores brasileiro ou americano.

Talvez uma forma interessante de utilização seria assim:
tonumber('VALOR|PRECISAO|FORMATO')

tonumber('1234.123.123,56|f:2|BRL')

VALOR: 11.760,00
PRECISAO: f:2
FORMATO: BRL

Date format error in expression NOW

When I use the expression now with now(yyyy-MM-dd mm:ss) the format returned is:
2017-7-14 57:13
In this case the month is returned with only one digit, the correct response would be:
2017-07-14 57:13

Add method to store a variable from a response field found by json path

/**
* Stores the value of the response field found by json path
/
this.Then(/^(api) user stores the value '(.
)' from response in variable (.*)$/, function(keyPath, name, callback) {

   keyPath = helperCommon.getTreatedValue(keyPath);
   var varName = helperCommon.getTreatedValue(name);

   //get value from JSON using JSONPATH
   jsonparser.init(trest.response.body);
   var varValue = jsonparser.getValue(keyPath)[0];

   // Add the value to variables
   helperVars.addVariable(varName, varValue);
   this.delayCallback(callback);

});

Math Expression

Criar mecanismo para usar expressões matemática simples de forma mais intuitiva:
exemplo: math(item+outroItem*6+44+item)

Add steps to interact using pure JS

Add some steps for interact with the page using pure JS like the following examples:

And user clicks by JS on 'container-key'
And user executes the JS 'window.alert('mteste')'

SPA for Tests

  • create a single page application for test all the methods inside the framework

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.