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,340 points
75 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,130 points
11,074 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,130 points
4,815 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,520 points
4,602 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,010 points
5,462 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,890 points
3,290 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 2, 2020 in Selenium by Sri
• 3,010 points
3,887 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 5, 2020 in Selenium by Sri
• 3,010 points
11,220 views
0 votes
2 answers