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
/**
 * @file Dialog form component base class
 * @description Intialize dialog form by passing in DialogForm name and OK / Cancel button name.
 * Allow to check whether Ok button is clickable and perform click action of OK / Cancel button.
 * @author      Wong Jia Hui (jiahui.wong@3ds.com)
 * @copyright   Dassault Systèmes
 */
import { Form } from '../e2elib/lib/src/pageobjects/form.component';
import { ButtonBase } from './buttonbase';
 
export class DialogBase extends Form {
  // Buttons
  public btnOk: ButtonBase;
  public btnCancel: ButtonBase;
 
  /**
   * To initialize dialog by pass-in dialog name
   *
   * @param dialogName Name of dialog to initialize
   * @param btnOkName Button name of positive action to save changes
   * @param btnCancelName Button name of negative action to cancel changes
   */
  public constructor(dialogName: string, btnOkName: string, btnCancelName: string) {
    super(dialogName);
 
    // Initialize ok and cancel button in a dialog
    this.btnOk = new ButtonBase(btnOkName);
    this.btnCancel = new ButtonBase(btnCancelName);
  }
 
  /**
   * Perform click action on Ok button if it is clickable
   *
   * @param waitTime [Optional] miliseconds of how long it should wait for Ok Button to be clickable.
   * @return boolean to indicate whether click action is performed
   */
  public async clickOK(waitTime?: number): Promise<boolean> {
    const canClickOk = await this.btnOk.isClickable(waitTime);
    if (canClickOk) {
      await this.btnOk.click();
      await this.waitUntilHidden();
    }
    return canClickOk;
  }
 
  /**
   * Perform click action on Cancel button
   */
  public async clickCancel(): Promise<void> {
    await this.btnCancel.click();
    await this.waitUntilHidden();
  }
}