No, you cannot set the hover state programmatically.
As others have pointed out, you can set a class programmatically, and use the same style for the element when hovered or classed:
a.hover, a:hover { ... }
You could do something similar with :focus, which is also programmatically settable (demo).
However, it appears that you have access only to fire javascript at the application, and not to change any parts of its source. What you would have to do, in this scenario, is to change the css rule itself using java script.
In the setup of your tests, you may change all :hover styles to styles that additionally accept a class name:
function allowMockHover() {
// iterate over all styleSheets
for(var i = 0, l = document.styleSheets.length; i < l; i++) {
var s = document.styleSheets[i];
if(s.cssRules == null) continue;
// iterate over all rules in styleSheet
for(var x = 0, rl = s.cssRules.length; x < rl; x++) {
var r = s.cssRules[x];
if(r.selectorText && r.selectorText.indexOf(':hover') >= 0) {
fixRule(r);
}
}
}
}
function fixRule(rule) {
// if the current rule has several selectors, treat them separately:
var parts = rule.selectorText.split(',');
for(var i = 0, l = parts.length; i < l; i++) {
if(parts[i].indexOf(':hover') >= 0) {
// update selector to be same + selector with class
parts[i] = [ parts[i], parts[i].replace(/:hover/gi, '.mock-hover') ].join(',');
}
}
// update rule
rule.selectorText = parts.join(',');
}
Demo