4

I'm trying to use webdriverIO to make automatic test over an API rest without any result, also try with chai and chai-http using webdriverIO, but nothing yet. Any clue?

This is something I wrote:

  var chai = require('chai');
  var chaiHttp = require('chai-http');
  global.expect = chai.expect;
  chai.Should();
  chai.use(chaiHttp);

  var username = 'salvador.salvatierra@alegra.com';
  var token = 'a5ff7f1063582fd0140d';

  describe('Se consulta a la lista de contactos a traves de la API rest', 
 function(){

   it('Se hace un request GET al endpoint /contacts', function(){

    chai.request('https://app.alegra.com/api/v1/contacts')
    .get('/')
    .set('Accept','application/json')
    .query({limit:'10', order_direction: 'DESC', order_field: 'id'})
    .auth(username,token)
    .then(function(res){
        console.log(res);
        res.should.have.status(200);
        res.body.should.be.a.json;
    })
    .catch(function (err){
        setTimeout(function(){
            throw new err;
        });         
    })      
});

});

UPDATE:
I'm using webdriverIO with mocha, chai and chai-http. The way I'm running this is .\node_modules\.bin\wdio wdio.conf.js --spec .\test\specs\test\get_test.js via command and the browser command I'm using is browser.url('/invoices'). The endpoint I want to hit is https://app.alegra.com/api/v1/contacts/

This is my package.json:

 {
  "name": "web-test",
  "version": "1.0.0",
  "description": "\"# Alegra webdriverIO tests\"",
  "main": "index.js",
  "dependencies": {},
  "devDependencies": {
    "body-parser": "^1.17.2",
    "chai": "^4.1.1",
    "chai-http": "^3.0.0",
    "chai-webdriverio": "^0.4.2",
    "express": "^4.15.4",
    "supertest": "^3.0.0",
    "wdio-dot-reporter": "0.0.8",
    "wdio-mocha-framework": "^0.5.11",
    "wdio-selenium-standalone-service": "0.0.8",
    "wdio-spec-reporter": "^0.1.2",
    "webdriverio": "^4.8.0"
   },
   "scripts": {
     "test": "echo \"Error: no test specified\" && exit 1"
   },
   "author": "Salvador Salvatierra",
   "license": "ISC",
   "directories": {
     "test": "test"
   },
   "repository": {
   "type": "git",
   "url": "git+https://ssalvatierra@bitbucket.org/ssalvatierra/alegra-wdio.git"
   },
  "keywords": [
    "alegra",
    "test",
    "webdriverio"
  ],
  "homepage": "https://bitbucket.org/ssalvatierra/alegra-wdio#readme"
  }
  • 1
    Welcome to Stack Overflow! Please read [ask], especially the part about [mcve] (MCVE), and [How much research effort is expected?](https://meta.stackoverflow.com/questions/261592/how-much-research-effort-is-expected-of-stack-overflow-users) This will help you debug your own programs and solve problems for yourself. If you do this and are still stuck you can come back and post your MCVE, what you tried, and the execution result including any error messages so we can better help you. Also provide a link to the page and/or the relevant HTML. – JeffC Aug 23 '17 at 20:49
  • Your question looks much better now. Don't you have to invert the order or your call to be `var get = chai.request('').auth(user, pass).get('partial_url')`? – Tom Aug 23 '17 at 23:26
  • @Tom when i change the code like `var get = chai.request('https://app.alegra.com').auth(username,pass).get('/invoice');` I got an .auth is not a function error. – Salvador Salvatierra Aug 23 '17 at 23:57
  • How do you run your code? Are you using also Jasmine? What is the var `browser`? Can you provide any `package.json` for your example? Please add all information you can in the question. – Tom Aug 24 '17 at 00:24
  • I already update the information @Tom – Salvador Salvatierra Aug 24 '17 at 00:56
  • @Salvador, your package code has an extra comma, so it gives syntax error. After fixing that and runnign `npm install`, it says `npm ERR! peerinvalid Peer chai-webdriverio@0.4.2 wants chai@~4.0.1`. Are you sure all the information in the question is correct? – Tom Aug 24 '17 at 08:04
  • @Tom, that was just a part of it, I just uptate the package.json – Salvador Salvatierra Aug 24 '17 at 13:14
  • I added the callback function so I can get the http response, now when i run the test and it should appear an error, for some reason the error it is not recognize, for example erase the auth part, the test should get to the throw new error part and show me the error in res, but this dont happend, any clue? – Salvador Salvatierra Aug 25 '17 at 17:40
  • @iamdanchiv do you know something about this? – Salvador Salvatierra Aug 29 '17 at 15:35
  • @Tom i just change the code, this run really good, but now I cannot get the errors when there is no 200 status, if you comment the ".auth" line and run this you will see that it run good, it shouldnt run good because it never find the 200 status code – Salvador Salvatierra Aug 30 '17 at 18:48
  • @robertklep can you help with this? – Salvador Salvatierra Aug 31 '17 at 03:21
  • I heard that Selenium aims at testing web UI. The Node API request = require('http') has ways of sending HTTP requests. Postman appears to simplify regression bookkeeping. – eel ghEEz May 08 '18 at 13:51

0 Answers0