URL validation

This sample code checks whether a specific URL is shown in the browser. As an example, when you go to the Dynatrace Portal http://portal.dynatrace.com/, you are redirected to https://portal.dynatrace.com/index.jsp. To perform validation that this is the page we landed on, we can use the following code in a Custom action with gomez_top[0] as the target.

When the expected URL is found, we add a hidden DIV element to the page. At the end of the step, we can then place a Validate action, set to validate against a specific element. The element to validate against is #URLMatch. The script will then fail if any other URL is shown in the browser.

// Grab the current URL
var fullUrl = window.location.pathname + window.location.search;
alert(fullUrl); 

// Check to make sure it matches what we are looking for
if (fullUrl.indexOf("http://www.dynatrace.com/en/index.html") !== -1)
{
	alert ("found the URL we searched for"); 

	// create an element on the page with an ID attribute of #URLMatch.
	// We will use this element for a Validation action.
	var el = document.createElement('div');
	el.id = 'URLMatch';
	document.body.appendChild(el);
	alert ("added #URLMatch to the page for validation");
}