Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Could not select scenario in Protractor #61

Open
pezholio opened this issue Sep 28, 2018 · 6 comments
Open

Could not select scenario in Protractor #61

pezholio opened this issue Sep 28, 2018 · 6 comments

Comments

@pezholio
Copy link

Hi,

I'm trying to use ng-apimock with Protractor in an Ionic project. After a few false starts, I think I'm almost there, but I'm getting the error Could not select scenario [get-single-case] thrown when trying to use my mocks.

Here's my protractor.conf.js:

// 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 = {
  allScriptsTimeout: 11000,
  specs: [
    './src/**/*.e2e-spec.ts'
  ],
  capabilities: {
    'browserName': 'chrome'
  },
  directConnect: true,
  baseUrl: 'http://localhost:4200/',
  framework: 'jasmine',
  jasmineNodeOpts: {
    showColors: true,
    defaultTimeoutInterval: 30000,
    print: function() {}
  },
  onPrepare() {
    require('ts-node').register({
      project: 'e2e/tsconfig.e2e.json'
    });
    
    var ngApimock = require('ng-apimock')();

    ngApimock.run({
      "src": "e2e/mocks",
    });
    
    jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
    browser.ngApimock = require('../.tmp/mocks/protractor.mock.js');
  },
  ngApimockOpts: {
    angularVersion: 6,
    hybrid: false
  }
};

And here's a mock:

{
  "expression": "/cases/fdaacd04-7125-117a-ac6d-45a68b1d5de1",
  "method": "GET",
  "name": "case",
  "responses": {
    "get-single-case": {
      "default": true,
      "status": 200,
      "data": {
      ...
      }
    }
  }
}

(I've left the actual data out for brevity)

And here's my tests:

import { CasePage } from './case.po';
import { browser, ExpectedConditions, $ } from 'protractor';

describe('Case information', () => {
  let page: CasePage;

  beforeEach(() => {
    browser['ngApimock'].selectScenario('case', 'get-single-case');
    page = new CasePage();
    page.get();
  });
  
  describe('Listing cases', () => {
    it('should list cases', () => {
      var cases = page.getListofCases();
      expect(cases.count()).toEqual(20);
    });
  });
  
  describe('Show case detail', () => {
    it('should show case information', () => {
      page.clickFirstCase().then(function() {
        expect(page.getHeaderText()).toMatch(/Visit details/);
      });
    })
  });
});

Any help would be appreciated!

@pezholio pezholio changed the title Could not select scenario Could not select scenario in Protractor Sep 28, 2018
@mdasberg
Copy link
Owner

mdasberg commented Oct 1, 2018

@pezholio could you try and chain your selectScenario promise.
It is an async call so it could be that the scenario has not been set yet befor you doe a page.get()

@pezholio
Copy link
Author

pezholio commented Oct 5, 2018

I've tried this in my page object:

browser['ngApimock'].selectScenario('case', 'get-single-case').then(function() {
  this.navigateTo('/cases/fdaacd04-7125-117a-ac6d-45a68b1d5de1');
});

And I still get the same Could not select scenario [get-single-case] error

@pezholio
Copy link
Author

pezholio commented Oct 5, 2018

Here's some more detailed output:

Jasmine started

  Case information

    Show case detail
      ✓ should show case information

Executed 1 of 1 spec SUCCESS in 0.014 sec.
[11:47:58] E/launcher - Could not select scenario [get-single-case]
[11:47:58] E/launcher - Error: Could not select scenario [get-single-case]
    at process.on (/Users/stuart/Documents/FamilyStoryUI/fsIonic/node_modules/protractor/built/launcher.js:177:52)
    at process.emit (events.js:180:13)
    at process.emit (/Users/stuart/Documents/FamilyStoryUI/fsIonic/node_modules/protractor/node_modules/source-map-support/source-map-support.js:439:21)
    at process.emit (/Users/stuart/Documents/FamilyStoryUI/fsIonic/node_modules/source-map-support/source-map-support.js:461:21)
    at process._fatalException (internal/bootstrap/node.js:391:27)
[11:47:58] E/launcher - Process exited with error code 199

Weirdly, the test seems to pass, but I don't see any output in Chrome

@marcioferlan
Copy link

@pezholio can you please share the setup for running ng-apimock on your Ionic 3 project? Like the dependencies you installed, the setup for tslint, protractor and jasmine.. as well as a simple test case in which you managed to select the scenario properly? I'm trying it for a couple hours now with no success yet.
Thanks in advance!

@pezholio
Copy link
Author

pezholio commented Mar 5, 2019

Thanks, but I ended up going down a different route for this, using a live test API, and creating/deleting everything I needed as part of the setup/teardown routine.

@julissamackey
Copy link

julissamackey commented Apr 23, 2019

Hi @marcioferlan @mdasberg I am also receiving this error using Protractor

Could not select scenario [success] thrown

Here is my setup:
My Protractor Config

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

exports.config = {
	allScriptsTimeout: 30000,
	specs: [
		'./source/client/test/ui-tests/spec-files/*/*.ui-spec.ts'
	],
	capabilities: {
		browserName: 'chrome',
		chromeOptions: {
			// args: ["--headless", "--disable-gpsu"] 
		}
	},
	directConnect: true,
	jasmineNodeOpts: {
		showColors: true,
		defaultTimeoutInterval: 60000,
		print: function () { }
	},
	onPrepare() {

		require('ts-node').register({
			project: './source/client/test/ui-tests/tsconfig.e2e.json'
		});

		jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
		
		var ngApimock = require('ng-apimock')();
		ngApimock.run({
			"src": "./source/client/test/ui-tests/mock-api-responses",
		  });
		browser.ngApimock = require('./.tmp/mocks/protractor.mock.js');
		
	},
	ngApimockOpts: {
		angularVersion: 7,
		hybrid: false
	},
	specReporter: {
		maxLogLines: 5,  // limit number of lines logged per test
		suppressErrorSummary: false,  // do not print error summary
		suppressFailed: false,  // do not print information about failed tests
		suppressPassed: false,  // do not print information about passed tests
		suppressSkipped: true,  // do not print information about skipped tests
		showSpecTiming: false // print the time elapsed for each spec
	}
};

My mock

{
	"expression": "/billing/customers/search",
	"method": "POST",
	"body": {"LastName":"kop"},
	"name": "partialNameMatch",
	"responses": {
	  "success": {
		"default": true, 
		"status": 200, 
		"headers": {},
		"data": {"Customers": [--omitted for brevity --]}, 
		"delay": 2000
	  }
	}
  }

Where I am selecting the scenario [ Page Object ]

navigateToSubscriberSearch(){
		return browser['ngApimock'].selectScenario('partialNameMatch', 'success').then(()=>{
			browser.get('/subscribers/search');
		});
	}

Any thoughts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants