-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
369 lines (331 loc) · 12.6 KB
/
index.js
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
const fs = require("fs");
const puppeteer = require("puppeteer");
const tour = require("./tour").tour;
(async () => {
const browser = await puppeteer.launch({
headless: false,
defaultViewport: {
width: 1024,
height: 768
}
});
const page = await browser.newPage();
function destroyOverlay() {
return page.evaluate(() => {
destroyOverlay();
});
}
async function capture(path, func, options = {}) {
await page.evaluate(() => {
addOverlay();
});
await page.evaluate(func);
const screenshotOptions = Object.assign(
{ path: `screenshots/${path}` },
options
);
await page.screenshot(screenshotOptions);
await destroyOverlay();
}
await page.goto("http://localhost:8069/web/login?login=admin");
//await page.screenshot({ path: "screenshots/login.png" });
await page.type('[name="password"]', "");
await page.click('[type="submit"]');
await page.waitForSelector(".o_home_menu");
await page.waitFor(1000);
await page.addScriptTag({
content: fs.readFileSync("./annotationHelper.js").toString()
});
async function captureTour(i) {
console.log(i);
const name = await page.evaluate(selector => {
const names = [];
[".o_menu_brand", ".breadcrumb", selector].forEach(s => {
const e = document.querySelector(s);
if (e && e.innerText && e.innerText.trim()) {
names.push(e.innerText.trim().replace("\n", " / "));
}
});
return names.join(" / ");
}, tour[i].trigger);
tour[i].name = name;
console.log(name);
try {
await page.hover(".o_tooltip");
await page.waitFor(1000);
const rect = await page.evaluate(() => {
const el = document.querySelector(".o_tooltip");
if (el) {
const { x, y, width, height } = el.getBoundingClientRect();
return { x, y, width, height };
}
return {
x: 0,
y: 0,
width: window.innerWidth,
height: window.innerHeight
};
});
await capture(`${i}.png`, () => {}, {
clip: {
x: rect.x - 120,
y: rect.y - 120,
width: rect.width + 240,
height: rect.height + 240
}
});
} catch (e) {
console.log("tooltip not found");
}
await page.click(tour[i].trigger);
await page.waitFor(2000);
await page.evaluate(() => {
['[placeholder="Name"]', '[placeholder="Product Name"]'].forEach(
selector => {
const e = document.querySelector(selector);
if (e) {
e.value = "Test";
const event = document.createEvent("HTMLEvents");
event.initEvent("change", true, false);
e.dispatchEvent(event);
}
}
);
});
const needToAdd = await page.evaluate(() => {
const e = document.querySelector(".o_input.ui-autocomplete-input");
if (e) {
return e.value === "";
}
return false;
});
if (needToAdd) {
try {
await page.type(".o_input.ui-autocomplete-input", "Test");
await page.waitFor(500);
await page.click(".ui-autocomplete li.ui-menu-item a");
} catch (e) {}
}
}
for (let i = 0; i < tour.length; i++) {
await captureTour(i);
}
console.log(JSON.stringify(tour));
/*
await capture( "home.png", () => {
addBorderToSelector('[data-menu-xmlid="purchase.menu_purchase_root"]', true);
});
*/
/*
// config installed apps
await page.click('[data-menu-xmlid="base.menu_management"]');
await page.waitFor(1000);
await page.click('.o_search_options button');
await page.click('.o_search_options .o_filters_menu div:nth-of-type(5) a');
await capture( "install_apps_final.png", () => {
addBorderToSelector('.o_search_options .o_filters_menu div:nth-of-type(5) a', true)
});
*/
/*
await capture( "menu_sales.png", () => {
addBorderToSelector('[data-menu-xmlid="sale.sale_menu_root"]', true);
});
await page.click('[data-menu-xmlid="sale.sale_menu_root"]');
await page.waitForSelector('[data-menu-xmlid="sale.menu_sale_config"]');
// expand menu
await page.click('[data-menu-xmlid="sale.menu_sale_config"]');
await capture( 'sales_configuration.png', () => {
addBorderToSelector('[data-menu-xmlid="sale.menu_sale_config"]');
addBorderToSelector('[data-menu-xmlid="sale.menu_sale_general_settings"]', true);
});
await page.click('[data-menu-xmlid="sale.menu_sale_general_settings"]');
await page.waitForSelector('[name="group_uom"]');
await page.click('[name="group_uom"]');
await capture("activate_uom_configuration.png", () => {
addArrowToSelector('[name="group_uom"]', "1");
addHighlightToSelector('[name="group_uom"]');
addArrowToSelector('[name="execute"]', "2");
});
await capture("menu_config_uom.png", () => {
const dom = '[attrs="{\'invisible\': [(\'group_uom\',\'=\',False)]}"]';
addHighlightToSelector(dom);
addArrowToSelector(dom);
});
*/
/*
// test config purchase flow
await page.click('[data-menu-xmlid="purchase.menu_purchase_root"]');
await page.waitForSelector('[data-menu-xmlid="purchase.menu_procurement_management"]');
// expand menu
await page.click('[data-menu-xmlid="purchase.menu_procurement_management"]');
await capture( "purchase_home.png", () => {
addBorderToSelector('[data-menu-xmlid="purchase.menu_procurement_management"]');
addBorderToSelector('[data-menu-xmlid="purchase.menu_procurement_partner_contact_form"]', true);
});
await page.click('[data-menu-xmlid="purchase.menu_procurement_partner_contact_form"]');
await page.waitForSelector(".btn.btn-primary.o-kanban-button-new");
await capture("purchase_new_article_button.png", () => {
addBorderToSelector(".btn.btn-primary.o-kanban-button-new", true);
});
await page.click(".btn.btn-primary.o-kanban-button-new");
await page.waitForSelector('[name="name"]');
// await page.type('[name="name"]', "My Sample Product");
await page.select('[name="type"]', '"product"');
// uncheck
await page.click('[name="sale_ok"]');
await capture("articles_fabric_general.png", () => {
addArrowToSelector('[name="name"]', "1");
addHighlightToSelector('[name="name"]');
addArrowToSelector('[name="sale_ok"]', "2");
addHighlightToSelector('[name="sale_ok"]');
addArrowToSelector('[name="type"]', "3");
addHighlightToSelector('[name="type"]');
document.querySelector('[name="list_price"] input').value = ''
addArrowToSelector('[name="list_price"]', "4");
addHighlightToSelector('[name="list_price"]');
addArrowToSelector('[name="taxes_id"]', "x");
addHighlightToSelector('[name="taxes_id"]');
document.querySelector('[name="standard_price"] input').value = ''
addArrowToSelector('[name="standard_price"]', "5");
addHighlightToSelector('[name="standard_price"]');
document.querySelector('[name="uom_po_id"] input').value = ''
addArrowToSelector('[name="uom_po_id"]', "6");
addHighlightToSelector('[name="uom_po_id"]');
});
await capture("articles_invoicing_taxes.png", () => {
document.querySelectorAll('.nav-item a')[4].click();
document.querySelector('.o_content').scrollTop = 200;
addArrowToSelector('.nav-item:nth-child(5)');
addArrowToSelector('[name="supplier_taxes_id"]', "x");
addHighlightToSelector('[name="supplier_taxes_id"]');
});
*/
/*
// test config sales flow
await page.click('[data-menu-xmlid="sale.sale_menu_root"]');
await page.waitForSelector('[data-menu-xmlid="sale.product_menu_catalog"]');
// expand menu
await page.click('[data-menu-xmlid="sale.product_menu_catalog"]');
await capture( "menu_ventes_articles.png", () => {
addBorderToSelector('[data-menu-xmlid="sale.product_menu_catalog"]');
addBorderToSelector('[data-menu-xmlid="sale.menu_product_template_action"]', true);
});
await page.click('[data-menu-xmlid="sale.menu_product_template_action"]');
await page.waitForSelector(".btn.btn-primary.o-kanban-button-new");
await capture("articles_ventes_create.png", () => {
addBorderToSelector(".btn.btn-primary.o-kanban-button-new", true);
});
await page.click(".btn.btn-primary.o-kanban-button-new");
await page.waitForSelector('[name="name"]');
await page.select('[name="type"]', '"product"');
// uncheck
await page.click('[name="purchase_ok"]');
await capture("articles_sale_general.png", () => {
addArrowToSelector('[name="name"]', "1");
addHighlightToSelector('[name="name"]');
addArrowToSelector('[name="purchase_ok"]', "2");
addHighlightToSelector('[name="purchase_ok"]');
addArrowToSelector('[name="type"]', "3");
addHighlightToSelector('[name="type"]');
document.querySelector('[name="list_price"] input').value = ''
addArrowToSelector('[name="list_price"]', "4");
addHighlightToSelector('[name="list_price"]');
addArrowToSelector('[name="taxes_id"]', "x");
addHighlightToSelector('[name="taxes_id"]');
document.querySelector('[name="standard_price"] input').value = ''
addArrowToSelector('[name="standard_price"]', "5");
addHighlightToSelector('[name="standard_price"]');
});
await capture("articles_sale_inventory.png", () => {
document.querySelectorAll('.nav-item a')[5].click();
document.querySelector('.o_content').scrollTop = 200;
document.querySelector('[name="route_ids"] div:nth-child(2) label').click()
document.querySelector('[name="route_ids"] div:nth-child(3) label').click()
addBorderToSelector('.nav-item:nth-child(6)', true);
addArrowToSelector('[name="route_ids"] div:nth-child(2)');
addHighlightToSelector('[name="route_ids"]');
});
*/
/*
// test config sales flow
await page.click('[data-menu-xmlid="sale.sale_menu_root"]');
await page.waitForSelector('[data-menu-xmlid="sale.sale_order_menu"]');
// expand menu
await page.click('[data-menu-xmlid="sale.sale_order_menu"]');
await capture("menu_ventes_devis.png", () => {
addBorderToSelector('[data-menu-xmlid="sale.sale_order_menu"]');
addBorderToSelector('[data-menu-xmlid="sale.menu_sale_quotations"]', true);
addArrowToSelector('.o_searchview_facet', 'x');
addHighlightToSelector('.o_searchview_facet');
});
*/
/*
// create invoice
await page.click('[data-menu-xmlid="purchase.menu_purchase_root"]');
await page.waitForSelector('.o_data_cell');
await page.click('.o_data_cell');
await page.waitForSelector('[name="action_view_invoice"]');
await capture("po_view_invoices.png", () => {
addBlur('[name="partner_id"]');
addBlur('[name="amount_untaxed"]');
addBlur('.ui-sortable');
addBlur('[name="amount_tax"]');
addBlur('[name="amount_total"]');
addBorderToSelector('[name="action_view_invoice"]', true);
});
*/
/*
// accounting
await capture( "menu_comptabilite.png", () => {
addBorderToSelector('[data-menu-xmlid="account_accountant.menu_accounting"]', true);
});
await page.click('[data-menu-xmlid="account_accountant.menu_accounting"]');
await page.waitForSelector('[data-menu-xmlid="account.menu_finance_reports"]');
await page.click('[data-menu-xmlid="account.menu_finance_reports"]');
await capture( "menu_balance_sheet.png", () => {
addBorderToSelector('[data-menu-xmlid="account.menu_finance_reports"]');
addBorderToSelector('[data-menu-xmlid="l10n_ch_reports.account_financial_html_report_menu_7"]', true);
});
*/
/*
// inventory
await capture( "menu_inventory.png", () => {
addBorderToSelector('[data-menu-xmlid="stock.menu_stock_root"]', true);
});
await page.click('[data-menu-xmlid="stock.menu_stock_root"]');
await page.waitForSelector('[data-menu-xmlid="stock.menu_stock_inventory_control"]');
await page.click('[data-menu-xmlid="stock.menu_stock_inventory_control"]');
await capture( "menu_stocks_articles.png", () => {
addBorderToSelector('[data-menu-xmlid="stock.menu_stock_inventory_control"]');
addBorderToSelector('[data-menu-xmlid="stock.menu_product_variant_config_stock"]', true);
}, {
clip: {
x: 0,
y: 0,
width: 1024,
height: 350
}
});
*/
/*
// add client
await capture( "menu_ventes.png", () => {
addBorderToSelector('[data-menu-xmlid="sale.sale_menu_root"]', true);
});
await page.click('[data-menu-xmlid="sale.sale_menu_root"]');
await page.waitForSelector('[data-menu-xmlid="sale.sale_order_menu"]');
await page.click('[data-menu-xmlid="sale.sale_order_menu"]');
await capture( "menu_ventes_clients.png", () => {
addBorderToSelector('[data-menu-xmlid="sale.sale_order_menu"]');
addBorderToSelector('[data-menu-xmlid="sale.res_partner_menu"]', true);
}, {
clip: {
x: 0,
y: 0,
width: 1024,
height: 350
}
});
*/
await browser.close();
})();