How to locate class using enums in base class

0 votes
Below is the code for every PageClass:

public void goToParticularTableSection(TableSectionDraggablePage tableSectionDraggablePage){

    switch (tableSectionDraggablePage) {

        case DefaultFunctionality:

            clickOnElement(defaultFunctionalityTableHeader);

            break;

        case ConstrainMovement:

            clickOnElement(constraintMovementTableHeader);

            break;

        ...

    }

    TestLogger.log.info(tableSectionDraggablePage + " clicked");

}

 

For every PageClass I have another class with enums:

public enum TableSectionDraggablePage {

    DefaultFunctionality,

    ConstrainMovement,

    ...

}

 

How to move goToParticularTableSection method into Base class and have the common use of this method in every PageClass what allows me avoid code duplication in every page class?

Jul 26, 2018 in Selenium by Martin
• 4,320 points
660 views

1 answer to this question.

0 votes

Define getters in PageClass like getDefaultFunctionality(), getConstrainMovement() etc. and then redesign the enum like this:

public enum TableSectionDraggablePage {

 DefaultFunctionality, 

 defaultFunctionalityTableHeader,

 ConstrainMovement,

 constraintMovementTableHeader,

 ...


 TableSectionDraggablePage(PageClass pageClass) {

   this.DefaultFunctionality = pageClass.getDefaultFunctionality();

   this.defaultFunctionalityTableHeader = pageClass.getDefaultFunctionalityTableHeader();

   ...

 }

}

Then move goToParticularTableSection(TableSectionDraggablePage) to BaseClass.

Then just call the method from PageClass like this:

super.goToParticularTableSection(new TableSectionDraggablePage(this));

answered Jul 26, 2018 by Samarpit
• 5,910 points

Related Questions In Selenium

0 votes
1 answer

How to scroll up/down a page using Actions class in Selenium?

Hi Naetik, you can use Actions class ...READ MORE

answered Jul 5, 2019 in Selenium by Anvi
• 14,150 points
19,942 views
0 votes
1 answer
0 votes
1 answer

How to create a Base Class in Selenium and use it with test scripts?

Hi Donna, you can use following code ...READ MORE

answered Jul 18, 2019 in Selenium by Anvi
• 14,150 points
12,078 views
+1 vote
1 answer
0 votes
2 answers

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,500 points
12,753 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
8,623 views
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,910 points
6,697 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 3, 2020 in Selenium by Sri
• 3,190 points
7,561 views
0 votes
2 answers

How to open a browser window in full screen using Selenium WebDriver with C#

Hi , we have inbuilt method Maximize(). driver.Manage().Wind ...READ MORE

answered Sep 6, 2020 in Selenium by Sri
• 3,190 points
15,592 views
0 votes
2 answers
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP