'How do I call a @Before method from my Hooks class, in TestRunner?

I am setting up an automated framework to run tests on Android emulators, using Appium. I have added logic to launch Appium and the emulator programatically, but would like to be able to edit the "launch settings" from the TestRunner class.

My ideal goal is to have everything I need in the TestRunner class, so I can run my tests against a specific port, emulator, and tags.

But currently with the method I have now, I am receiving the following error:

'Message: cucumber.runtime.CucumberException: Hooks must declare 0 or 1 arguments.'

@CucumberOptions(
        plugin = {"pretty", "html:target/cucumber-reports"}
        , monochrome = true
        , features = "src/test/java/feature"
        , tags = "@Login"
)

public class TestRunner {

    public void run() throws MalformedURLException, InterruptedException {
        setUpDriver(4723, "Android9");
    }
}

_________________________________________________________

public class Hooks extends DriverFactory {


    static AppiumDriverLocalService service;

    @Before
    public static void setUpDriver(int port, String simulator) throws InterruptedException {
        service = AppiumDriverLocalService
                .buildService(new AppiumServiceBuilder().usingPort(port)
                        .usingDriverExecutable(new File("path/to/node/file"))
                        .withAppiumJS(new File("/path/to/appium/file")));
        System.out.println("\n Appium server: " + service.getUrl());
        service.start();
        Thread.sleep(2000);

        try {
            setUpMobileDriver(simulator);
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
    }


Solution 1:[1]

You can pass from Maven or you can use System properties

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Arun Nair