Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get scenario name before driver instantiation? #3173

Closed
dragos-panzaru-md opened this issue Jun 28, 2023 · 7 comments
Closed

How to get scenario name before driver instantiation? #3173

dragos-panzaru-md opened this issue Jun 28, 2023 · 7 comments
Labels

Comments

@dragos-panzaru-md
Copy link

dragos-panzaru-md commented Jun 28, 2023

I have a custom driver implementation:
`

    String scenarioName = StepEventBus.getEventBus().getBaseStepListener().getCurrentTestOutcome().getName();

    String buildName = System.getProperty("buildName");

    try {

        MutableCapabilities caps = new MutableCapabilities();

        caps.setCapability("platformName", "Android");

        caps.setCapability("appium:platformVersion", "9");

        caps.setCapability("appium:newCommandTimeout", 90);

        caps.setCapability("appium:appiumVersion", "1.22.3");

        caps.setCapability("appium:deviceType", "phone");

        caps.setCapability("appium:deviceName", "^Samsung.*");

        caps.setCapability("appium:automationName", "UiAutomator2");

        caps.setCapability("appium:ignoreUnimportantViews", false);

        caps.setCapability("appium:app", "storage:APP_ID");

        MutableCapabilities sauceOptions = new MutableCapabilities();

        sauceOptions.setCapability("build", buildName);

        sauceOptions.setCapability("name", scenarioName);

        sauceOptions.setCapability("tunnelName", "tunnel");

        sauceOptions.setCapability("tunnelOwner", "SAUCE_USERNAME");

        sauceOptions.setCapability("phoneOnly", true);

        caps.setCapability("sauce:options", sauceOptions);

        return new AndroidDriver(new URL(<saucelabs_url>), caps);
  } catch (MalformedURLException e) {

        throw new Error(e);
    }`

The first line worked in serenity 3.2.5 and returned the title of the scenario that is under execution.
Now I am trying to upgrade serenity, cucumber and junit in order to be able to execute scenarios in parallel, not just features.
Currently, with serenity version 3.8.1 the line looks like this String scenarioName = StepEventBus.getParallelEventBus().getBaseStepListener().getCurrentTestOutcome().getName();
but the scenario name always returns "Test outcome unavailable"

@wakaleo
Copy link
Member

wakaleo commented Jun 28, 2023

In parallel execution, due to the nature of the event messages, this information is not available until the end of the scenario execution.

@dragos-panzaru-md
Copy link
Author

I understand. But in this case can I get at least the feature name? Otherwise what should I put in the "name" capability so that it makes sense when I look in the Saucelabs Dashboard when checking the test executions?

@wakaleo
Copy link
Member

wakaleo commented Jun 28, 2023

The JUnit 5 and Cucumber event logs make this extremely difficult in general. I don't recall if we found a solution - have a look at the current serenity-saucelabs and serenity-browserstack modules to see.

@dragos-panzaru-md
Copy link
Author

Thank you for the quick responses.

@dragos-panzaru-md
Copy link
Author

dragos-panzaru-md commented Jun 28, 2023

@wakaleo I found a quick solution looking into the serenity-saucelabs module:
if(TestSession.isSessionStarted()) { testName = TestSession.getTestSessionContext().getCurrentTestName(); }
Thanks again for your help.

@dragos-panzaru-md
Copy link
Author

@wakaleo Another thing I noticed is that the code that I have in a @BeforeAll hook is executed before driver instantiation if I use cucumber-junit 7.2.3, but if I upgrade to version 7.12.1 then the driver instantiation is done before the @BeforeAll hook. Is this normal?

@dragos-panzaru-md
Copy link
Author

Scratch that. After upgrade it was using the @BeforeAll annotation from Junit instead of the one from Cucumber. Not sure why this happened but with the one from Cucumber, then the code in the @BeforeAll method is executed before driver instantiation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants