0

I have written Page object class for Login page to test UI look & feel for web, iphone & tablet. For each verification I have written a method to return cssValue or text for that element.

Writing that increases lot method defined in a single class. Is there any way to reduce no of methods declared in a page object class?

Example:

public String getBannerCssValue(String cssValue){ 
    return getCssValue(driver.findElement(banner), cssValue); 
} 

public String getSmartPhoneLegendText(){ 
    return getElementText(driver.findElement(smartPhoneLegend)); 
} 

public String getSmartPhoneLegendCssValue(String cssValue){ 
    return getCssValue(driver.findElement(smartPhoneLegend), cssValue); 
} 

public String getTabletLegendText(){ 
    return getElementText(driver.findElement(tabletLegend)); 
} 

public String getTabletLegendCssValue(String cssValue){ 
    return getCssValue(driver.findElement(tabletLegend), cssValue); 
} 

public String getButtonTextValue(){ 
    return getAttribute(driver.findElement(login), "value"); 
} 

public String getSubmitButtonCssValue(String cssValue){ 
    return getCssValue(driver.findElement(login), cssValue); 
} 

public String getForgotPasswordCssValue(String cssValue){ 
    return getCssValue(driver.findElement(forgotYourPassword), cssValue); 
} 

public String getTabButtonTextValue(){ 
    return getAttribute(driver.findElement(tabletSubmit), "value"); 
}
KingArasan
  • 733
  • 1
  • 10
  • 19
  • 1
    I just came across "PageObjects using Enum Pattern", that sounds interesting. https://github.com/vsundramurthy/WebdriverPageObjectsUsingEnum any feedback for this approach? – KingArasan Nov 19 '13 at 17:19
  • Well do you *need* all these methods? As in, are you *actually* using the various `*getCssValue` methods? – Arran Nov 19 '13 at 17:27
  • 1
    Instead of a method for each object, have only 3 methods, getCssValue, getAttributeValue, getTextValue and call these with different object values. – Akbar Nov 20 '13 at 06:03
  • i would prefer to have some annotation mapping for web elements and have action methods that uses the web elements directly. instead getters use the POM using Enum pattern suggested by @KingArasan – Karthikeyan Nov 20 '13 at 07:03
  • @TestAutomationEngr Outside page object we should n't expose the Web element. So Test class will not know about Web element. – KingArasan Nov 20 '13 at 17:51
  • @KingArasan In that case, declare all the webelements at class level and have a single method say getAttributeValue(String elementName, String attributeType), which gets the webelement based on elementName and calls any of the 3 methods based on attributeType and returns the attribute value(text, css,....) – Akbar Nov 21 '13 at 08:46

1 Answers1

-2

I think you should be guided by the way you'll actually use these getters.

In my code, I often read a number of controls into a single object: user data on the page gets read into a User object. So I have a single getter for that.

In other contexts, where I don't have (or need) an object, I have individual getters for individual controls.

Are there setters for some or all of these getters? If so, consider merging a getter/setter pair into a single function. I've written about this on my blog:

Burdette Lamar
  • 229
  • 2
  • 13