cucumber stepdefinition file is not recognized by the protractor cucumber config file - protractor

unable to execute the steps in the step definition file
i tried the solutions present in the google but none of them are answer my questions.
my Config file
//seleniumAddress: 'http://localhost:4444/wd/hub',
directConnect: true,
//specs: ['/Users/bharaniravisankar/Desktop/PRO/SPECS/TEST.JS'],
framework: 'custom',
// path relative to the current config file
frameworkPath: require.resolve('protractor-cucumber-framework'),
capabilities: {
'browserName': 'chrome'
},
specs: [
'/Users/bharaniravisankar/Desktop/PRO/Feature/test.feature'
],
cucumberOpts: {
require: '/Users/bharaniravisankar/Desktop/PRO/Feature/Step Definition/login.js',
//tags: false,
//format: 'pretty',
profile: false,
'no-source': true
}
};
my console log
? Given User navigate to Home Page
Undefined. Implement with the following snippet:
Given('User navigate to Home Page', function () {
// Write code here that turns the phrase above into concrete actions
return 'pending';
});
? When User enter email and other details
Undefined. Implement with the following snippet:
When('User enter email and other details', function () {
// Write code here that turns the phrase above into concrete actions
return 'pending';
});
? And click on Submit button
Undefined. Implement with the following snippet:
When('click on Submit button', function () {
// Write code here that turns the phrase above into concrete actions
return 'pending';
});
? Then Login is created sucessfully
Undefined. Implement with the following snippet:
Then('Login is created sucessfully', function () {
// Write code here that turns the phrase above into concrete actions
return 'pending';
});
✔ After # CONG.js/node_modules/protractor-cucumber-framework/lib/resultsCapturer.js:26
1 scenario (1 undefined)
4 steps (4 undefined)
Stepdefinition file
var { Given, When, Then } = require("cucumber");
module.exports = function () {
this.Given(/^User navigate to Home Page$/, async function () {
// this.When('User enter email and other details', function () {
//launch AWS portal
browser.get('https://portal.aws.amazon.com/billing/signup#/start');
//Maximize the browser window
browser.driver.manage().window().maximize();
//Check the title of the Webpage
expect(await browser.getTitle()).toEqual('AWS Console - Signup');
});
this.When(/^User enter email and other details$/, function () {
// this.When('User enter email and other details', function () {
element(by.model('credentials.email')).sendKeys('bharaniravi36#gmail.com')
element(by.model('credentials.password')).sendKeys('Feb%1992');
element(by.model('credentials.rePassword')).sendKeys('Feb%1992');
element(by.model('credentials.fullName')).sendKeys('bharaniravi85');
});
//this.When('click on Submit button', function () {
this.When(/^click on Submit button$/, function () {
element(by.xpath("(//input[#class='a-button-input'])[1]")).click();
});
this.Then(/^Login is created sucessfully$/, function () {
expect(browser.getTitle()).toEqual('AWS Console - Signup');
element(by.id('company')).sendKeys('POLI');
//click on country drop down
element(by.model("address.countryCode")).click();
element(by.xpath("//option[#label='American Samoa']")).click();
// add sleep to give a time for te options to reveal
browser.sleep(3000)
});
};
in my research i didnt miss anything in my setup and every thing is setup in my system and required dependencies are downloaded.

First of all try creating the step definition folder outside the feature folder to keep separation of features and step definitions and folder name should be without spaces like 'stepdefinition'.
Secondly, make sure all the feature steps should be implemented in the step definition file and the text of each step should be the same as mentioned in the features.
Try using this and let me know, if it works for you.

Related

In protractor, I want the code to handle based on if OTP triggers and if not, I can login to the home page or any page and cont do the work

I am new to coding and as well as to protractor.
In protractor, I want the code to handle based on if OTP triggers go and retrieve OTP and if not, login to the home page or any page and continue to do the actions in the home page. I was trying to do an if else check with
I tried as like below
browser.getcurrentUrl().toEqual().then function()
{
statements;
},
I don't think it works. Can someone help?
below is my code snippet.
Basically i was trying to check the url, if it contains specific texts in it, I dont want anything to perform further execution want to exit out of execution. If the url doesnt contain anything specified I want to proceed with further execution.
The if condition is working fine. but not the else part.
var HomePages = require('../Pages/HomePage.js');
var EC = protractor.ExpectedConditions;
describe(‘Check_url function’, function() {
browser.wait(EC.urlContains(’some url’),2000).then(result => {
if (result) {
console.log('Sorry!!!!!!!, Encountered PassCode Authentication Process.
Execution cant be proceed further');
} else {
HomePages.profile();
browser.driver.sleep(300);
}
});
});
//////////////////////////
HomePages.js -
'use strict';
module.exports = {
Homepage: {
usrname: element(by.className('profile-name')),
usricon: element(by.css('[title="profile"]')),
Cli_id: element(by.css('[title=“Client ID"]'))
},
profile: function() {
this.click_Profile();
},
click_Profile: function() {
var angular3 = this.Homepage;
angular3.usricon.click();
},

Screenshot is not attached to report but available in 'allure-results' folder or failure Specs screenshot

In Allure Reporters [with Protractor], The screenshot which is being taken is only at the end of the test. Due to which the screenshot which is showing in the Allure Reports are of login page only and not of the application once user logged in.
Here is the code, I am using to generate the Allure Reports.
allureReporterSetup: function() {
const AllureReporter = require('jasmine-allure-reporter');
jasmine.getEnv().addReporter(new AllureReporter({
resultsDir: 'allure-results'
}));
jasmine.getEnv().afterEach(function (done) {
browser.takeScreenshot().then(function (png) {
allure.createAttachment('Screenshot', function () {
return new Buffer(png, 'base64')
}, 'image/png')();
done();
})
});
},
This may help you
onPrepare() {
var originalAddExpectationResult = jasmine.Spec.prototype.addExpectationResult;
jasmine.Spec.prototype.addExpectationResult = function () {
if (!arguments[0]) {
browser.takeScreenshot().then(function (png) {
allure.createAttachment('Screenshot', function () {
return new Buffer(png, 'base64')
}, 'image/png')();
})
}
return originalAddExpectationResult.apply(this, arguments);
};
var AllureReporter = require('jasmine-allure-reporter');
jasmine.getEnv().addReporter(new AllureReporter({
resultsDir: 'allure-results',
}));
}
As I understand Protractor is a tool for testing Angular JS web sites. It's quite like the Selenium so it is not anyhow connected with your issue.
Your issue is connected with a testing framework that you use.
What happens now is your screenshot is probably taken at the end of a test (after scenario/after test) or even after test suite.
What you need is to take the screenshot right after test step or even right after a test failure. I guess after your test failure some teardown actions are performed. The thing is you need to take a screenshot before those actions. This way it will be taken in time.

e2e Testing in protractor. SignIn

I am not able to redirect on required page on sigIn page. It clicks on button but not giving the output as required. Not able to hit the server for further process after signin process.Plz help
describe("it should be able to run on different events as defined", function(){
it("should be get on browser", function(){
browser.get("http://www.localhost:8100/#/signin");
expect(browser.getCurrentUrl()).toEqual("http://www.localhost:8100/#/signin");
browser.sleep(2000);
element(by.css("[ng-model='user.email']")).sendKeys('ash.mat23.23#gmail.com');
element(by.css("[ng-model='user.email']")).getAttribute('placeholder').then(function(element){
expect(element).toEqual('Email');
browser.sleep(2000);
});
element(by.css("[ng-model='user.password']")).sendKeys('123456');
element(by.css("[ng-model='user.password']")).getAttribute('placeholder').then(function(element){
expect(element).toEqual('Password (at least 6 characters)');
browser.sleep(2000);
});
element(by.id('signin_submit_btn'));
browser.driver.actions().sendKeys(protractor.Key.ENTER).perform();
browser.sleep(5000);
});
});
Are you sure it's clicking the button properly? To my mind the line that reads:
element(by.id('signin_submit_btn'));
Should have a click event on the end, i.e. it should read:
element(by.id('signin_submit_btn')).click();
I'm not completely sure what you are asking. It looks to me that you are preforming all actions at the same time. You should make sure filling in the username and password is done before clicking on submit or pressing enter. I hope this helps:
describe("it should be able to run on different events as defined", function () {
it("should be get on browser", function () {
browser.get("http://www.localhost:8100/#/signin").then(() => {
expect(browser.getCurrentUrl()).toEqual("http://www.localhost:8100/#/signin");
Promise.all([
$("[ng-model='user.email']").sendKeys('ash.mat23.23#gmail.com'),
$("[ng-model='user.password']").sendKeys('123456'),
$("[ng-model='user.email']").getAttribute('placeholder').then(function (element) {
expect(element).toEqual('Email');
}),
$("[ng-model='user.password']").getAttribute('placeholder').then(function (element) {
expect(element).toEqual('Password (at least 6 characters)');
})
]).then(()=>{
$('#signin_submit_btn').click(); // or browser.driver.actions().sendKeys(protractor.Key.ENTER).perform();
})
})
});
});

Clicking buttons after a modal event with protractor

I'm having a problem clicking on a button that is on a modal or on a page after a modal is supposed to have been closed. Here is my experience:
I have a modal i'm dealing with. I create the actions to have it displayed. I have a wait function that waits for one of the modal's items to be "clickable" (This allows it to be both present and displayed). I then verify the text on the modal.
All of the above is successful. However, when I try to click on the button to close it, I'm getting an error stating that another element on the page would be clickable. I'm thinking I need to disable angular (and CSS?) animation. Is this answer still relevant to the latest version of protractor?
How to disable animations in protractor for angular js application
The problem I have with the above answer is that typescript didn't recognize the "angular" object.
I also see this question: Click on a button in a Modal Window - Protractor But the "answer" is to sleep for 2 seconds. Not my desired solution (if at all possible).
In any case, I found a way to reproduce what I'm talking about. The following spec will load the angular materials page to the dialog demo page. It will click on the Confirm Dialog button, verify the header text on the modal, click the close button, then try to repeat the steps a second time. It fails on the second time, even though it is supposed to have waited until the button is clickable.
/**
* modal.conf.js
*/
exports.config = {
framework: 'jasmine',
specs: ['modal.spec.js'],
useAllAngular2AppRoots: false,
jasmineNodeOpts: {
'stopSpecOnExpectationFailure': true,
showColors: true
}
};
'use strict';
/**
* modal.spec.js
*/
var headerText = "Would you like to delete your debt?";
describe('Click Modal and Close test', function () {
beforeAll(function () {
browser.get('https://material.angularjs.org/latest/demo/dialog')
});
it('should click to open modal', function () {
confirmBtn.click().then(function () {
WaitForLoad(cancelBtn).then(function () {
expect(headerTextEl).toEqual(headerTextEl);
});
});
});
it('should click to close modal', function () {
cancelBtn.click().then(function () {
WaitForLoad(confirmBtn);
});
});
it('should click to open modal', function () {
confirmBtn.click().then(function () {
WaitForLoad(cancelBtn).then(function () {
expect(headerTextEl).toEqual(headerTextEl);
});
});
});
it('should click to close modal', function () {
cancelBtn.click().then(function () {
WaitForLoad(confirmBtn);
});
});
});
// region Page Objects
var confirmBtn = $('.layout-margin > button:nth-child(2)');
var headerTextEl = $('.md-title');
var cancelBtn = $('button.md-cancel-button');
// endregion
// region actions
var WaitForLoad = function (el, timeout) {
var EC = protractor.ExpectedConditions;
return browser.wait(EC.elementToBeClickable(el), timeout);
};
// endregion

Protractor: inconsistent test reports?

Testing an angular app, the test are sometimes passing and sometimes failing...
My test cases look like:
it('test-1: should has main button', function () {
expect(page.demoButton).not.toBeUndefined();
});
it('test-2: should open modal on click secondary button', function () {
page.demoButton.click().then(function () {
page.SecondaryButton.click().then(function() {
expect(page.Modal).not.toBeUndefined();
});
});
});
it('test-3: should open modal with correct text', function () {
page.demoButton.click().then(function () {
page.SecondaryButton.click().then(function() {
expect(page.Modal.text.getText()).toEqual('Are you sure to cancel
this?');
});
});
});
If I run the test, sometimes the tests are passed sometimes some of them get failed..
Most of the time error is like: No element found using locator: By.cssSelector(".myButton"). or Cannot read property 'getText' of undefined
Thank you in advance!
I fixed that issue with using:
browser.waitForAngular();
As I see that issue occurs with getText and click events, So:
it('test-2: should open modal on click secondary button', function () {
page.demoButton.click().then(function () {
browser.waitForAngular();
page.SecondaryButton.click().then(function() {
browser.waitForAngular();
expect(page.Modal.text.getText()).toEqual('Are you sure to cancel
this?');
});
});
});
was the solution.