I have the following functions in JavaScript:
function SelectFirstVisiblePublicationAndHideIt ( PageObj )
{
var hideButtonXpath = "//img[@title='To hide this item in your profile, mark it as invisible']";
var hideButtonArray;
var numberOfHideButton;
var publicationTitle;
aqUtils.Delay(500);
hideButtonArray = PageObj.EvaluateXpath(hideButtonXpath);
numberOfHideButton = hideButtonArray.length;
hideButtonArray[0].Click();
publicationTitle = hideButtonArray[0].parent.parent.FindChildByXPath("//a").innerText;
return publicationTitle;
}
function SelectFirstVisiblePublicationAndReclaimIt ( PageObj )
{
var reclaimButtonXpath = "//button[@title='Claim this publication and stay on this page']";
var reclaimButtonArray;
var numberOfReclaimButton;
var publicationTitle;
aqUtils.Delay(500);
reclaimButtonArray = PageObj.EvaluateXpath(reclaimButtonXpath);
numberOfReclaimButton = reclaimButtonArray.length;
reclaimButtonArray[0].Click();
publicationTitle = reclaimButtonArray[0].parent.parent.FindChildByXPath("//a").innerText;
return publicationTitle;
}
SelectFirstVisiblePublicationAndHideIt
and SelectFirstVisiblePublicationAndReclaimIt
are very similar except for the Xpath expression.
I am wondering if I should merge them into one function by:
- re-naming variables and functions names in a more generic way
- introduce an additional input argument that serves as a flag to indicate which Xpath expression is to be used
Doing so has pros and cons:
- Pros: reduce the number of function by one
- Cons: purpose of a function can no longer be read from its name; having one more input argument; become further away from the principle of "one function should do one thing and one thing only"
Any suggestions?