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,330 points
43 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,890 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 4, 2019 in Selenium by Anvi
• 14,090 points
6,791 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,090 points
2,782 views
0 votes
1 answer

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,510 points
3,124 views
0 votes
1 answer
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,890 points
2,357 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,890 points
2,505 views
0 votes
1 answer

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

Simply Use this: driver.Manage().Window.Maximize(); READ MORE

answered Jun 7, 2018 in Selenium by Samarpit
• 5,890 points
8,670 views
0 votes
2 answers