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

Need to get the Session ID right after the WEB Driver initialise. #2752

Closed
despellhtb opened this issue Mar 22, 2022 · 1 comment
Closed

Comments

@despellhtb
Copy link

I want to get the Session ID right after the WEB Driver initialise.
The reason is I want to create a URL link with the Session ID.
To get the Session ID I am running this:
SessionId sessionId = ThucydidesWebDriverSupport.getSessionId();

What I have tried so far:

  1. Used serenity.extension.packages but seems like the event fires just before the WEB drive initialise itself. Both methods implemented seems like don't get the job done. (https://serenity-bdd.github.io/theserenitybook/latest/extending-webdriver.html)
  2. Using EventPublisher (Cucumber Plugins) also don't fit the scenario, because I want this to run both in console and when running a test VIA the IDE.

This of course can be implemented by outputting the Session ID before any test case, in any navigation for example and so on, but I want a more elegant solution.

Is there a way to fire an event when the WebDriver initialise itself? Also I want to avoid the Custom Web Driver thing.

@despellhtb
Copy link
Author

despellhtb commented Mar 22, 2022

Found the answer myself, so if anyone need this just do the following:

  1. Add your package with your method to serenity.conf file
    serenity.extension.packages=test.hooks

  2. Create the following class:

package test.hooks;

import net.serenitybdd.core.webdriver.enhancers.CustomDriverEnhancer;
import net.thucydides.core.util.EnvironmentVariables;
import org.openqa.selenium.*;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.remote.SessionId;

public class DriverListener implements CustomDriverEnhancer {

    @Override
    public void apply(EnvironmentVariables environmentVariables, WebDriver driver) {
        SessionId sessionID = ((RemoteWebDriver) driver).getSessionId();
        System.out.println(sessionID);
    }
}

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

No branches or pull requests

1 participant