Quantcast
Channel: Active questions tagged selenium - Stack Overflow
Viewing all articles
Browse latest Browse all 97806

How to extend a class having parameterized @BeforeMethod

$
0
0

I want to extend BaseClass from all test cases class. For some test cases I want to login with Admin credentials and for some with Customer.

Previously this code was working properly as launchBrowserAndLogin() method was not having any parameters.

Is there any way for extending class with parameter?

Here is my code:

public class BaseClass {

    public  BaseClass() {
    }

    @BeforeMethod
    public void launchBrowserAndLogin(String userType) {        
        if(userType.equals("Admin")) {
            launchBrowserAndUrl(Constants.ADMIN_URL);
            login(Constants.ADMIN_USER_NAME, Constants.ADMIN_USER_PASSWORD);
        }
        if(userType.equals("Customer")) {
            launchBrowserAndUrl(Constants.CUSTOMER_TEST_URL);
            login(Constants.CUSTOMER_USER_NAME, Constants.CUSTOMER_USER_PASSWORD);
        }
    }

    @AfterMethod
    public void tearDown() {
        TestDriver.getDriver().quit();
    }
}


public class AssignEditDeleteRoleAccessibilityTest extends BaseClass {

    CreateUser newUser = new CreateUser();
    RoleAssignmentAccessValidation roleAccessValidation = new RoleAssignmentAccessValidation();

    @DataProvider(name = "AssignEditDeleteRoleAccessibilityTest")
    public static Object[] roleNames() {
        return new Object[] {Constants.AGENCY_ASSISTANT_ROLE_NAME, Constants.OPS_MANAGER_ROLE_NAME};
    }

    @Test ( priority=1, dataProvider = "AssignEditDeleteRoleAccessibilityTest")
    public void assignRoleAccessTest(String roleName) {

        newUser.createUserAssignRoleAndLogin(roleName);

        boolean isAssignRoleOptionAvailable =roleAccessValidation.assignRoleAccess();

        assertEquals(isAssignRoleOptionAvailable, false);
    }
}

Now I am getting error:

FAILED CONFIGURATION: @BeforeMethod launchBrowserAndLogin org.testng.TestNGException: Can inject only one of <ITestContext, XmlTest, Method, Object[], ITestResult> into a @BeforeMethod annotated launchBrowserAndLogin.


Viewing all articles
Browse latest Browse all 97806

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>