mdasberg / ng-apimock

Node plugin that provides the ability to use scenario based api mocking: for local development for protractor testing
MIT License
99 stars 26 forks source link

Could not select scenario [short-term] #29

Open mr-mateus opened 6 years ago

mr-mateus commented 6 years ago

[16:06:04] E/launcher - Could not select scenario [short-term] [16:06:04] E/launcher - Error: Could not select scenario [short-term] at process.on (C:\workspace\ngapimock-test\node_modules\protractor\lib\launcher.ts:187:50) at emitOne (events.js:96:13) at process.emit (events.js:188:7) at process.emit (C:\workspace\ngapimock-test\node_modules\source-map-support\source-map-support.js:439:21) at process._fatalException (bootstrap_node.js:296:26) [16:06:04] E/launcher - Process exited with error code 199

[16:06:04] E/launcher - Could not select scenario [short-term] [16:06:04] E/launcher - Error: Could not select scenario [short-term] at process.on (C:\workspace\ngapimock-test\node_modules\protractor\lib\launcher.ts:187:50) at emitOne (events.js:96:13) at process.emit (events.js:188:7) at process.emit (C:\workspace\ngapimock-test\node_modules\source-map-support\source-map-support.js:439:21) at process._fatalException (bootstrap_node.js:296:26) [16:06:04] E/launcher - Process exited with error code 199

wswebcreation commented 6 years ago

Hi @mr-mateus

Can you please post your script that selects the scenario and the json file of the api you want to change?

Based on the readme you should have something like in here

mr-mateus commented 6 years ago

Hi @wswebcreation.

I have cloned the repository and followed the readme.md.

spec.ts

import { NgApimockTestPage } from './app.po';
import { browser } from 'protractor';

describe('ng-apimock-test App', () => {
  let page: NgApimockTestPage;
  let ngApimock: any = browser['ngApimock'];

  beforeEach(() => {
    page = new NgApimockTestPage();
  });

  it('should display one instalment', () => {
    ngApimock.selectScenario('api/quote-overview', 'short-term');
    page.navigateTo();
    expect(page.getInstalments().count()).toEqual(1);
  });

  it('should display three instalments', () => {
    ngApimock.selectScenario('api/quote-overview', 'flexiloan-3');
    page.navigateTo();
    expect(page.getInstalments().count()).toEqual(3);
  });

  it('should display six instalments', () => {
    ngApimock.selectScenario('api/quote-overview', 'flexiloan-6');
    page.navigateTo();
    expect(page.getInstalments().count()).toEqual(6);
  });

  it('should show an error', () => {
    ngApimock.selectScenario('api/quote-overview', 'failed');
    page.navigateTo();
    expect(page.getInstalments().count()).toEqual(0);
    expect(page.getError()).toBeTruthy();
  });
});
// Protractor configuration file, see link for more information
// https://github.com/angular/protractor/blob/master/lib/config.ts

const { SpecReporter } = require('jasmine-spec-reporter');

exports.config = {
  useAllAngular2AppRoots: true,
  allScriptsTimeout: 11000,
  specs: [
    './e2e/**/*.e2e-spec.ts'
  ],
  capabilities: {
    'browserName': 'chrome'
  },
  directConnect: true,
  // baseUrl: 'http://localhost:4200/',
  framework: 'jasmine',
  jasmineNodeOpts: {
    showColors: true,
    defaultTimeoutInterval: 30000,
    print: function() {}
  },
  beforeLaunch: function() {
    require('ts-node').register({
      project: 'e2e/tsconfig.e2e.json'
    });
  },
  onPrepare() {
    browser.ngApimock = require('./.tmp/ngApimock/protractor.mock.js');
    jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
  }
};
wswebcreation commented 6 years ago

Hi @mr-mateus

Can you also post an example of the JSON? I'm curious about the name-field of the JSON file. You now have a / in it. It could be that that is the problem.

mr-mateus commented 6 years ago

Hi,

This is the scenario

short-term.json

{ "quote": { "principal": 300, "interest": 84.32, "totalToRepay": 384.32, "instalments": [{ "paymentDate": "2017-05-01", "paymentAmount": 384.32 }], "term": 35 } }

quote-overview.json { "expression": "api/quote-overview", "method": "GET", "name": "api/quote-overview", "isArray": false, "responses": { "short-term": { "default": true, "status": 200, "headers": { "content-type": "application/json" }, "file": "mock_data/quote-overview/short-term.json" }, "flexiloan-3": { "status": 200, "headers": { "content-type": "application/json" }, "file": "mock_data/quote-overview/flexiloan-3.json" }, "flexiloan-6": { "status": 200, "headers": { "content-type": "application/json" }, "file": "mock_data/quote-overview/flexiloan-6.json" }, "failed": { "status": 401 } } }

2017-10-31 3:27 GMT-02:00 Wim Selles notifications@github.com:

Hi @mr-mateus https://github.com/mr-mateus

Can you also post an example of the JSON? I'm curious about the name-field of the JSON file. You now have a / in it. It could be that that is the problem.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/mdasberg/ng-apimock/issues/29#issuecomment-340663940, or mute the thread https://github.com/notifications/unsubscribe-auth/ARhBXUqOEqHdfcSdjQ0QFHFdoAna1cVvks5sxq-sgaJpZM4QLngS .

wswebcreation commented 6 years ago

@mr-mateus

Try camelCaseing your name and leave out the / => "name": "apiQuoteOverview" and then in your Protractor tests do this

ngApimock.selectScenario('apiQuoteOverview', 'short-term');

That should work

mr-mateus commented 6 years ago

Hi,

I tried, but get the same problem...

Could not select scenario [short-term] [13:21:15] E/launcher - Error: Could not select scenario [short-term]

import { NgApimockTestPage } from './app.po'; import { browser } from 'protractor';

describe('ng-apimock-test App', () => { let page: NgApimockTestPage; let ngApimock: any = browser['ngApimock'];

beforeEach(() => { page = new NgApimockTestPage(); });

it('should display one instalment', () => { ngApimock.selectScenario('api/quoteOverview', 'short-term'); page.navigateTo(); expect(page.getInstalments().count()).toEqual(1); });

it('should display three instalments', () => { ngApimock.selectScenario('api/quoteOverview', 'flexiloan-3'); page.navigateTo(); expect(page.getInstalments().count()).toEqual(3); });

it('should display six instalments', () => { ngApimock.selectScenario('api/quoteOverview', 'flexiloan-6'); page.navigateTo(); expect(page.getInstalments().count()).toEqual(6); });

it('should show an error', () => { ngApimock.selectScenario('api/quoteOverview', 'failed'); page.navigateTo(); expect(page.getInstalments().count()).toEqual(0); expect(page.getError()).toBeTruthy(); }); });

2017-10-31 8:06 GMT-02:00 Wim Selles notifications@github.com:

@mr-mateus https://github.com/mr-mateus

Try camelCaseing your name and leave out the / => "name": "apiQuoteOverview" and then in your Protractor tests do this

ngApimock.selectScenario('apiQuoteOverview', 'short-term');

That should work

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/mdasberg/ng-apimock/issues/29#issuecomment-340715881, or mute the thread https://github.com/notifications/unsubscribe-auth/ARhBXYazus49T4RobHlzIBXHyADzwjoQks5sxvEcgaJpZM4QLngS .

wswebcreation commented 6 years ago

@mr-mateus

You are still using a different name in your script, I mean you are still using api/quoteOverview as a reference to the API. The name of the scenario shouldn't be the problem

mdasberg commented 6 years ago

@wswebcreation nice catch. The expression is converted to a regular expression, hence using a / will not work

mr-mateus commented 6 years ago

Hi,

I searched but didn't find the meaning of error code 199. Can you help me to understanding?

I have two computers... one the protractor test works but the other give me the code 199.

2017-10-31 17:31 GMT-02:00 Mischa Dasberg notifications@github.com:

@wswebcreation https://github.com/wswebcreation nice catch. The expression is converted to a regular expression, hence using a / will not work

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/mdasberg/ng-apimock/issues/29#issuecomment-340881536, or mute the thread https://github.com/notifications/unsubscribe-auth/ARhBXe5vH6FR6nRwG6R6eUNyDT2sVaOTks5sx3WjgaJpZM4QLngS .

builtbyjay commented 6 years ago

Hi @mr-mateus - I have answered this issue here: https://github.com/builtbyjay/ngapimock-test/issues/1#issuecomment-351685345

Zima04 commented 5 years ago

any updates?

builtbyjay commented 5 years ago

Ahh sorry, it seems I've deleted the repo referenced in the link above. From what I can remember, the cause of this error was protractor HTTP requests to ng-apimock (select scenario endpoints) using the app port number rather than the port number ng-apimock is being served from.

The fix was to create a proxy rule for /ngapimock/* endpoints to use the correct port number.