iTest only supports the built in internal browser (mozilla) and Internet Explorer 7. So, I am not sure why you would want to check the browser type.
Anyway, to run any JavaScript in the web browser use the web application's 'eval' action.
The command body will take in the JavaScript you wish to run. It is recommended that you put each statement in a separate line;
I notice that your JavaScript is actually displaying the browser name by overwriting the content of the page.
You could use JavaScript alert to show you the value:
alert(browser);
You can get all the alert messages in iTest by running the "listPrompts" action.
So your test case steps would look like this:
eval var browser = navigator.appName;
eval var version = navigator.appVersion;
eval alert(browser);
eval alert(version);
listPrompts
The response of listPrompts will have the values you are looking for.
Another interesting way of calling javascript which might span multiple lines.
You can wrap all your steps in a function.
Set the function in the web page's context using 'eval' action
The call the function using another 'eval' action
e.g. if you have a javascript function is:
var browser = navigator.appName;
var result;
if (browser == "Microsoft Internet Explorer") {
result = 10;
} else {
result = 20;
}
alert(result);
You could wrap this into an eval action:
eval var myFunction = new Function("var browser = navigator.appName; var result; if (browser == 'Microsoft Internet Explorer') { result = 10; } else { result = 20; } alert(result);");
eval myFunction();
No one has followed this question yet.