What is it?
This extension allows you to easily check the "index" and "follow" Meta Robot tags for a page.
How to add it to selenium:
1. Add the following code into the 'user-extensions.js' file:
user-extensions.js
Selenium.prototype.assertMetaRobotTags = function(thisIndex, thisFollow)
{
// Grab meta robots element, and compare the tags
var expectedIndex = thisIndex.toLowerCase();
var expectedFollow = thisFollow.toLowerCase();
var actualIndex;
var actualFollow;
//var xpathCommand = "xpath=//meta[contains(@name,\"robots\")]";
var xpath = "//meta[contains(@name,\"robots\") and (contains(@content, \"index\") or contains(@content, \"follow\"))]";
var xpathCommand = "xpath=" + xpath;
try
{
var element = this.page().findElement(xpathCommand);
}
catch (e)
{
var message = 'Test failed:\n' + "Meta Robots Tag not found";
LOG.error(message);
Assert.fail(message);
return;
}
var content = element.getAttribute("content").toLowerCase();
actualIndex = (content.indexOf("noindex")>-1)
? "noindex"
: (content.indexOf("index")>-1)
? "index"
: "undefined";
actualFollow = (content.indexOf("nofollow")>-1)
? "nofollow"
: (content.indexOf("follow")>-1)
? "follow"
: "undefined";
LOG.info("Actual Index: " + actualIndex + " - Actual Follow: " + actualFollow);
Assert.matches(expectedIndex, actualIndex);
Assert.matches(expectedFollow, actualFollow);
};
Example:
Sample Selenium code:
| open | http://www.google.com | |
| verifyMetaRobotTags | noindex | follow |
