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

Protractor not able to run tests with ngApimock #12

Closed Tipster74743 closed 7 years ago

Tipster74743 commented 7 years ago

I'm getting an error as soon as the spec starts when running protractor 5.1.1

[09:15:44] E/launcher - Could not select scenario [success] [09:15:44] E/launcher - Error: Could not select scenario [success] at process.on (C:\Program Files (x86)\Nodist\bin\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:\Users\bim4\mgo-api\src\main\client\node_modules\source-map-support\source-map-support.js:430:21) at process.emit (C:\Program Files (x86)\Nodist\bin\node_modules\protractor\node_modules\source-map-support\source-map-support.js:430:21) at process._fatalException (bootstrap_node.js:292:26) [09:15:44] E/launcher - Process exited with error code 199

The test looks like:

it('should load the payment-list page', () => { browser['ngApimock'].selectScenario('api/v1/consumer', 'success'); let happyUser = page.getHappyUser(); page.navigateTo(happyUser); });

I'm using angular-cli and used the same setup as the issue in https://github.com/mdasberg/ng-apimock/issues/10

The expression is named api/v1/consumer and the name is consumer. I've tried both of those as the first argument in selectScenario. The Scenario is named 'success'. If I leave the second argument blank I get a "Could not select scenario 'undefined'." What am I doing wrong?

wswebcreation commented 7 years ago

@Tipster74743

Can you post the json you want to use. Each json should have a name:"api-name" to identify it. It now looks you are referring to the expression.

Tipster74743 commented 7 years ago

Yeah, I actually was able to change it after seeing that the basepath was going to localhost:4200 instead of localhost:3000.

Here is the json, though:

 {
  "expression": "api/v1/consumer",
  "method": "GET",
  "name": "getUserInformation",
  "isArray": false,
  "responses": {
    "success": {
      "default": true,
      "status": 200,
      "headers": {},
      "data": {},
      "file": "",
      "statusText": ""
    }
  }
}

The protractor test actually loads now with that change. Is there a way to get it to stay on 3000 instead of 4200?

Tipster74743 commented 7 years ago

Also, speaking of expressions, does it have to match the entire name of the http request? For example, in my first question, it shows 'api/v1/consumer'. Do I need the full path for this? Or should I expect the plugin to spot just that portion? Debugging, it looks like it's still working like normal.

wswebcreation commented 7 years ago

Sorry for the late reaction, didn't notices both your question.

Question portnumber: The protractor test actually loads now with that change. Is there a way to get it to stay on 3000 instead of 4200? Can you give your config of protractor and your config of the server you are starting? It looks that there is a difference between them.

Question expression: According to the readme: "expression": "your expression here (ie a regex without the leading and trailing '/' or a string)", So it matches using a regular expression. To test if all work I often use this online tool. When you have only a few services the regex can be very simple, but when you have a lot of services it can be useful to use a stricter expression.

mdasberg commented 7 years ago

@Tipster74743

Question portnumber: When using the angular-cli setup, your api can both be accessed under localhost:4200 and localhost:3000.

This is because you run the mocks as a separate server which runs by default on 3000, and you proxy the requests from the angular-cli serve which runs by default on 4200.

Tipster74743 commented 7 years ago

@wswebcreation I think that did it. I totally glanced over the baseURL in the protractor config.