1

Help, please,to correctly write a test of datepicker. I have an unclickable field where my selected date will be set:

<input type="text" class="submit hasDatepicker" placeholder="License Expiry Date*" 
name="website_field[bGl==]" 
id="website_field_bGl" value="" size="16" 
readonly="readonly">

with clickable button that opens a date-form:

<img class="ui-datepicker-trigger" src="images/calendar.png" alt="Select date" 
title="Select date">

month:

<select class="ui-datepicker-month" data-handler="selectMonth" data- 
event="change"><option value="0">Jan</option></select> ...

year:

<select class="ui-datepicker-year" data-handler="selectYear" data- 
event="change"><option value="2000">2000</option></select> ...

and a script:

                    $(function(){
                        $( "#website_field_bGljZW5zZSBleHBpcnkgZGF0ZQ" 
).datepicker({
                            changeMonth: true,
                            changeYear: true,
                            firstDay:1,
                            dateFormat: "yy-mm-dd",
                            showOn: "button",
                            buttonImage: "images/calendar.png",
                            buttonImageOnly: true,
                            buttonText: "Select date",
                            minDate: "2000-01-01",
                            yearRange: "2000:+15"
                        }).attr("readonly", "readonly");
                    });

I need to set a date, for example: 2020-07-14.

How to do this? Thanks.

I did smth primitive and it works. But maybe there is more 'pro' variant available?:

    var LicenceExpiryDateInputField = 
    element(by.id('website_field_bGljZW5zZSBleHBpcnkgZGF0ZQ'));
    var LicenceExpiryDateButton = $('img.ui-datepicker-trigger');
    var LicenceExpiryDateForm = element(by.id('ui-datepicker-div'));
    var SelectMonth = $('select.ui-datepicker-month').$('[value="6"]');
    var SelectYear = $('select.ui-datepicker-year').$('[value="2020"]');
    var SelectDate = element(by.linkText('14')); 

    LicenceExpiryDateButton.click();
        expect(LicenceExpiryDateForm.isPresent()).toBe(true);
    SelectMonth.click();
        expect(SelectMonth.isSelected()).toBe(true);
        expect(SelectMonth.getText()).toEqual('Jul');
    SelectYear.click();
        expect(SelectYear.isSelected()).toBe(true);
        expect(SelectYear.getText()).toBe('2020');
    SelectDate.click();
    expect(...Here i need to check somehow LicenceExpiryDateInputField on correct data (2020-07-14)...)
  • Check [this ticket](https://stackoverflow.com/questions/19599450/how-to-select-option-in-drop-down-protractorjs-e2e-tests) – Andersson Nov 05 '18 at 10:21
  • I wrote some code with chosen Options and it works (please, check my Edit Question). But maybe there is more 'pro' variant available? – Ekaterina Salazkina Nov 05 '18 at 10:39
  • If you want to check that selected date is correctly displayed, try to get attribute `value` of `input.submit.hasDatepicker` – Andersson Nov 05 '18 at 10:42
  • I thought to do this, as i thought that value="" will become as value='2020-07-14'. But it's still empty. Nothing change in that Input string. That Input before my date selection is equal to Input after my date selection.. – Ekaterina Salazkina Nov 05 '18 at 10:54
  • *i'm about Input string – Ekaterina Salazkina Nov 05 '18 at 10:55
  • Did you check the same in code? Note that visually (if you ckeck `value` attribute in DOM with browser dev tools) it won't be changed (`value=""` as before), however appropriate code will get actual value – Andersson Nov 05 '18 at 11:03
  • Ok. I left this issue for some time. And decided just to check InvisibilityOf form: SelectDate.click(); browser.wait(EC.invisibilityOf(LicenceExpiryDateForm), 2000); expect(LicenceExpiryDateForm.isPresent()).toBeFalsy(); – Ekaterina Salazkina Nov 05 '18 at 11:47
  • Hmm... Not the best way to test DropDown IMHO :) If it's because you don't know how to check `value` , then [this](https://stackoverflow.com/questions/20310442/how-to-gettext-on-an-input-in-protractor) might help – Andersson Nov 05 '18 at 11:50
  • You meant like this: expect(LicenceExpiryDateForm.getAttribute('value')).toEqual('2020-07-14'); ? I have an error: Expected null to equal '2020-07-14'. – Ekaterina Salazkina Nov 05 '18 at 12:36
  • 2
    Yes, but `element(by.id("website_field_bGl")).getAttribute('value')` instead of `LicenceExpiryDateForm.getAttribute('value')` – Andersson Nov 05 '18 at 12:44
  • Wow! You are awesome! :) It works as i wanted. Thank you ;) – Ekaterina Salazkina Nov 05 '18 at 13:06

0 Answers0