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,220 points
20 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,130 points

Related Questions In Selenium

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 in Selenium by Anvi
• 13,240 points
120 views
0 votes
1 answer

How to handle drop downs using Selenium WebDriver in Java

First, find an XPath which will return ...READ MORE

answered Mar 27, 2018 in Selenium by nsv999
• 5,090 points
2,138 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,090 points
739 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,130 points
989 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,130 points
704 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,130 points
3,722 views
0 votes
2 answers

How to get HTML Source of WebElement in Selenium WebDriver using Python?

You can read innerHTML attribute to get source of ...READ MORE

answered Jun 13, 2018 in Selenium by Samarpit
• 5,130 points
15,400 views