Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6840693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:52:30+00:00 2026-05-26T23:52:30+00:00

While writing UI automation tests I come across forms with many fields and instead

  • 0

While writing UI automation tests I come across forms with many fields and instead of passing numerous arguments to test methods I create classes to quickly set form data. So if there is a sign up form I create SignUpDataObjectClass which would have instance variable corresponding to form fields i.e.

public class SignUpFormObject() {
 private username;
 private password;

 public SignUpFormObject setUsername(String username) {
  this.username = username;
  return this;
 }

 public String getUsername() {
  return username;
 }

 public SignUpFormObject setPassword(String password) {
  this.password = password;
  return this;
 }

 public String getPassword() {
  return password;
 }

 // Util method to set signup test data. Test method can use it on the fly
 public static SignUpFormObject setSignUpData() {
  SignUpFormObject dataObject = new SignUpFormObject();
  dataobject.setUsername("test user").setPassword("password");

  return dataobject;    
 }   
}

And then I came across a scenario when it did not make sense to have single data object class for a form. The form is related to creation of Coupon and then there could be different categories of Coupon. For sake of brevity I would limit the number of fields here. So there would be two kinds of coupons – offer and printable. Both of them will have coupon name and one field specific to offer
(let’s consider it – offer expire date) and another for printable (let’s consider it – printable code)

So I decided to create Coupon abstract class which would have all common fields and then CouponOffer and CouponPrintable classes would extend Coupon class and add their own fields i.e.

public abstract class Coupon {
 private String couponname;

 public Coupon setCouponname(String couponName) {
  this.couponname = couponname;
 }  

 public String getCouponname() {
  return couponname;
 }

And CouponOffer class comes here –

public class CouponOffer extends Coupon {
 private String offerExpireDate;

 public CouponOffer setOfferExpireDate(String offerExpireDate) {
  this.offerExpireDate = offerExpireDate;
  return this;
 }  

 public String getOfferExpireDate() {
  return offerExpireDate;
 }

 // Util method to set coupon offer data
 public static CouponOffer setCouponOfferData() {

  CouponOffer couponOffer = new CouponOffer();    
  couponOffer.setCouponname("test coupon");    
  couponOffer.setOfferExpireDate("31/12/2013");   
  return couponOffer();
 }
}

I am willing to know if using abstract class is bad approach here and there are better solutions available.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T23:52:30+00:00Added an answer on May 26, 2026 at 11:52 pm

    I think it’s a good solution.

    Your class CouponOffer just adds the offerExpireDate functionality. Any other functionalities (attributes) of Coupon can be reused by other implementations.

    And no need to repeat the trivial Coupon fields for every implementation

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While writing a simple remoting test I've come up against a suprising situation involving
While writing some test cases, and some of the tests check for the result
While writing functional tests for a controller, I came across a scenario where I
I do write unit tests while writing APIs and core functionalities. But I want
While writing a test suite, I needed to provide an implementation of operator<<(std::ostream&... for
While writing yet another class full of methods that access database tables to work,
While writing a file using ofstream, how do I know when the file's size
while writing a custom attribute in C# i was wondering if there are any
While writing some C code, I decided to compile it to assembly and read
While writing code in a file that would comprise of PHP, HTML, CSS &

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.