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
66
67
68
69
import { element, by } from '../e2elib/node_modules/protractor/built';
import { QLogType } from '../e2elib/lib/src/main/qlogtype.enum';
import { QUtils } from '../e2elib/lib/src/main/qutils.class';
import { WebLogin } from '../e2elib/lib/src/pageobjects/weblogin.component';
import { WebLogout } from '../e2elib/lib/src/pageobjects/weblogout.component';
import { QConsole } from '../e2elib/lib/src/helper/qconsole';
 
export class AppBase {
  /**
   * Performs application login action.
   *
   * @returns Promise object indicating the completion of login action
   */
  public async login(username?: string, clearViewCache: boolean = true): Promise<void> {
    // Login
    // S&OP Added username argument for PCS to login as different user
    const webLogin = new WebLogin();
    try {
      await webLogin.login(undefined, username);
 
      // S&OP added IF statement (some test require viewAutoSave true thus can pass false to skip setting this to false)
      if (clearViewCache) {
        await QConsole.viewAutoSave(false);
        await QConsole.clearViewCache();
      }
    } catch (err) {
      expect(err).toBeLogged(QLogType.ERROR);
      return;
    }
  }
 
  /**
   * Performs application logout action.
   *
   * @returns Promise object indicating the completion of logout action
   */
  public async logout(): Promise<void> {
    // Logout
    const webLogout = new WebLogout();
    await webLogout.logout();
  }
 
  /**
   * Checks for any unexpected toast messages.
   *
   * @returns Promise object indicating the completion of check
   */
  public async checkToastMessage(): Promise<void> {
    await QUtils.checkToastMessage();
  }
 
  /**
   * Turn off auto view save and clear view cache. For turning the feature ON, pass boolean when calling App.login method.
   */
  public async disableAutoViewSave(): Promise<void> {
    await QConsole.viewAutoSave(false);
    await QConsole.clearViewCache();
  }
 
  /**
   * Get application title.
   *
   * @returns Application title string
   */
  public async getTitle(): Promise<string> {
    const title = element(by.css('section.experience')).element(by.css('.title'));
    return title.getText();
  }
}