d5-testing-library 1.0.1 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -75,10 +75,9 @@ var createDriver = async (browser) => {
75
75
  // src/utils/elementIsNotPresent.ts
76
76
  import { Condition } from "selenium-webdriver";
77
77
  var elementIsNotPresent = function elementIsNotPresent2(locator) {
78
- return new Condition("for no element to be located " + locator, function(driver) {
79
- return driver.findElements(locator).then(function(elements) {
80
- return elements.length == 0;
81
- });
78
+ return new Condition("for no element to be located " + locator, async function(driver) {
79
+ const elements = await driver.findElements(locator);
80
+ return elements.length == 0;
82
81
  });
83
82
  };
84
83
 
@@ -123,18 +122,33 @@ var SubsystemsPanel = class extends AbstractElement {
123
122
  };
124
123
 
125
124
  // src/pageObjects/elements/Forms/AbstractForm.ts
125
+ import { By as By4 } from "selenium-webdriver";
126
126
  var AbstractForm = class extends AbstractPage {
127
127
  containerBy;
128
+ popupContainerBy;
128
129
  constructor(driver) {
129
130
  super(driver);
130
131
  this.containerBy = byTestId(`form-content-wrapper-${this.formName}`);
131
132
  }
133
+ async isModal() {
134
+ const el = await this.getContainerElement();
135
+ const value = await el.getAttribute("data-ismodal");
136
+ return value === "true";
137
+ }
132
138
  getContainerElement = () => {
133
139
  return this.driver.findElement(this.containerBy);
134
140
  };
135
141
  get formName() {
136
142
  return "";
137
143
  }
144
+ /**
145
+ * Возвращает true если форма есть в DOM
146
+ * @example
147
+ * class MyForm extends FormEdit {}
148
+ * //...
149
+ * const formEdit = new MyForm();
150
+ * expect(await formEdit.exists()).toBe(true);
151
+ */
138
152
  async exists() {
139
153
  try {
140
154
  await this.driver.wait(elementIsNotPresent(this.containerBy), 1e3);
@@ -143,13 +157,30 @@ var AbstractForm = class extends AbstractPage {
143
157
  return true;
144
158
  }
145
159
  }
160
+ /**
161
+ * Получение заголовка на формы
162
+ * @example
163
+ * const listForm = new MyForm();
164
+ * //...
165
+ * expect(await listForm.getTitleText()).toBe('MyFormTitle');
166
+ */
167
+ async getTitleText() {
168
+ if (await this.isModal()) {
169
+ const popupEl = await this.driver.findElement(this.popupContainerBy);
170
+ const titleEl2 = await popupEl.findElement(By4.className("popup-title"));
171
+ return titleEl2.getText();
172
+ }
173
+ let container = await this.getContainerElement();
174
+ let titleEl = await container.findElement(By4.className("form-toolbar-name-container"));
175
+ return titleEl.getText();
176
+ }
146
177
  };
147
178
 
148
179
  // src/pageObjects/elements/Forms/FormEdit.ts
149
- import { By as By5 } from "selenium-webdriver";
180
+ import { By as By7 } from "selenium-webdriver";
150
181
 
151
182
  // src/pageObjects/elements/Editors/AbstractEditor.ts
152
- import { By as By4, Key } from "selenium-webdriver";
183
+ import { By as By5, Key } from "selenium-webdriver";
153
184
 
154
185
  // src/pageObjects/AbstractFormElement.ts
155
186
  var AbstractFormElement = class extends AbstractElementWithParent {
@@ -163,7 +194,7 @@ var AbstractFormElement = class extends AbstractElementWithParent {
163
194
  var AbstractDXEditorWithInput = class extends AbstractFormElement {
164
195
  async getInputElement() {
165
196
  const controlEl = await this.getElement();
166
- return controlEl.findElement(By4.className("dx-texteditor-input"));
197
+ return controlEl.findElement(By5.className("dx-texteditor-input"));
167
198
  }
168
199
  async getInputValue() {
169
200
  const inputEl = await this.getInputElement();
@@ -197,6 +228,67 @@ var NumberEditor = class extends AbstractDXEditorWithInput {
197
228
  }
198
229
  };
199
230
 
231
+ // src/pageObjects/elements/Editors/CheckBox.ts
232
+ var CheckBox = class extends AbstractFormElement {
233
+ async getValue() {
234
+ const inputEl = await this.getElement();
235
+ const result = await inputEl.getAttribute("aria-checked");
236
+ if (result === "true")
237
+ return true;
238
+ if (result === "false")
239
+ return false;
240
+ return void 0;
241
+ }
242
+ async setValue(value) {
243
+ const inputEl = await this.getElement();
244
+ const currentValue = await this.getValue();
245
+ if (currentValue !== value) {
246
+ await inputEl.click();
247
+ }
248
+ }
249
+ };
250
+
251
+ // src/pageObjects/elements/Editors/SelectBoxEditor.ts
252
+ import { By as By6, Key as Key2 } from "selenium-webdriver";
253
+
254
+ // src/utils/xpathHelper.ts
255
+ var XPathHelper = class {
256
+ static getRoleXpath(role) {
257
+ return `//div[@role='${role}']`;
258
+ }
259
+ static getClassAndValueXpath(cssClass, value) {
260
+ return `//div[contains(@class, '${cssClass}') and contains(.,'${value}')]`;
261
+ }
262
+ };
263
+
264
+ // src/pageObjects/elements/Editors/SelectBoxEditor.ts
265
+ var SELECT_BOX_OPTION_TEXT_CONTAINER_CLASS = "d5-multi-select-item";
266
+ var SELECT_BOX_ELEMENT_ROLE = "option";
267
+ var SelectBoxEditor = class extends AbstractDXEditorWithInput {
268
+ async setSelectInputValue(value) {
269
+ const inputEl = await this.getInputElement();
270
+ await inputEl.click();
271
+ await inputEl.sendKeys(value, Key2.ENTER);
272
+ const combinedValueXpath = XPathHelper.getRoleXpath(SELECT_BOX_ELEMENT_ROLE) + XPathHelper.getClassAndValueXpath(SELECT_BOX_OPTION_TEXT_CONTAINER_CLASS, value);
273
+ await this.driver.wait(async () => {
274
+ try {
275
+ const optElement = await inputEl.findElement(By6.xpath(combinedValueXpath));
276
+ await optElement.click();
277
+ return true;
278
+ } catch (e) {
279
+ return false;
280
+ }
281
+ }, 2e3);
282
+ }
283
+ async getValue() {
284
+ const value = await super.getInputValue();
285
+ return value == "" ? null : value;
286
+ }
287
+ setValue(value) {
288
+ return this.setSelectInputValue(value);
289
+ }
290
+ };
291
+
200
292
  // src/pageObjects/elements/Editors/editorFactory.ts
201
293
  var editorFactory = async (getParentElement, elementBy, driver) => {
202
294
  const elementInstance = new AbstractFormElement(getParentElement, elementBy, driver);
@@ -206,6 +298,10 @@ var editorFactory = async (getParentElement, elementBy, driver) => {
206
298
  return new TextEditor(getParentElement, elementBy, driver);
207
299
  if (classSting.includes("number-control"))
208
300
  return new NumberEditor(getParentElement, elementBy, driver);
301
+ if (classSting.includes("check-box"))
302
+ return new CheckBox(getParentElement, elementBy, driver);
303
+ if (classSting.includes("select-control"))
304
+ return new SelectBoxEditor(getParentElement, elementBy, driver);
209
305
  throw new Error("Unknown type of editor. Please write ticket to the support");
210
306
  };
211
307
 
@@ -216,6 +312,9 @@ function createDataTestId(formName, itemType, itemName) {
216
312
  function createFieldTestId(formName, itemName) {
217
313
  return createDataTestId(formName, "form_field" /* FORM_FIELD */, itemName);
218
314
  }
315
+ function createTableId(formName) {
316
+ return `${"table" /* TABLE */}-${formName}`;
317
+ }
219
318
 
220
319
  // src/pageObjects/elements/FormField.ts
221
320
  var FormField = class extends AbstractElementWithParent {
@@ -229,10 +328,22 @@ var FormField = class extends AbstractElementWithParent {
229
328
  this.editor = await editorFactory(this.getParentElement, this.elementBy, this.driver);
230
329
  }
231
330
  }
331
+ /**
332
+ * Возвращает значение в поле
333
+ * @example
334
+ * expect(await formEdit.field('NumberFld').getValue()).toBe(10);
335
+ * expect(await formEdit.field('TextFld').getValue()).toBe('TestValue');
336
+ */
232
337
  async getValue() {
233
338
  await this.initEditor();
234
339
  return this.editor.getValue();
235
340
  }
341
+ /**
342
+ * Устанавливает значение в поле
343
+ * @example
344
+ * await formEdit.field('NumberFld').setValue(123);
345
+ * await formEdit.field('TextFld').setValue('TestValue');
346
+ */
236
347
  async setValue(value) {
237
348
  await this.initEditor();
238
349
  return this.editor.setValue(value);
@@ -241,21 +352,284 @@ var FormField = class extends AbstractElementWithParent {
241
352
 
242
353
  // src/pageObjects/elements/Forms/FormEdit.ts
243
354
  var FormEdit = class extends AbstractForm {
244
- saveButtonBy = By5.id("button-save");
355
+ saveButtonBy = By7.id("button-save");
356
+ constructor(driver) {
357
+ super(driver);
358
+ this.popupContainerBy = By7.className(`popup form-edit-${this.formName}`);
359
+ }
360
+ /**
361
+ * Находит поле формы редактирования по имени
362
+ * @example
363
+ * const formEdit = new MyForm();
364
+ * //...
365
+ * expect(await formEdit.field('Name').getValue()).toBe('test value');
366
+ */
245
367
  field(name) {
246
368
  return new FormField(this.getContainerElement, this.formName, name, this.driver);
247
369
  }
370
+ /**
371
+ * Нажатие на кнопку Сохранить
372
+ * @example
373
+ * const formEdit = new MyForm();
374
+ * //...
375
+ * await formEdit.saveButtonClick();
376
+ */
248
377
  async saveButtonClick() {
249
378
  await this.driver.findElement(this.saveButtonBy).click();
250
379
  }
251
380
  };
252
381
 
253
382
  // src/pageObjects/elements/Forms/ListForm.ts
254
- import { By as By6 } from "selenium-webdriver";
383
+ import { By as By13 } from "selenium-webdriver";
384
+
385
+ // src/pageObjects/elements/Table/Table.ts
386
+ import { By as By10 } from "selenium-webdriver";
387
+
388
+ // src/pageObjects/elements/Table/utils.ts
389
+ import { By as By8 } from "selenium-webdriver";
390
+ var getRowPathByIndex = (index) => {
391
+ return By8.xpath(`//tr[@aria-rowindex="${transformInputIndex(index)}"]`);
392
+ };
393
+ var getColumnPathByIndex = (index) => {
394
+ return By8.xpath(`//td[@aria-colindex="${transformInputIndex(index)}"]`);
395
+ };
396
+ var getColumnPathByCaption = (caption) => {
397
+ return By8.xpath(`//td[@role="columnheader"][@aria-label="Column ${caption}"]`);
398
+ };
399
+ var getCellPathByIndex = (index) => {
400
+ return By8.xpath(`//td[@role="gridcell"][@aria-colindex="${transformInputIndex(index)}"]`);
401
+ };
402
+ var transformInputIndex = (index) => index + 1;
403
+ var transformOutputIndex = (index) => +index - 1;
404
+
405
+ // src/pageObjects/elements/Table/elements/Row.ts
406
+ import { By as By9 } from "selenium-webdriver";
407
+
408
+ // src/pageObjects/elements/Table/elements/Cell.ts
409
+ var Cell = class extends AbstractElementWithParent {
410
+ index;
411
+ constructor(getParentElement, index, driver) {
412
+ super(getParentElement, driver);
413
+ this.index = index;
414
+ this.elementBy = getCellPathByIndex(index);
415
+ }
416
+ async getValue() {
417
+ const cellEl = await this.getElement();
418
+ return cellEl.getText();
419
+ }
420
+ getIndex() {
421
+ return this.index;
422
+ }
423
+ };
424
+
425
+ // src/pageObjects/elements/Table/elements/Row.ts
426
+ var Row = class extends AbstractElementWithParent {
427
+ index;
428
+ getColumnByCaption;
429
+ constructor(getParentElement, index, driver, getColumnByCaption) {
430
+ super(getParentElement, driver);
431
+ this.index = index;
432
+ this.elementBy = getRowPathByIndex(index);
433
+ this.getColumnByCaption = getColumnByCaption;
434
+ }
435
+ getRowElement = () => {
436
+ return this.driver.findElement(this.elementBy);
437
+ };
438
+ async getCellByIndex(index) {
439
+ const rowEl = await this.getElement();
440
+ const cell = rowEl.findElement(getCellPathByIndex(index));
441
+ if (cell) {
442
+ return new Cell(this.getRowElement, index, this.driver);
443
+ }
444
+ throw new Error(`Cannot find cell by index: ${index}`);
445
+ }
446
+ async getCell(caption) {
447
+ const column = await this.getColumnByCaption(caption);
448
+ if (column) {
449
+ const index = column.getIndex();
450
+ return this.getCellByIndex(index);
451
+ }
452
+ throw new Error("Unknown caption of cell");
453
+ }
454
+ async select() {
455
+ const rowEl = await this.getElement();
456
+ await rowEl.click();
457
+ }
458
+ async isSelected() {
459
+ const rowEl = await this.getElement();
460
+ const result = await rowEl.getAttribute("aria-selected");
461
+ return result === "true";
462
+ }
463
+ getIndex() {
464
+ return this.index;
465
+ }
466
+ async getCells() {
467
+ const rowEl = await this.getElement();
468
+ const cells = await rowEl.findElements(By9.css(`td[role="gridcell"]`));
469
+ const result = [];
470
+ cells.forEach((_, index) => {
471
+ const newCell = new Cell(this.getRowElement, index, this.driver);
472
+ result.push(newCell);
473
+ });
474
+ return result;
475
+ }
476
+ };
477
+
478
+ // src/pageObjects/elements/Table/elements/Column.ts
479
+ var Column = class extends AbstractElementWithParent {
480
+ index;
481
+ constructor(getParentElement, index, driver) {
482
+ super(getParentElement, driver);
483
+ this.index = index;
484
+ this.elementBy = getColumnPathByIndex(index);
485
+ }
486
+ async caption() {
487
+ const el = await this.getElement();
488
+ return el.getText();
489
+ }
490
+ getIndex() {
491
+ return this.index;
492
+ }
493
+ };
494
+
495
+ // src/pageObjects/elements/Table/Table.ts
496
+ var Table = class extends AbstractElementWithParent {
497
+ constructor(getParentElement, formName, driver) {
498
+ super(getParentElement, driver);
499
+ this.elementBy = By10.id(createTableId(formName));
500
+ }
501
+ async getHeaderElement() {
502
+ const parentEl = await this.getElement();
503
+ return parentEl.findElement(By10.className("dx-header-row"));
504
+ }
505
+ async getDataGrid() {
506
+ const parentEl = await this.getElement();
507
+ return parentEl.findElement(By10.css(`div[role="grid"]`));
508
+ }
509
+ getTableElement = () => {
510
+ return this.driver.findElement(this.elementBy);
511
+ };
512
+ async getRowByIndex(index) {
513
+ const gridContainer = await this.getDataGrid();
514
+ const row = await gridContainer.findElement(getRowPathByIndex(index));
515
+ if (row) {
516
+ return new Row(this.getTableElement, index, this.driver, this.getColumnByCaption.bind(this));
517
+ }
518
+ throw new Error(`Cannot find row by index: ${index}`);
519
+ }
520
+ async getColumnByIndex(index) {
521
+ const headerContainer = await this.getHeaderElement();
522
+ const column = await headerContainer.findElement(getColumnPathByIndex(index));
523
+ if (column) {
524
+ return new Column(this.getTableElement, index, this.driver);
525
+ }
526
+ throw new Error(`Cannot find column by index: ${index}`);
527
+ }
528
+ async getColumnByCaption(caption) {
529
+ const headerContainer = await this.getHeaderElement();
530
+ const column = await headerContainer.findElement(getColumnPathByCaption(caption));
531
+ if (column) {
532
+ const index = await column.getAttribute("aria-colindex");
533
+ return new Column(this.getTableElement, transformOutputIndex(index), this.driver);
534
+ }
535
+ throw new Error(`Cannot find column by caption: ${caption}`);
536
+ }
537
+ async selectRowByIndex(index) {
538
+ const row = await this.getRowByIndex(index);
539
+ if (row) {
540
+ await row.select();
541
+ } else {
542
+ throw new Error(`Cannot find row by index: ${index}`);
543
+ }
544
+ }
545
+ async getRows() {
546
+ const gridContainer = await this.getDataGrid();
547
+ const rows = await gridContainer.findElements(By10.className("dx-row dx-data-row"));
548
+ const result = [];
549
+ rows.forEach((_, index) => {
550
+ const newRow = new Row(this.getTableElement, index, this.driver, this.getColumnByCaption.bind(this));
551
+ result.push(newRow);
552
+ });
553
+ return result;
554
+ }
555
+ async getColumns() {
556
+ const headerContainer = await this.getHeaderElement();
557
+ const columns = await headerContainer.findElements(By10.css(`td[role="columnheader"]`));
558
+ const result = [];
559
+ columns.forEach((_, index) => {
560
+ const newCol = new Column(this.getTableElement, index, this.driver);
561
+ result.push(newCol);
562
+ });
563
+ return result;
564
+ }
565
+ async element() {
566
+ return this.getElement();
567
+ }
568
+ };
569
+
570
+ // src/pageObjects/elements/TableToolbar/TableToolbar.ts
571
+ import { By as By12 } from "selenium-webdriver";
572
+
573
+ // src/pageObjects/elements/TableToolbar/TableToolbarButton.ts
574
+ import { By as By11 } from "selenium-webdriver";
575
+ var TOOLBAR_BUTTON_CLASS = "toolbar-button";
576
+ var TableToolbarButton = class extends AbstractElementWithParent {
577
+ constructor(getParentElement, name, driver) {
578
+ super(getParentElement, driver);
579
+ this.elementBy = By11.id(`${TOOLBAR_BUTTON_CLASS}-${name}`);
580
+ }
581
+ async click() {
582
+ const button = await this.getElement();
583
+ return button.click();
584
+ }
585
+ };
586
+
587
+ // src/pageObjects/elements/TableToolbar/TableToolbar.ts
588
+ var TABLE_TOOLBAR_CLASS = "d5-table-toolbar";
589
+ var TableToolbar = class extends AbstractElementWithParent {
590
+ constructor(getParentElement, formName, driver) {
591
+ super(getParentElement, driver);
592
+ this.elementBy = By12.id(`${TABLE_TOOLBAR_CLASS}-${formName}`);
593
+ }
594
+ getTableToolbarElement = () => {
595
+ return this.driver.findElement(this.elementBy);
596
+ };
597
+ async button(name) {
598
+ const toolbar = await this.getTableToolbarElement();
599
+ const button = await toolbar.findElement(By12.id(`${TOOLBAR_BUTTON_CLASS}-${name}`));
600
+ if (button) {
601
+ return new TableToolbarButton(this.getTableToolbarElement, name, this.driver);
602
+ }
603
+ throw new Error(`Cannot find button by name: ${name}`);
604
+ }
605
+ };
606
+
607
+ // src/pageObjects/elements/Forms/ListForm.ts
255
608
  var ListForm = class extends AbstractForm {
256
- titleBy = By6.className("form-toolbar-name-container");
257
- getTitleText() {
258
- return this.getContainerElement().then((el) => el.findElement(this.titleBy)).then((el) => el.getText());
609
+ constructor(driver) {
610
+ super(driver);
611
+ this.popupContainerBy = By13.className(`popup form-inline-${this.formName}`);
612
+ }
613
+ /**
614
+ * Находит таблицу
615
+ * @example
616
+ * const listForm = new MyForm();
617
+ * //...
618
+ * expect(listForm.table());
619
+ */
620
+ table() {
621
+ return new Table(this.getContainerElement, this.formName, this.driver);
622
+ }
623
+ /**
624
+ * Находит таблицу
625
+ * @example
626
+ * const listForm = new MyForm();
627
+ * //...
628
+ * expect(listForm.toolbarButton());
629
+ */
630
+ toolbarButton(name) {
631
+ const toolbar = new TableToolbar(this.getContainerElement, this.formName, this.driver);
632
+ return toolbar.button(name);
259
633
  }
260
634
  };
261
635