Skip to content

Commit f343d43

Browse files
Merge pull request #400 from AutomationSolutionz/recorder
Recorder multi-step-test support
2 parents 430d7ee + c33c7da commit f343d43

File tree

9 files changed

+774
-1879
lines changed

9 files changed

+774
-1879
lines changed

Apps/Web/AI_Recorder/background/back.js

Lines changed: 139 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,56 @@ import './sentiment_analyzer.js';
1313
import './back_reocrder.js';
1414
// import '../common_files/poly_fill.js';
1515

16-
/* Zeuz function start */
1716
var master = {};
1817
var clickEnabled = true;
1918

20-
/* Open panel */
19+
/* Create menu */
20+
function create_menus() {
21+
let menus = [
22+
["Go_to_link", "Go to link"],
23+
["Save_Text", "Save Text"],
24+
["Validate_Text", "Validate Text"],
25+
// ["Validate_Text_By_AI", "Validate Text by AI"],
26+
["Wait_For_Element_To_Appear", "Wait for Element to Appear"],
27+
["Wait_For_Element_To_Disappear", "Wait for Element to Disappear"],
28+
]
29+
for(let i =0; i< menus.length; i++){
30+
browserAppData.contextMenus.create({
31+
id: menus[i][0],
32+
title: menus[i][1],
33+
documentUrlPatterns: [
34+
"http://*/*",
35+
"https://*/*"
36+
],
37+
contexts: ["all"]
38+
})
39+
}
40+
browserAppData.runtime.sendMessage({
41+
action: 'content_classify',
42+
text: "Hello world",
43+
})
44+
.then(()=>{
45+
console.log("Classify init finished");
46+
browserAppData.contextMenus.create({
47+
id: "Validate_Text_By_AI",
48+
title: "Validate Text by AI",
49+
documentUrlPatterns: [
50+
"http://*/*",
51+
"https://*/*"
52+
],
53+
contexts: ["all"]
54+
})
55+
});
56+
}
57+
2158

22-
// import {getWindowSize} from "/back_zeuz.js";
2359
function getWindowSize(callback) {
24-
browserAppData.storage.local.get('window', function(result) {
25-
var height = 740;
26-
//var width = 780;
27-
var width = 1110;
60+
browserAppData.storage.local.get('window', async function(result) {
61+
62+
// var width = 1110;
63+
var win = await chrome.windows.getCurrent();
64+
var height = Math.round(win.height*0.9);
65+
var width = Math.round(win.width*0.6);
2866
if (result) {
2967
try {
3068
result = result.window;
@@ -51,7 +89,7 @@ function open_panel(tab) {
5189
browserAppData.windows.update(master[contentWindowId], {
5290
focused: true
5391
}).catch(function(e) {
54-
master[contentWindowId] == undefined;
92+
master[contentWindowId] = undefined;
5593
open_panel(tab);
5694
});
5795
return;
@@ -112,47 +150,97 @@ function open_panel(tab) {
112150
getWindowSize(f);
113151
}
114152

115-
/* Create menu */
116-
function create_menus() {
117-
let menus = [
118-
["Go_to_link", "Go to link"],
119-
["Save_Text", "Save Text"],
120-
["Validate_Text", "Validate Text"],
121-
// ["Validate_Text_By_AI", "Validate Text by AI"],
122-
["Wait_For_Element_To_Appear", "Wait for Element to Appear"],
123-
["Wait_For_Element_To_Disappear", "Wait for Element to Disappear"],
124-
]
125-
for(let i =0; i< menus.length; i++){
126-
browserAppData.contextMenus.create({
127-
id: menus[i][0],
128-
title: menus[i][1],
129-
documentUrlPatterns: [
130-
"http://*/*",
131-
"https://*/*"
132-
],
133-
contexts: ["all"]
134-
})
135-
}
136-
browserAppData.runtime.sendMessage({
137-
action: 'content_classify',
138-
text: "Hello world",
139-
})
140-
.then(()=>{
141-
console.log("Classify init finished");
142-
browserAppData.contextMenus.create({
143-
id: "Validate_Text_By_AI",
144-
title: "Validate Text by AI",
145-
documentUrlPatterns: [
146-
"http://*/*",
147-
"https://*/*"
148-
],
149-
contexts: ["all"]
150-
})
153+
var panelWindow;
154+
async function open_panel_2(tab) {
155+
browserAppData.storage.local.set({
156+
meta_data: metaData,
157+
recorded_actions: [],
151158
});
152-
}
159+
let contentWindowId = tab.windowId;
160+
console.log('panelWindow', panelWindow);
161+
var result = await browserAppData.storage.local.get(['panelWindow']);
162+
console.log('result.panelWindow', result.panelWindow);
163+
// console.log('result.panelWindow', result.panelWindow);
164+
165+
if (result.panelWindow && result.panelWindow[contentWindowId]) {
166+
browserAppData.windows.update(result.panelWindow[contentWindowId], {
167+
focused: true
168+
}).catch(function(e) {
169+
console.log('panelWindow catch error', panelWindow);
170+
console.error('error', e);
171+
var panel_dict = result.panelWindow
172+
panel_dict[contentWindowId] = undefined;
173+
panelWindow = undefined;
174+
browserAppData.storage.local.set({
175+
panelWindow: panel_dict
176+
}).then(open_panel(tab));
177+
});
178+
return;
179+
} else if (!clickEnabled) {
180+
return;
181+
}
182+
183+
clickEnabled = false;
184+
setTimeout(function() {
185+
clickEnabled = true;
186+
}, 1000);
187+
188+
var f = function(height, width) {
189+
browserAppData.windows.create({
190+
url: browserAppData.runtime.getURL("panel/index.html"),
191+
type: "popup",
192+
//height: 705,
193+
height: height,
194+
//width: 1366
195+
width: width
196+
}).then(function waitForPanelLoaded(panelWindowInfo) {
197+
return new Promise(function(resolve, reject) {
198+
let count = 0;
199+
let interval = setInterval(function() {
200+
if (count > 100) {
201+
reject("editor has no response");
202+
clearInterval(interval);
203+
}
153204

205+
browserAppData.tabs.query({
206+
active: true,
207+
windowId: panelWindowInfo.id,
208+
status: "complete"
209+
}).then(async function(tabs) {
210+
if (tabs.length != 1) {
211+
count++;
212+
return;
213+
} else {
214+
var result = await browserAppData.storage.local.get(['panelWindow']);
215+
if (result.panelWindow) var panel_dict = result.panelWindow;
216+
else var panel_dict = {};
217+
panel_dict[contentWindowId] = panelWindowInfo.id;
218+
await browserAppData.storage.local.set({
219+
panelWindow: panel_dict
220+
});
221+
console.log('panel_dict', panel_dict);
222+
panelWindow = panelWindowInfo.id;
223+
console.log('opening panelWindow', panelWindow);
224+
create_menus();
225+
resolve(panelWindowInfo);
226+
clearInterval(interval);
227+
}
228+
})
229+
}, 200);
230+
});
231+
}).then(function bridge(panelWindowInfo){
232+
return browserAppData.tabs.sendMessage(panelWindowInfo.tabs[0].id, {
233+
selfWindowId: panelWindowInfo.id,
234+
commWindowId: contentWindowId
235+
});
236+
}).catch(function(e) {
237+
console.log(e);
238+
});
239+
};
240+
getWindowSize(f);
241+
}
154242

155-
browserAppData.action.onClicked.addListener(open_panel);
243+
browserAppData.action.onClicked.addListener(open_panel_2);
156244
browserAppData.windows.onRemoved.addListener(function(windowId) {
157245
let keys = Object.keys(master);
158246
for (let key of keys) {
@@ -181,3 +269,8 @@ browserAppData.runtime.onInstalled.addListener(function (details) {
181269
console.log("Recorder Installed");
182270
}
183271
});
272+
273+
var i_am_running = 0;
274+
setInterval(()=>{
275+
i_am_running++;
276+
},200)

Apps/Web/AI_Recorder/background/back_zeuz.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ const browserAppData = chrome || browser;
44
function getWindowSize(callback) {
55
chrome.storage.local.get('window', function(result) {
66
var height = 740;
7-
//var width = 780;
8-
var width = 1110;
7+
var width = 780;
8+
// var width = 1110;
99
if (result) {
1010
try {
1111
result = result.window;

Apps/Web/AI_Recorder/background/data.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"testName": "Test_name",
44
"stepNo": 0,
55
"stepName": "Step_name",
6-
"url": "url",
7-
"apiKey": "apiKey",
8-
"jwtKey": "jwtKey"
6+
"url": "",
7+
"apiKey": "",
8+
"jwtKey": ""
99
}

Apps/Web/AI_Recorder/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"description": "This ZeuZ Chrome extension allow you to record a test case, use ZeuZ AI to get an acurate page element, and play back the test case right in your browser.",
33
"manifest_version": 3,
44
"name": "ZeuZ Test Recorder",
5-
"version": "3.0",
5+
"version": "4.0",
66
"minimum_chrome_version": "117",
77
"icons": {
88
"16": "panel/assets/images/small_logo.png",

Apps/Web/AI_Recorder/panel/assets/css/mystyle.css

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,12 @@ body
9393
.dropdown-item{
9494
font-size: 15px;
9595
}
96-
#nav_menu_up
96+
#test_id
9797
{
98-
background: #fff;
99-
/*min-height: 50px;*/
100-
padding-top: 10px;
98+
display: inline-block;
99+
width: 70px;
100+
border: 2px solid black;
101+
border-radius: 8px;
101102
}
102103
.tr_body
103104
{
@@ -303,13 +304,6 @@ body
303304
width: 100%;
304305
padding-right: 120px;
305306
}
306-
.settings_container
307-
{
308-
display: flex;
309-
flex-direction: row;
310-
min-height: 94vh;
311-
justify-content: space-between
312-
}
313307
.settings_form h3
314308
{
315309
text-transform: uppercase;
@@ -634,7 +628,22 @@ body
634628
font-style: italic;
635629
}
636630

637-
631+
.tr{
632+
background-color:white;
633+
}
634+
.td-no{
635+
min-width: 75px;
636+
}
637+
.table-custom{
638+
width: 640px;
639+
}
640+
.del-btn:hover{
641+
opacity: 1;
642+
}
643+
.del-btn{
644+
/* visibility: hidden; */
645+
opacity: 0.3;
646+
}
638647
.font_black ::-webkit-input-placeholder
639648
{
640649
color: #000

Apps/Web/AI_Recorder/panel/assets/js/background/recorder.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,31 @@ class BackgroundRecorder {
3232
})
3333
return;
3434
}, 500)
35+
this.recording_flag = false
36+
setInterval(async ()=>{
37+
if (!this.attached) return;
38+
browserAppData.storage.local.get(null, function (result) {
39+
if (result.recorded_actions.length === 0) return;
40+
for(let i = 0; i < result.recorded_actions.length; i++){
41+
if (result.recorded_actions[i] === 'empty'){
42+
if (!this.recording_flag) this.recording_flag = true;
43+
else{
44+
var new_arr = [];
45+
for (const action of result.recorded_actions) {
46+
if (action !== 'empty') new_arr.push(action);
47+
}
48+
result.recorded_actions = new_arr;
49+
browserAppData.storage.local.set({
50+
recorded_actions: new_arr
51+
})
52+
this.recording_flag = false;
53+
}
54+
return;
55+
}
56+
}
57+
})
58+
return;
59+
}, 10000)
3560
}
3661

3762
/* Bind initial time */

0 commit comments

Comments
 (0)