-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcopy.ts
More file actions
148 lines (113 loc) · 4.47 KB
/
copy.ts
File metadata and controls
148 lines (113 loc) · 4.47 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import { Page, expect, BrowserContext } from "@playwright/test";
import fs from "fs";
const orderPurchase = async (page: Page) => {
// Extend timeout to handle slow iframe/page loads under load
page.setDefaultTimeout(15000);
// Load authentication state (cookie-based)
const context: BrowserContext = page.context();
const storageState = JSON.parse(
fs.readFileSync("./.auth/login.json", "utf-8")
);
await context.addCookies(storageState.cookies);
// Go to Business Central
await page.goto("https://businesscentral.dynamics.com/", {
waitUntil: "load",
});
// Wait up to 20s for the iframe element to exist (not necessarily visible)
await page.waitForSelector(".designer-client-frame", { timeout: 20000 });
// Get the iframe once it's present
const iframeHandle = await page.$(".designer-client-frame");
if (!iframeHandle) throw new Error("iframe element not found");
const iframe = await iframeHandle.contentFrame();
if (!iframe) throw new Error("iframe not yet loaded");
await iframe.waitForSelector('a:has-text("Einkaufsbestell")', {
timeout: 20000,
});
const purchaseOrdersButton = iframe.locator('a:has-text("Einkaufsbestell")');
if (!iframe) {
throw new Error("Failed to get iframe content");
}
// Wait for the "Purchase Orders" link to be visible
await expect(purchaseOrdersButton).toBeVisible();
await purchaseOrdersButton.click();
const purchaseOrderPage = iframe.getByText("Einkaufsbestellungen", {
exact: true,
});
await expect(purchaseOrderPage).toBeVisible();
const newButton = iframe.getByRole("menuitem", { name: "Neu" });
await newButton.click();
const vendorName = iframe.getByLabel("Kreditorenname", { exact: true });
const vendorNameDropDown = iframe.getByLabel("Wählen Sie einen Wert für");
const documentDateField = iframe.getByRole("combobox", {
name: "Belegdatum",
});
const vendorInvoice = iframe.getByLabel("Kred.-Rechnungsnr.");
await expect(documentDateField).toBeEmpty();
await expect(vendorInvoice).toBeEmpty();
await vendorNameDropDown.click();
const okButton = iframe.getByRole("button", { name: "OK" });
await okButton.click();
await expect(vendorName).not.toBeEmpty();
await expect(documentDateField).not.toBeEmpty();
const invoiceNumber = Math.floor(10000 + Math.random() * 90000).toString();
await vendorInvoice.fill(invoiceNumber);
await expect(vendorInvoice).not.toBeEmpty();
const itemNumber = iframe.getByRole("combobox", {
name: "Nr.",
exact: true,
});
const itemTableNumber = iframe.getByLabel("1896-S");
await itemNumber.click();
await itemTableNumber.click();
const unitPriceInput = iframe.getByRole("textbox", {
name: "EK-Preis Ohne MwSt.",
exact: true,
});
const totalPriceInput = iframe.getByRole("textbox", {
name: "Zeilenbetrag Ohne MwSt.",
exact: true,
});
await unitPriceInput.waitFor();
const quantity = iframe.getByRole("textbox", {
name: "Menge",
exact: true,
});
await quantity.fill("10");
await page.click("body");
const unitPriceValue = await unitPriceInput.inputValue();
const totalPriceValue = await totalPriceInput.inputValue();
// Optional math checks can go here if needed
const status = iframe.getByRole("textbox", { name: "Status" });
const statusOpen = await status.textContent();
await expect(statusOpen).toBe("Offen");
const permissionButton = iframe.locator(
'button[aria-label="Genehmigung anfordern"]'
);
await expect(permissionButton).toBeVisible();
await permissionButton.click();
const sendPermissionButton = iframe.locator(
'button[aria-label="Genehmigungsanforderung senden"]'
);
await expect(sendPermissionButton).toBeVisible();
await sendPermissionButton.click();
const startButton = iframe.getByRole("menuitem", { name: "Start" });
await expect(startButton).toBeVisible();
await startButton.click();
const statusRelease = await status.textContent();
await expect(statusRelease).toBe("Freigegeben");
const postButton = iframe.getByRole("button", {
name: "Buchen...",
exact: true,
});
await postButton.click();
await okButton.click();
const yesButton = iframe.getByRole("button", { name: "Ja" });
await yesButton.click();
const postedPurchasePage = iframe.getByText("Geb. Einkaufsrechnung", {
exact: true,
});
await expect(postedPurchasePage).toBeVisible();
const vendorInvoiceNumber = iframe.getByLabel(invoiceNumber);
await expect(vendorInvoiceNumber).toHaveText(invoiceNumber);
};
export default orderPurchase;