index.ts 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /**
  2. * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
  3. * SPDX-License-Identifier: MIT
  4. */
  5. import type { Page } from '@playwright/test';
  6. class FreeLayoutModel {
  7. public readonly page: Page;
  8. constructor(page: Page) {
  9. this.page = page;
  10. }
  11. // 获取节点数量
  12. async getNodeCount() {
  13. return await this.page.evaluate(
  14. () => document.querySelectorAll('[data-testid="sdk.workflow.canvas.node"]').length
  15. );
  16. }
  17. public async isStartNodeExist() {
  18. return await this.page.locator('[data-node-id="start_0"]').count();
  19. }
  20. public async isEndNodeExist() {
  21. return await this.page.locator('[data-node-id="end_0"]').count();
  22. }
  23. public async isConditionNodeExist() {
  24. return await this.page.locator('[data-node-id="condition_0"]').count();
  25. }
  26. async addConditionNode() {
  27. const preConditionNodes = await this.page.locator('.gedit-flow-activity-node');
  28. const preCount = await preConditionNodes.count();
  29. const button = this.page.locator('[data-testid="demo.free-layout.add-node"]');
  30. // open add node panel
  31. await button.click();
  32. await this.page.waitForSelector('[data-testid="demo-free-node-list-condition"]');
  33. // add condition
  34. const conditionItem = this.page.locator('[data-testid="demo-free-node-list-condition"]');
  35. await conditionItem.click();
  36. // determine whether the node was successfully added
  37. await this.page.waitForFunction(
  38. (expectedCount) =>
  39. document.querySelectorAll('.gedit-flow-activity-node').length === expectedCount,
  40. preCount + 1
  41. );
  42. }
  43. }
  44. export default FreeLayoutModel;