Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pid.txt

# Zeuz Node specific ignores
Framework/settings.conf
Apps/Web/aiplugin/data.json
node-bigquery-privkey.json
AutomationLog/
iosSimulator/*
Expand Down
9 changes: 8 additions & 1 deletion Apps/Web/AI_Recorder/background/back.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
const metaData = {};
var metaData = {};

fetch("data.json")
.then(Response => Response.json())
.then(data => {
metaData = data;
});

const browserAppData = chrome || browser;

import './back_zeuz.js';
Expand Down
9 changes: 9 additions & 0 deletions Apps/Web/AI_Recorder/background/data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"testNo": "TEST-0000",
"testName": "Test_name",
"stepNo": 0,
"stepName": "Step_name",
"url": "url",
"apiKey": "apiKey",
"jwtKey": "jwtKey"
}
28 changes: 21 additions & 7 deletions Apps/Web/AI_Recorder/content/recorder.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,20 @@ class Recorder {
var html = document.createElement('html');
html.innerHTML = document.documentElement.outerHTML;

for (let each of target) if (each[1] == 'xpath:position') {var xpath = each[0];break;}
for (let each of target) if (each[1] == 'xpath:position') {
var xpath = each[0];
break;
}
var xPathResult = document.evaluate(xpath, html);
if(xPathResult) var main_elem = xPathResult.iterateNext();
else return;

main_elem.setAttribute('zeuz', 'aiplugin');
console.log(main_elem.hasAttribute('zeuz'), main_elem);

// Recorder already changed the value which should not be sent to ai-engine
if (command === 'text')
main_elem.removeAttribute('value');
// get all <head> elements from html
var elements = html.getElementsByTagName('head');
while (elements[0])
Expand All @@ -76,6 +82,11 @@ class Recorder {
while (elements[0])
elements[0].parentNode.removeChild(elements[0])

// get all <link> elements from html
var elements = html.getElementsByTagName('link');
while (elements[0])
elements[0].parentNode.removeChild(elements[0])

var xPathResult = document.evaluate(xpath, document);
if(xPathResult) console.log('doc true')
else console.log('doc false');
Expand Down Expand Up @@ -211,12 +222,15 @@ class Recorder {
return;
}
this.attached = false;
browserAppData.storage.local.set({
recorded_actions: this.recorded_actions,
}).then(()=>{
this.idx = 0;
this.recorded_actions = [];
});
console.log('saving recorded_actions from content file');
// When there are 2 iframes. it saves 3 times. this is a temporary fix. Should be fixed properly
if (this.recorded_actions.length > 0)
browserAppData.storage.local.set({
recorded_actions: this.recorded_actions,
}).then(()=>{
this.idx = 0;
this.recorded_actions = [];
});

for (let event_key in this.eventListeners) {
var event_info = this.parse_the_event_key(event_key);
Expand Down
151 changes: 25 additions & 126 deletions Apps/Web/aiplugin/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,31 @@ const tabs = {};
const inspectFile = 'inspect.js';
const activeIcon = 'active-64.png';
const defaultIcon = 'small_logo.png';
let zeuz_url = '__ZeuZ__UrL_maPP';
let zeuz_key = '__ZeuZ__KeY_maPP';
var zeuz_url;
var zeuz_key;

fetch("data.json")
.then(Response => Response.json())
.then(data => {
zeuz_url = data.zeuz_url;
zeuz_key = data.zeuz_key;
console.log(data);
console.log(zeuz_url);
console.log(zeuz_key);
browserAppData.storage.local.set({
url: zeuz_url,
key: zeuz_key,
},
function() {
console.log("Logged in successfully!");
});
});

function logout() {
browserAppData.storage.local.remove(['key'], function() {
alert("Logged out successfully!");
});
}
browserAppData.contextMenus.create({
title: "Logout",
contexts: ["all"],
// onclick: logout,
id: "zeuz_inspector"
});

browserAppData.contextMenus.onClicked.addListener(logout);

Expand Down Expand Up @@ -66,123 +77,11 @@ function toggle(tab) {

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

if (!tabs[tab.id]) {
// tabs[tab.id] = Object.create(inspect);
// inspect.toggleActivate(tab.id, 'activate', activeIcon);

// check key exists
browserAppData.storage.local.get(['key'], function(result) {
// console.log('Value currently is ' + result.key);

if (result.key != null) {
// activate
tabs[tab.id] = Object.create(inspect);
inspect.toggleActivate(tab.id, 'activate', activeIcon);
} else {
if (zeuz_url.startsWith('__ZeuZ__UrL_maP'))
var server_url = prompt("Please enter your ZeuZ server address", "");
else
var server_url = zeuz_url;
if (zeuz_key.startsWith('__ZeuZ__KeY_maP'))
var api_key = prompt("Please enter your API key", "");
else
var api_key = zeuz_key;

var verify_status;
var verify_token;

if (server_url != null && api_key != null) {

//process the url

var lastChar = server_url.substr(server_url.length - 1);
if (lastChar == "/") {
server_url = server_url.slice(0, -1); // remove last char '/'
}

if (server_url.startsWith("http") == false) {

if ((server_url.indexOf("localhost") != -1) || (server_url.indexOf("127.0.0.1") != -1) || (server_url.indexOf("0.0.0.0") != -1)) {
server_url = "http://" + server_url; // add http:// in the beginning
} else {
server_url = "https://" + server_url; // add http:// in the beginning
}

}

if (zeuz_key.startsWith('__ZeuZ__KeY_maP')) {
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener("readystatechange", function() {
if (this.readyState === 4) {
console.log(this.responseText);

verify_status = this.status;
verify_token = this.responseText;

// show message for verification
if (verify_status === 200) {

if (verify_token === null) {
alert("Sorry! Api key is wrong.");
} else {
// save server url and api key
// browserAppData.storage.local.set({ url: server_url ,key: api_key }, function () {
browserAppData.storage.local.set({
url: server_url,
key: JSON.parse(this.responseText).token
},
function() {
console.log('Value is set to ', server_url, this.responseText);
if (zeuz_url.startsWith('__ZeuZ__UrL_maP'))
alert("Logged in successfully!");
else
console.log("Logged in successfully!");
});

// activate plugin
tabs[tab.id] = Object.create(inspect);
inspect.toggleActivate(tab.id, 'activate', activeIcon);
}

} else if ((verify_status === 403) || (verify_status === 0)) {
alert("Sorry! Server URL is incorrect.");
} else if (verify_status === 404) {
alert("Sorry! Api key is incorrect.");
} else {
alert("Sorry! Server url/key is incorrect.");
}


}
});
xhr.open("GET", server_url + "/api/auth/token/verify?api_key=" + api_key);
xhr.send();
} else {
browserAppData.storage.local.set({
url: server_url,
key: zeuz_key,
},
function() {
console.log("Logged in successfully!");
});

// activate plugin
tabs[tab.id] = Object.create(inspect);
inspect.toggleActivate(tab.id, 'activate', activeIcon);
}


} else {
alert("Sorry! Server url/key cannot be empty.");
}

}

});


} else {
if (!tabs[tab.id]){
tabs[tab.id] = Object.create(inspect);
inspect.toggleActivate(tab.id, 'activate', activeIcon);
}
else {
// deactivate plugin
inspect.toggleActivate(tab.id, 'deactivate', defaultIcon);
for (const tabId in tabs) {
Expand Down Expand Up @@ -238,7 +137,7 @@ browserAppData.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
if (request.apiName == 'ai_record_single_action') {
var url = `${zeuz_url}/ai_record_single_action/`

console.log("zeuz_key", zeuz_key)
fetch(url, {
method: "POST",
headers: {
Expand Down
4 changes: 4 additions & 0 deletions Apps/Web/aiplugin/data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"zeuz_url": "__ZeuZ__UrL_maPP",
"zeuz_key": "__ZeuZ__KeY_maPP"
}
5 changes: 5 additions & 0 deletions Apps/Web/aiplugin/inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ class Inspector {
while (elements[0])
elements[0].parentNode.removeChild(elements[0])

// get all <link> elements from div
var elements = html.getElementsByTagName('link');
while (elements[0])
elements[0].parentNode.removeChild(elements[0])

// get all <script> elements from div
var elements = html.getElementsByTagName('script');
while (elements[0])
Expand Down
23 changes: 8 additions & 15 deletions Framework/Built_In_Automation/Web/Selenium/BuiltInFunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,15 +460,12 @@ def set_extension_variables():
url = ConfigModule.get_config_value("Authentication", "server_address").strip()
apiKey = ConfigModule.get_config_value("Authentication", "api-key").strip()
jwtKey = CommonUtil.jwt_token.strip()
with open(Path(aiplugin_path) / "background.js") as file:
text = file.read()
# if "__ZeuZ__UrL_maPP" in text or "__ZeuZ__KeY_maPP" in text:
with open(Path(aiplugin_path) / "background.js", "w") as file:
zeuz_url_var_idx = text.find("let zeuz_url = ")
zeuz_url_var = text[zeuz_url_var_idx:zeuz_url_var_idx+text[zeuz_url_var_idx:].find("\n")]
zeuz_key_var_idx = text.find("let zeuz_key = ")
zeuz_key_var = text[zeuz_key_var_idx:zeuz_key_var_idx+text[zeuz_key_var_idx:].find("\n")]
file.write(text.replace(zeuz_url_var, f"let zeuz_url = '{url}';", 1).replace(zeuz_key_var, f"let zeuz_key = '{apiKey}';", 1))
with open(Path(aiplugin_path) / "data.json", "w") as file:
json.dump({
"zeuz_url": url,
"zeuz_key": apiKey
}, file, indent=4)

except:
return CommonUtil.Exception_Handler(sys.exc_info(), None, "Could not load inspector extension")

Expand All @@ -482,11 +479,7 @@ def set_extension_variables():
with open(Path(ai_recorder_path) / "panel" / "index.html", "w") as file:
# html = re.compile(r'^(\s*)', re.MULTILINE).sub(r'\1' * 4, soup.prettify())
file.write(html)
with open(Path(ai_recorder_path) / "background" / "back.js") as file:
recorder_back_js_text = file.read()
with open(Path(ai_recorder_path) / "background" / "back.js", "w") as file:
metaData_idx = recorder_back_js_text.find("const metaData = ")
metaData_var = recorder_back_js_text[metaData_idx:metaData_idx+recorder_back_js_text[metaData_idx:].find("\n")]
with open(Path(ai_recorder_path) / "background" / "data.json", "w") as file:
metaData = {
"testNo": CommonUtil.current_tc_no,
"testName": CommonUtil.current_tc_name,
Expand All @@ -496,7 +489,7 @@ def set_extension_variables():
"apiKey": apiKey,
"jwtKey": jwtKey,
}
file.write(recorder_back_js_text.replace(metaData_var, f"const metaData = {metaData};", 1))
json.dump(metaData, file, indent=4)
except:
return CommonUtil.Exception_Handler(sys.exc_info(), None, "Could not load recorder extension")

Expand Down