How to test date picker using protractor?
I'm testing date picker which used ngbDatepicker and it only allows the user to pick the date from the calendar. Is there any possible way to pick a date from this using protractor?
<form class="form-inline">
<div class="form-group">
<div class="input-group">
<input class="form-control" placeholder="yyyy-mm-dd"
name="dp" [(ngModel)]="model" ngbDatepicker #d="ngbDatepicker">
<div class="input-group-append">
<button class="btn btn-outline-secondary calendar" (click)="d.toggle()" type="button"></button>
</div>
</div>
</div>
</form>
This is the screenshot of the date picker:
What I need is to select the day after today in the datepicker.
Thanks in advance!!
angular typescript protractor e2e-testing
add a comment |
I'm testing date picker which used ngbDatepicker and it only allows the user to pick the date from the calendar. Is there any possible way to pick a date from this using protractor?
<form class="form-inline">
<div class="form-group">
<div class="input-group">
<input class="form-control" placeholder="yyyy-mm-dd"
name="dp" [(ngModel)]="model" ngbDatepicker #d="ngbDatepicker">
<div class="input-group-append">
<button class="btn btn-outline-secondary calendar" (click)="d.toggle()" type="button"></button>
</div>
</div>
</div>
</form>
This is the screenshot of the date picker:
What I need is to select the day after today in the datepicker.
Thanks in advance!!
angular typescript protractor e2e-testing
add a comment |
I'm testing date picker which used ngbDatepicker and it only allows the user to pick the date from the calendar. Is there any possible way to pick a date from this using protractor?
<form class="form-inline">
<div class="form-group">
<div class="input-group">
<input class="form-control" placeholder="yyyy-mm-dd"
name="dp" [(ngModel)]="model" ngbDatepicker #d="ngbDatepicker">
<div class="input-group-append">
<button class="btn btn-outline-secondary calendar" (click)="d.toggle()" type="button"></button>
</div>
</div>
</div>
</form>
This is the screenshot of the date picker:
What I need is to select the day after today in the datepicker.
Thanks in advance!!
angular typescript protractor e2e-testing
I'm testing date picker which used ngbDatepicker and it only allows the user to pick the date from the calendar. Is there any possible way to pick a date from this using protractor?
<form class="form-inline">
<div class="form-group">
<div class="input-group">
<input class="form-control" placeholder="yyyy-mm-dd"
name="dp" [(ngModel)]="model" ngbDatepicker #d="ngbDatepicker">
<div class="input-group-append">
<button class="btn btn-outline-secondary calendar" (click)="d.toggle()" type="button"></button>
</div>
</div>
</div>
</form>
This is the screenshot of the date picker:
What I need is to select the day after today in the datepicker.
Thanks in advance!!
angular typescript protractor e2e-testing
angular typescript protractor e2e-testing
asked 2 days ago
Sanjani Gunathilaka
358
358
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
Yes, it is possible to pick date using protractor. You can simulate all the behaviors which the user can do.
Since, you have not provided e2e test source code. Below points will guide you in writing e2e tests for datepicker.
const EC = protractor.ExpectedConditions;
browser.wait(EC.presenceOf(element(by.css('btn-outline-secondary'))), 5000).then(() => {
element(by.css('btn-outline-secondary')).click(); // This will click calendar icon
const d = new Date().getDate()+1; // This will get you next day value
// Write your code to find next day element and click it using click() function
// Hint: Each day is a "div" with class "btn-light" and day as content of that div element
});
EC.presenceOf()
will check whether calendar icon button is present or not (and will timeout after 5 seconds).
If it is present, then it will click that icon. So, calendar will open.
Now, your task is to identify the next day and select it.
Identification of next day can be done, using getDate()
function, as shown above.
Selecting it can also be done easily, with the hints given above.
I got the date element using XPath after referring to your answer. It worked well! Thank you!!
– Sanjani Gunathilaka
2 days ago
add a comment |
you can directly sendkeys to the input for this date.
Its tricky about the format. From the screenshot i can see its day / month / year
Try the following code:
you will need momentjs package: https://www.npmjs.com/package/moment
Here is information about moment date formatter: https://devhints.io/moment
const datenow = new Date();
datenow.setDate(datenow.getDate() + 1); // today + 1 day.
const moment = require('moment');
// format the date to string.
const formatedDate = moment(datenow).format('D MMM YYYY');
// send the formated date to the input.
element(by.xpath('//input[@class='form-control']')).sendKeys(formatedDate);
Note: adapt it to your needs, this is just example how to handle date picker.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53945417%2fhow-to-test-date-picker-using-protractor%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Yes, it is possible to pick date using protractor. You can simulate all the behaviors which the user can do.
Since, you have not provided e2e test source code. Below points will guide you in writing e2e tests for datepicker.
const EC = protractor.ExpectedConditions;
browser.wait(EC.presenceOf(element(by.css('btn-outline-secondary'))), 5000).then(() => {
element(by.css('btn-outline-secondary')).click(); // This will click calendar icon
const d = new Date().getDate()+1; // This will get you next day value
// Write your code to find next day element and click it using click() function
// Hint: Each day is a "div" with class "btn-light" and day as content of that div element
});
EC.presenceOf()
will check whether calendar icon button is present or not (and will timeout after 5 seconds).
If it is present, then it will click that icon. So, calendar will open.
Now, your task is to identify the next day and select it.
Identification of next day can be done, using getDate()
function, as shown above.
Selecting it can also be done easily, with the hints given above.
I got the date element using XPath after referring to your answer. It worked well! Thank you!!
– Sanjani Gunathilaka
2 days ago
add a comment |
Yes, it is possible to pick date using protractor. You can simulate all the behaviors which the user can do.
Since, you have not provided e2e test source code. Below points will guide you in writing e2e tests for datepicker.
const EC = protractor.ExpectedConditions;
browser.wait(EC.presenceOf(element(by.css('btn-outline-secondary'))), 5000).then(() => {
element(by.css('btn-outline-secondary')).click(); // This will click calendar icon
const d = new Date().getDate()+1; // This will get you next day value
// Write your code to find next day element and click it using click() function
// Hint: Each day is a "div" with class "btn-light" and day as content of that div element
});
EC.presenceOf()
will check whether calendar icon button is present or not (and will timeout after 5 seconds).
If it is present, then it will click that icon. So, calendar will open.
Now, your task is to identify the next day and select it.
Identification of next day can be done, using getDate()
function, as shown above.
Selecting it can also be done easily, with the hints given above.
I got the date element using XPath after referring to your answer. It worked well! Thank you!!
– Sanjani Gunathilaka
2 days ago
add a comment |
Yes, it is possible to pick date using protractor. You can simulate all the behaviors which the user can do.
Since, you have not provided e2e test source code. Below points will guide you in writing e2e tests for datepicker.
const EC = protractor.ExpectedConditions;
browser.wait(EC.presenceOf(element(by.css('btn-outline-secondary'))), 5000).then(() => {
element(by.css('btn-outline-secondary')).click(); // This will click calendar icon
const d = new Date().getDate()+1; // This will get you next day value
// Write your code to find next day element and click it using click() function
// Hint: Each day is a "div" with class "btn-light" and day as content of that div element
});
EC.presenceOf()
will check whether calendar icon button is present or not (and will timeout after 5 seconds).
If it is present, then it will click that icon. So, calendar will open.
Now, your task is to identify the next day and select it.
Identification of next day can be done, using getDate()
function, as shown above.
Selecting it can also be done easily, with the hints given above.
Yes, it is possible to pick date using protractor. You can simulate all the behaviors which the user can do.
Since, you have not provided e2e test source code. Below points will guide you in writing e2e tests for datepicker.
const EC = protractor.ExpectedConditions;
browser.wait(EC.presenceOf(element(by.css('btn-outline-secondary'))), 5000).then(() => {
element(by.css('btn-outline-secondary')).click(); // This will click calendar icon
const d = new Date().getDate()+1; // This will get you next day value
// Write your code to find next day element and click it using click() function
// Hint: Each day is a "div" with class "btn-light" and day as content of that div element
});
EC.presenceOf()
will check whether calendar icon button is present or not (and will timeout after 5 seconds).
If it is present, then it will click that icon. So, calendar will open.
Now, your task is to identify the next day and select it.
Identification of next day can be done, using getDate()
function, as shown above.
Selecting it can also be done easily, with the hints given above.
answered 2 days ago
Saddam Pojee
4635
4635
I got the date element using XPath after referring to your answer. It worked well! Thank you!!
– Sanjani Gunathilaka
2 days ago
add a comment |
I got the date element using XPath after referring to your answer. It worked well! Thank you!!
– Sanjani Gunathilaka
2 days ago
I got the date element using XPath after referring to your answer. It worked well! Thank you!!
– Sanjani Gunathilaka
2 days ago
I got the date element using XPath after referring to your answer. It worked well! Thank you!!
– Sanjani Gunathilaka
2 days ago
add a comment |
you can directly sendkeys to the input for this date.
Its tricky about the format. From the screenshot i can see its day / month / year
Try the following code:
you will need momentjs package: https://www.npmjs.com/package/moment
Here is information about moment date formatter: https://devhints.io/moment
const datenow = new Date();
datenow.setDate(datenow.getDate() + 1); // today + 1 day.
const moment = require('moment');
// format the date to string.
const formatedDate = moment(datenow).format('D MMM YYYY');
// send the formated date to the input.
element(by.xpath('//input[@class='form-control']')).sendKeys(formatedDate);
Note: adapt it to your needs, this is just example how to handle date picker.
add a comment |
you can directly sendkeys to the input for this date.
Its tricky about the format. From the screenshot i can see its day / month / year
Try the following code:
you will need momentjs package: https://www.npmjs.com/package/moment
Here is information about moment date formatter: https://devhints.io/moment
const datenow = new Date();
datenow.setDate(datenow.getDate() + 1); // today + 1 day.
const moment = require('moment');
// format the date to string.
const formatedDate = moment(datenow).format('D MMM YYYY');
// send the formated date to the input.
element(by.xpath('//input[@class='form-control']')).sendKeys(formatedDate);
Note: adapt it to your needs, this is just example how to handle date picker.
add a comment |
you can directly sendkeys to the input for this date.
Its tricky about the format. From the screenshot i can see its day / month / year
Try the following code:
you will need momentjs package: https://www.npmjs.com/package/moment
Here is information about moment date formatter: https://devhints.io/moment
const datenow = new Date();
datenow.setDate(datenow.getDate() + 1); // today + 1 day.
const moment = require('moment');
// format the date to string.
const formatedDate = moment(datenow).format('D MMM YYYY');
// send the formated date to the input.
element(by.xpath('//input[@class='form-control']')).sendKeys(formatedDate);
Note: adapt it to your needs, this is just example how to handle date picker.
you can directly sendkeys to the input for this date.
Its tricky about the format. From the screenshot i can see its day / month / year
Try the following code:
you will need momentjs package: https://www.npmjs.com/package/moment
Here is information about moment date formatter: https://devhints.io/moment
const datenow = new Date();
datenow.setDate(datenow.getDate() + 1); // today + 1 day.
const moment = require('moment');
// format the date to string.
const formatedDate = moment(datenow).format('D MMM YYYY');
// send the formated date to the input.
element(by.xpath('//input[@class='form-control']')).sendKeys(formatedDate);
Note: adapt it to your needs, this is just example how to handle date picker.
answered 2 days ago
Infern0
1,094213
1,094213
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53945417%2fhow-to-test-date-picker-using-protractor%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown