Skip to content

Commit 44b5940

Browse files
Merge pull request #382 from AutomationSolutionz/inspector
Inspector
2 parents da12416 + 5065da5 commit 44b5940

File tree

7 files changed

+61
-99
lines changed

7 files changed

+61
-99
lines changed

Apps/Web/AI_Recorder/content/recorder.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ class Recorder {
9898
data: data,
9999
dataj: dataj,
100100
},
101-
response => {
101+
resp => {
102+
let response = resp.ai_choices;
102103
response[0].short.value = value;
103104
if (value) response[0].data_set[response[0].data_set.length-1][response[0].data_set[0].length-1] = value;
104105
this.recorded_actions[idx] = {

Apps/Web/aiplugin/background.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,4 +233,24 @@ if (navigator.userAgentData.platform.toLowerCase().includes('mac')){
233233
browserAppData.action.setTitle({
234234
title: "Cmd + Shift + X"
235235
});
236-
}
236+
}
237+
browserAppData.runtime.onMessage.addListener(
238+
function(request, sender, sendResponse) {
239+
if (request.apiName == 'ai_record_single_action') {
240+
var url = `${zeuz_url}/ai_record_single_action/`
241+
242+
fetch(url, {
243+
method: "POST",
244+
headers: {
245+
// "Content-Type": "application/json",
246+
"X-Api-Key": zeuz_key,
247+
},
248+
body: request.data,
249+
})
250+
.then(response => response.json())
251+
.then(text => {console.log(text);sendResponse(text);})
252+
253+
return true; // Will respond asynchronously.
254+
}
255+
}
256+
);

Apps/Web/aiplugin/inspect.js

Lines changed: 26 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class Inspector {
3131

3232
function insert_modal_text(response, modal_id) {
3333
console.log("insert_modal_text ..................")
34-
if (response.status == 200) {
34+
if (response["info"] == "success") {
3535
// show message about element
3636
const modalText = 'Element data was recorded. Please Click "Add by AI"';
3737
console.log(modalText);
@@ -45,29 +45,20 @@ class Inspector {
4545
}
4646
return true;
4747
}
48+
console.error(response["info"]);
4849
return false;
4950

5051
}
5152

52-
async function send_data(server_url, api_key, data, backup_data, modal_id) {
53-
let resp = await fetch(server_url + "/api/contents/", {
54-
method: "POST", // or 'PUT'
55-
headers: {
56-
"Content-Type": "application/json",
57-
"Authorization": `Bearer ${api_key}`,
58-
},
59-
body: data,
60-
});
61-
if (insert_modal_text(resp, modal_id)) return;
62-
resp = await fetch(server_url + "/api/contents/", {
63-
method: "POST", // or 'PUT'
64-
headers: {
65-
"Content-Type": "application/json",
66-
"Authorization": `Bearer ${api_key}`,
67-
},
68-
body: backup_data,
69-
});
70-
insert_modal_text(resp, modal_id);
53+
async function send_data(server_url, api_key, data, modal_id) {
54+
browserAppData.runtime.sendMessage({
55+
apiName: 'ai_record_single_action',
56+
data: data,
57+
},
58+
response => {
59+
insert_modal_text(response, modal_id);
60+
}
61+
);
7162
}
7263

7364
// check if we are locating sibling now
@@ -92,42 +83,29 @@ class Inspector {
9283

9384
// Get full page html, remove <style> and <script> tags //
9485
// create a new div container
95-
var div = document.createElement('div');
86+
var html = document.createElement('html');
9687
var myString = document.documentElement.outerHTML;
9788

9889
// assign your HTML to div's innerHTML
99-
div.innerHTML = myString;
90+
html.innerHTML = myString;
10091

10192
// get all <script> elements from div
102-
var elements = div.getElementsByTagName('script');
93+
var elements = html.getElementsByTagName('head');
94+
while (elements[0])
95+
elements[0].parentNode.removeChild(elements[0])
10396

104-
// remove all <script> elements
97+
// get all <script> elements from div
98+
var elements = html.getElementsByTagName('script');
10599
while (elements[0])
106100
elements[0].parentNode.removeChild(elements[0])
107101

108102
// get all <style> elements from div
109-
var elements = div.getElementsByTagName('style');
110-
111-
// remove all <style> elements
103+
var elements = html.getElementsByTagName('style');
112104
while (elements[0])
113105
elements[0].parentNode.removeChild(elements[0])
114106

115107
// get div's innerHTML into a new variable
116-
var refinedHtml = div.innerHTML;
117-
118-
119-
const tracker_info = {
120-
'elem': this.elem['html'], // main element not entire html. Not required in backend !!
121-
'html': refinedHtml,
122-
'url': window.location.href,
123-
'source': 'web'
124-
}
125-
126-
const backup_tracker_info = {
127-
'elem': this.elem['original_html'], // main element not entire html. Not required in backend !!
128-
'url': window.location.href,
129-
'source': 'web'
130-
}
108+
var refinedHtml = html.outerHTML;
131109

132110
// choose sibling element
133111
browserAppData.storage.local.get(['sibling'], function (result) {
@@ -161,16 +139,11 @@ class Inspector {
161139
// send data to zeuz server directly
162140

163141
var data = JSON.stringify({
164-
"content": JSON.stringify(tracker_info),
165-
"source": "web"
142+
"page_src": refinedHtml,
143+
"action_type": "selenium"
166144
});
167145

168-
var backup_data = JSON.stringify({
169-
"content": JSON.stringify(backup_tracker_info),
170-
"source": "web"
171-
});
172-
173-
send_data(server_url, api_key, data, backup_data, this.modalNode);
146+
send_data(server_url, api_key, data, this.modalNode);
174147

175148
});
176149
// remove zeuz attribute
@@ -224,26 +197,6 @@ class Inspector {
224197
var refinedHtml = div.innerHTML;
225198

226199

227-
// prepare data to send
228-
const tracker_info = {
229-
'elem': result.main,
230-
'sibling': this.sibling['html'],
231-
'html': refinedHtml,
232-
'url': window.location.href,
233-
'source': 'web'
234-
}
235-
236-
const backup_tracker_info = {
237-
'elem': result.main,
238-
'sibling': this.sibling['original_html'],
239-
'url': window.location.href,
240-
'source': 'web'
241-
}
242-
243-
244-
// send data to zeuz server
245-
// this.sendData(tracker_info, backup_tracker_info);
246-
247200
// get url-key and send data to zeuz
248201
browserAppData.storage.local.get(['key', 'url'], function (result) {
249202

@@ -255,16 +208,11 @@ class Inspector {
255208
// send data to zeuz server directly
256209

257210
var data = JSON.stringify({
258-
"content": JSON.stringify(tracker_info),
259-
"source": "web"
260-
});
261-
262-
var backup_data = JSON.stringify({
263-
"content": JSON.stringify(backup_tracker_info),
264-
"source": "web"
211+
"page_src": refinedHtml,
212+
"action_type": "selenium"
265213
});
266214

267-
send_data(server_url, api_key, data, backup_data, this.modalNode);
215+
send_data(server_url, api_key, data, this.modalNode);
268216

269217
});
270218
// remove zeuz attribute

Apps/Windows/ZeuZ_Windows_Inspector.py

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -117,29 +117,19 @@ def Authenticate():
117117

118118
def Upload(auth_thread, window_name):
119119
try:
120-
global auth
121-
if not auth:
122-
auth = auth_thread.result().json()["token"]
123-
Authorization = 'Bearer ' + auth
124120
url = server + "/" if server[-1] != "/" else server
125-
url += "api/contents/"
121+
url += "ai_record_single_action/"
126122
content = json.dumps({
127-
'html': xml_str,
123+
'page_src': xml_str,
124+
"action_type": "windows",
128125
"exact_path": {"path": path, "priority": path_priority},
129126
"window_name": window_name
130127
})
131-
132-
payload = json.dumps({
133-
"content": content,
134-
"source": "windows"
135-
})
136128
headers = {
137-
'Authorization': Authorization,
138-
'Content-Type': 'application/json'
139-
129+
"X-Api-Key": api_key,
140130
}
141131

142-
r = requests.request("POST", url, headers=headers, data=payload, verify=False)
132+
r = requests.request("POST", url, headers=headers, data=content, verify=False)
143133
response = r.json()
144134
del response["content"]
145135
r.ok and print("Content successfully sent to AI Engine\n")

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
# Changelog
22

33

4-
# Version 17
4+
# Version 18
55

66
### [Current changes]
77
-
88

9+
### [18.0.0][Nov 5, 2023]
10+
- **[Change]** AI Inspector new api integrated
911

12+
# Version 17
1013
### [17.1.0][Oct 23, 2023]
1114
- **[Fix]** Inspector bug fixes and improvements
1215
- **[Fix]** Appium desired capabilities fix

Framework/Built_In_Automation/Web/Selenium/BuiltInFunctions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ def set_extension_variables():
468468
zeuz_url_var = text[zeuz_url_var_idx:zeuz_url_var_idx+text[zeuz_url_var_idx:].find("\n")]
469469
zeuz_key_var_idx = text.find("let zeuz_key = ")
470470
zeuz_key_var = text[zeuz_key_var_idx:zeuz_key_var_idx+text[zeuz_key_var_idx:].find("\n")]
471-
file.write(text.replace(zeuz_url_var, f"let zeuz_url = '{url}';", 1).replace(zeuz_key_var, f"let zeuz_key = '{jwtKey}';", 1))
471+
file.write(text.replace(zeuz_url_var, f"let zeuz_url = '{url}';", 1).replace(zeuz_key_var, f"let zeuz_key = '{apiKey}';", 1))
472472
except:
473473
return CommonUtil.Exception_Handler(sys.exc_info(), None, "Could not load inspector extension")
474474

Framework/Version.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[ZeuZ Python Version]
2-
version = 17.1.0
2+
version = 18.0.0
33
[Release Date]
4-
date = October 23, 2023
4+
date = November 5, 2023

0 commit comments

Comments
 (0)