1

I am trying to implement a page class for footer in OpenCart application. which is having multiple links with same or similar properties except link text. What is the best way so that we can define single object and parameterize the link text.

Please share your ideas

3

Unfortunately, it's not possible to send arguments to annotation (reference)

One possible solution would be to create a Page Object class for link and pass a WebElement based on its li node.

Class Footer {
     @FindBy(css = "footer")
     WebElement baseElement;

     List<WebElement> links;

     Footer() {
         this.links = this.createLinks();
     }

     private List<Links> createLinks() {
          List<WebElement> links = baseElement.findElements("li");
          return links.stream().map(link -> new FooterLink(link)).collect(Collectors.toList());
      }
}

class Link {
    WebElement baseElement;
    Link(WebElement baseElement) {
       this.baseElement = baseElement;
    }
    //Now you can make any search for the specific 
    //Link using the baseElement attribute to narrow it properly
}
  • I think I understand the footer class, It seems like regular class when Page factory initialise Footer baseElement will be a Footer Object and when Create links called it fetches all li in it. Please Explain little more It would be helpful if you can also provide Pagefactory snippet. Finally What is FooterLink that you used in stream, is it Link constructor? and I did not understand the purpose of Link class... Little more detailed please .. I am new to these concepts – SQA_LEARN yesterday
  • The Link class aims to provide the behavior of a link - you could write methods to click on it, get its target URL, etc. By separating it from the Footer class, it can be instantiated for any link on the application - and if a particular link has a different behavior, you can polymorphically change it using inheritance. The base element, provided by the Footer component says how to find the link inside itself and the link class provides the behavior of a Link. – João Farias yesterday

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.