yanweiyuan3
2023-08-09 588bc7829387dfc761cc25f06f77d4c81818bd10
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { DateTimeSelector } from '../e2elib/lib/src/pageobjects/datetimeselector.component';
import { Month } from './timeutils';
import { by, browser } from '../e2elib/node_modules/protractor';
 
export class DateTimeSelectorBase extends DateTimeSelector {
  /**
   * Get date from datetime selector
   */
  public async getDate(): Promise<Date> {
    const year = Number(await this.getYear());
    const month = Month[await this.getMonth()];
    const day = Number(await this.getDay());
    return new Date(year, month, day);
  }
 
  /**
   * Get datetime from datetime selector
   */
  public async getDateTime(): Promise<Date> {
    const year = Number(await this.getYear());
    const month = Month[await this.getMonth()];
    const day = Number(await this.getDay());
    const hour = Number(await this.getHour());
    const minute = Number(await this.getMinute());
    const second = Number(await this.getSecond());
    return new Date(year, month, day, hour, minute, second);
  }
 
  /**
   * Set the day, month and year value
   *
   * @param date date value
   */
  public async setDate(date: Date): Promise<void> {
    /* await this.setDay(date.getDate().toString());
    await this.setMonth((date.getMonth() + 1).toString());
    await this.setYear(date.getFullYear().toString());*/
    // Temp unblock software issue (invalid character in datetime after setting value causing test to fail)
    await browser
          .actions()
          .click(this.element.element(by.css('.qDInput')))
          .perform()
          .then(() => {
            return this.element.element(by.css('.qDInput')).sendKeys(date.getDate().toString());
          });
 
    await browser.sleep(1000);
    await browser
    .actions()
    .click(this.element.element(by.css('.qMInput')))
    .perform()
    .then(() => {
      return this.element.element(by.css('.qMInput')).sendKeys((date.getMonth() + 1).toString());
    });
 
    await browser.sleep(1000);
    await browser
    .actions()
    .click(this.element.element(by.css('.qYInput')))
    .perform()
    .then(() => {
      return this.element.element(by.css('.qYInput')).sendKeys(date.getFullYear().toString());
    });
  }
}