Skip to content

Commit f9ac77e

Browse files
Merge pull request #504 from AutomationSolutionz/minor
Minor
2 parents 7b6ce3c + a14bb08 commit f9ac77e

File tree

5 files changed

+132
-53
lines changed

5 files changed

+132
-53
lines changed

Apps/Web/aiplugin/background.js

+60-46
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ fetch("data.json")
1818
key: zeuz_key,
1919
nodeId: zeuz_node_id,
2020
},
21-
function() {
22-
console.log("Logged in successfully!");
23-
});
21+
function () {
22+
console.log("Logged in successfully!");
23+
});
2424
});
2525

2626
function logout() {
27-
browserAppData.storage.local.remove(['key'], function() {
27+
browserAppData.storage.local.remove(['key'], function () {
2828
alert("Logged out successfully!");
2929
});
3030
}
@@ -40,11 +40,11 @@ const inspect = {
4040
// files: [inspectFile]
4141
// });
4242
browserAppData.tabs.sendMessage(id, {
43-
action: type
44-
}).then((response) => {
45-
console.log("Message from the content script:");
46-
console.log(response);
47-
})
43+
action: type
44+
}).then((response) => {
45+
console.log("Message from the content script:");
46+
console.log(response);
47+
})
4848
.catch((error) => {
4949
console.error(`Error: ${error}`)
5050
});
@@ -77,7 +77,7 @@ function toggle(tab) {
7777

7878
if (!isSupportedProtocolAndFileType(tab.url)) return;
7979

80-
if (!tabs[tab.id]){
80+
if (!tabs[tab.id]) {
8181
tabs[tab.id] = Object.create(inspect);
8282
inspect.toggleActivate(tab.id, 'activate', activeIcon);
8383
}
@@ -128,42 +128,56 @@ browserAppData.commands.onCommand.addListener(command => {
128128
browserAppData.tabs.onUpdated.addListener(getActiveTab);
129129
browserAppData.action.onClicked.addListener(toggle);
130130
console.log(navigator.userAgentData.platform);
131-
if (navigator.userAgentData.platform.toLowerCase().includes('mac')){
132-
browserAppData.action.setTitle({
133-
title: "Cmd + Shift + X"
134-
});
131+
if (navigator.userAgentData.platform.toLowerCase().includes('mac')) {
132+
browserAppData.action.setTitle({
133+
title: "Cmd + Shift + X"
134+
});
135135
}
136136
browserAppData.runtime.onMessage.addListener(
137-
function(request, sender, sendResponse) {
138-
if (request.apiName == 'ai_record_single_action') {
139-
var url = `${zeuz_url}/ai_record_single_action/`
140-
fetch(url, {
141-
method: "POST",
142-
headers: {
143-
// "Content-Type": "application/json",
144-
"X-Api-Key": zeuz_key,
145-
},
146-
body: request.data,
147-
})
148-
.then(response => response.json())
149-
.then(text => {console.log(text);sendResponse(text);})
150-
151-
var url = `${zeuz_url}/node_ai_contents/`
152-
fetch(url, {
153-
method: "POST",
154-
headers: {
155-
// "Content-Type": "application/json",
156-
"X-Api-Key": zeuz_key,
157-
},
158-
body: JSON.stringify({
159-
"dom_web": {"dom": request.html},
160-
"node_id": zeuz_node_id
161-
}),
162-
})
163-
.then(response => response.json())
164-
.then(text => {console.log(text);sendResponse(text);})
165-
166-
return true; // Will respond asynchronously.
167-
}
137+
function (request, sender, sendResponse) {
138+
if (request.apiName == 'ai_record_single_action') {
139+
var url = `${zeuz_url}/ai_record_single_action/`
140+
fetch(url, {
141+
method: "POST",
142+
headers: {
143+
// "Content-Type": "application/json",
144+
"X-Api-Key": zeuz_key,
145+
},
146+
body: request.data,
147+
})
148+
.then(response => response.json())
149+
.then(text => { console.log(text); sendResponse(text); })
150+
151+
var url = `${zeuz_url}/node_ai_contents/`
152+
fetch(url, {
153+
method: "POST",
154+
headers: {
155+
// "Content-Type": "application/json",
156+
"X-Api-Key": zeuz_key,
157+
},
158+
body: JSON.stringify({
159+
"dom_web": { "dom": request.html },
160+
"node_id": zeuz_node_id
161+
}),
162+
})
163+
.then(response => response.json())
164+
.then(text => { console.log(text); sendResponse(text); })
165+
166+
return true; // Will respond asynchronously.
167+
} else if (request.apiName == 'node_ai_contents'){
168+
fetch(url, {
169+
method: "POST",
170+
headers: {
171+
// "Content-Type": "application/json",
172+
"X-Api-Key": zeuz_key,
173+
},
174+
body: JSON.stringify({
175+
"dom_web": { "dom": request.dom },
176+
"node_id": zeuz_node_id
177+
}),
178+
})
179+
.then(response => response.json())
180+
.then(text => { console.log(text); sendResponse(text); })
181+
}
168182
}
169-
);
183+
);

Apps/Web/aiplugin/inspect.js

+34
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,38 @@
11
const browserAppData = chrome || browser;
2+
setInterval(() => {
3+
var html = document.createElement('html');
4+
html.setAttribute('zeuz','aiplugin');
5+
var myString = document.documentElement.outerHTML;
6+
html.innerHTML = myString;
7+
8+
var elements = html.getElementsByTagName('head');
9+
while (elements[0])
10+
elements[0].parentNode.removeChild(elements[0])
11+
12+
var elements = html.getElementsByTagName('link');
13+
while (elements[0])
14+
elements[0].parentNode.removeChild(elements[0])
15+
16+
var elements = html.getElementsByTagName('script');
17+
while (elements[0])
18+
elements[0].parentNode.removeChild(elements[0])
19+
20+
var elements = html.getElementsByTagName('style');
21+
while (elements[0])
22+
elements[0].parentNode.removeChild(elements[0])
23+
24+
// AI model works better on indented dom, so not removing indentation.
25+
// var result = html.outerHTML.replace(/\s+/g, ' ').replace(/>\s+</g, '><');
26+
27+
//The following code removes non-unicode characters except newline and tab
28+
var result = html.outerHTML.replace(/[\x00-\x08\x0B-\x1F\x7F]/g, '');
29+
30+
browserAppData.runtime.sendMessage({
31+
apiName: 'node_ai_contents',
32+
dom: result,
33+
})
34+
35+
}, 5000);
236

337
class Inspector {
438
constructor() {

Framework/Built_In_Automation/Sequential_Actions/action_declarations/selenium.py

+1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
{ "name": "resize window", "function": "resize_window", "screenshot": "web" },
6161
{ "name": "change attribute value", "function": "Change_Attribute_Value", "screenshot": "web" },
6262
{ "name": "capture network log", "function": "capture_network_log", "screenshot": "web" },
63+
{ "name": "if element exists", "function": "if_element_exists", "screenshot": "web" },
6364
) # yapf: disable
6465

6566
module_name = "selenium"

Framework/Built_In_Automation/Web/Selenium/BuiltInFunctions.py

+29
Original file line numberDiff line numberDiff line change
@@ -4257,3 +4257,32 @@ def resize_window(step_data):
42574257
except Exception:
42584258
return CommonUtil.Exception_Handler(sys.exc_info(), None, "Error resizing window")
42594259

4260+
@deprecated
4261+
@logger
4262+
def if_element_exists(data_set):
4263+
""" if an element found, save a value to a variable """
4264+
4265+
sModuleInfo = inspect.currentframe().f_code.co_name + " : " + MODULE_NAME
4266+
global selenium_driver
4267+
try:
4268+
variable_name = ""
4269+
value = ""
4270+
4271+
for left, mid, right in data_set:
4272+
if "action" in mid:
4273+
value, variable_name = right.split("=")
4274+
value = value.strip()
4275+
variable_name = variable_name.strip()
4276+
4277+
Element = LocateElement.Get_Element(data_set, selenium_driver)
4278+
if Element in failed_tag_list:
4279+
Shared_Resources.Set_Shared_Variables(variable_name, "false")
4280+
else:
4281+
Shared_Resources.Set_Shared_Variables(variable_name, value)
4282+
return "passed"
4283+
except Exception:
4284+
errMsg = (
4285+
"Failed to parse data/locate element. Data format: variableName = value"
4286+
)
4287+
return CommonUtil.Exception_Handler(sys.exc_info(), None, errMsg)
4288+

Framework/MainDriverApi.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -1221,8 +1221,8 @@ def send_dom_variables():
12211221
"variable_value": "",
12221222
"description": "",
12231223
})
1224-
except Exception:
1225-
CommonUtil.Exception_Handler(sys.exc_info())
1224+
except Exception as e:
1225+
CommonUtil.ExecLog(sModuleInfo, e.msg, 2)
12261226

12271227
if shared.Test_Shared_Variables('selenium_driver'):
12281228
try:
@@ -1255,10 +1255,11 @@ def send_dom_variables():
12551255
//The following code removes non-unicode characters except newline and tab
12561256
var result = html.outerHTML.replace(/[\x00-\x08\x0B-\x1F\x7F]/g, '');
12571257
return result;""")
1258-
except selenium.common.exceptions.JavascriptException:
1259-
CommonUtil.Exception_Handler(sys.exc_info())
1258+
except selenium.common.exceptions.JavascriptException as e:
1259+
CommonUtil.ExecLog(sModuleInfo, e.msg, 2)
12601260
dom = ""
1261-
except:
1261+
except Exception as e:
1262+
CommonUtil.ExecLog(sModuleInfo, e.msg, 2)
12621263
dom = None
12631264
else:
12641265
dom = None
@@ -1278,8 +1279,8 @@ def send_dom_variables():
12781279
elif res.status_code == 404:
12791280
CommonUtil.ExecLog(sModuleInfo, 'The chatbot API does not exist, server upgrade needed', 2)
12801281
return
1281-
except:
1282-
CommonUtil.Exception_Handler(sys.exc_info())
1282+
except Exception as e:
1283+
CommonUtil.ExecLog(sModuleInfo, e.msg, 2)
12831284

12841285

12851286
def set_device_info_according_to_user_order(device_order, device_dict, test_case_no, test_case_name, user_info_object, Userid, **kwargs):

0 commit comments

Comments
 (0)