Reputation: 2750
I was wondering if it's possible to use Jasmine library when using protractor and cucumber.
protractor.conf.js
:
exports.config = {
allScriptsTimeout: 11000,
specs: [
'./src/features/*.feature'
],
capabilities: {
'browserName': 'chrome'
},
directConnect: true,
framework: 'custom',
frameworkPath: require.resolve('protractor-cucumber-framework'),
cucumberOpts: {
require: './src/steps/**/*.ts',
},
onPrepare() {
require('ts-node').register({
project: 'e2e/tsconfig.e2e.json'
});
}
};
tsconfig.e2e.json
:
{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "../out-tsc/app",
"module": "commonjs",
"target": "es5",
"types": [
"jasmine",
"node"
]
}
}
My steps definition:
import { ChangeProfilePage } from './change-profile.po';
import { When, Then, Before } from 'cucumber';
let page: ChangeProfilePage;
Before(() => {
page = new ChangeProfilePage();
page.goToChangeProfile();
page.init();
});
When('The user fills in the form with valid inputs', () => {
page.setFaroId("123BA");
page.setFirstName("Baptiste");
page.setLastName("Arnaud");
page.setEmail("[email protected]");
page.setAdmin(true);
});
Then('The user clicks on the submit button', () => {
page.submitForm();
});
Then('The user should see the {string} indicator', (string) => {
expect(page.getSubmitMessage()).toEqual(true);
});
It prints out a Warning:
DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
And it says expect is not defined
.
What do I do wrong here? Also, the browser opens up and isn't redirecting to desire location. There's data:,
in the url tab. What does it mean?
Upvotes: 0
Views: 437
Reputation: 13712
If you use cucumber as test framework, you can't use Jasmine without import it.
From your given code, you want to use the assertion api: expect
supplied by Jasmine in your cucumber test script. Actually, you can use other assertion lib instead.
Like chai
and chai-as-promised
which is independent on any test framework.
// conf.js
exports.config = {
onPrepare: function() {
var chai = require('chai');
chai.use(require('chai-as-promised'));
global.expect = chai.expect;
}
};
// test script
// validate non-promise value (can't use `eventually`)
expect('a string').to.equal('b string');
// validate promise value (must use `eventually`)
expect(xx.getText()).to.eventually.equal('yyyyy')
Upvotes: 1