all repos — caroster @ 94ed421247e41b427d90cf078b579daf30b8842b

[Octree] Group carpool to your event https://caroster.io

backend/e2e/test/pages/_page.js (view raw)

 1/* eslint-disable class-methods-use-this */
 2'use strict';
 3import {cast} from './utils/cast';
 4export class Page {
 5  constructor(path) {
 6    this._path = path;
 7  }
 8
 9  get name() {
10    return 'undefined';
11  }
12
13  /**
14   * @return {string}
15   */
16  get path() {
17    return this._path;
18  }
19
20  /**
21   * @param {string} path
22   */
23  set path(path) {
24    this._path = path;
25  }
26
27  async open() {
28    console.log('browse url', this.path);
29    await browser.url(this.path);
30    await this.waitForDisplayed();
31  }
32
33  /**
34   *
35   * @param {string} selector
36   */
37  field(selector) {
38    throw new Error('Not implemented for ' + selector);
39  }
40
41  async submit() {
42    const field = this.field('submit');
43    const element = await $(field);
44    await browser.saveScreenshotByName(`${this.name}--filled`);
45    await element.click();
46  }
47
48  /**
49   *
50   * @param {string} selector
51   * @param {string} value
52   * @return {Promise<void>}
53   */
54  async type(selector, value = undefined) {
55    const field = this.field(selector);
56    if (typeof value === 'undefined') value = selector;
57    const element = await $(field);
58    await element.addValue(cast(value));
59  }
60
61  /**
62   *
63   * @param {string} selector
64   * @param {string} value
65   * @return {Promise<void>}
66   */
67  async pick(selector, value = undefined) {
68    const field = this.field(selector);
69    if (typeof value === 'undefined') value = selector;
70    const range = cast(value);
71    const container = await $(field);
72    const element = await container.$(
73      `.MuiSlider-markLabel[aria-hidden='true'][data-index='${range}']`
74    );
75    await element.click();
76  }
77
78  /**
79   *
80   * @param {string} selector
81   * @return {Promise<void>}
82   */
83  async click(selector) {
84    const field = this.field(selector);
85    const element = await $(field);
86    await element.click();
87  }
88
89  async waitForDisplayed(timeout = 1200, takeScreenshot = true) {
90    await new Promise(resolve => {
91      setTimeout(resolve, timeout);
92    });
93    if (takeScreenshot) await browser.saveScreenshotByName(this.name);
94  }
95}