org.openqa.selenium.NoSuchSessionException: Session ID is null error

When i am trying to run my selenium tests the first test seem to work correctly but then i am recieving this error for the subsequent tests, Im after switching my tests over to an electron app so not sure if this is after causing a issue :

org.openqa.selenium.NoSuchSessionException: Session ID is null. Using WebDriver after calling quit()? Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'

My set up page is:

public class SetUp extends TestRail {
private static ChromeDriver browser;
public static String urlHost;
public static String testEnv;
public static PageConfig pageConfig;

public void initialBrowser() {

    if(browser == null) {

        String projectLocation = System.getProperty("user.dir");
        System.setProperty("", projectLocation + "/chromedriver.exe");

        ChromeOptions options = new ChromeOptions();
        System.setProperty("", "true");

        browser = new ChromeDriver(options);

        pageConfig = new PageConfig(browser);


//method: To get the url configs for the environment used to run the test
//@parameter: dev or test. demo doesn't not have a separate front end url
public void beforeTest(@NotNull final String env) throws Exception {
    testEnv = env;
    System.out.println("TEST ENVIRONMENT:  " + testEnv);
    switch (env){
        case "qa-84" :
            urlHost = "http://ukdc1-docker-mx:84/qa/#/login";
        case "qa-85":
            urlHost = "http://ukdc1-docker-mx:85/qa/#/login";
            throw new Exception("Incorrect environment passed");

//method to close the browser after every cucumber scenario

public void closeBrowser(Scenario scenario) throws IOException, APIException {
            TakesScreenshot screenshot = (TakesScreenshot)browser;
            File source = screenshot.getScreenshotAs(OutputType.FILE);
            FileUtils.copyFile(source, new File("logs/screenshots/" + scenario.getName() + ".png"));
            System.out.println("Screenshot taken");
        } catch (Exception e){
            System.out.println("Exception while taking screenshot " + e.getMessage());

public void writeResultToTestRail(Scenario scenario) throws IOException, APIException {
    String tesCaseID = new String();
    for(String s: scenario.getSourceTagNames()){
            int size = s.length();
            int startOfID = s.indexOf('"');
            tesCaseID = s.substring(startOfID + 1,size - 2);
        Map data = new HashMap();
            data.put("status_id", 5);
            data.put("comment", "Test Env: " + urlHost + "\n\n" + logError(scenario));
        }else {
            data.put("status_id", 1);
        postTestCaseStatus("add_result_for_case/","3914", tesCaseID, data);

protected void getTestCaseDetailsInConsole(String testCaseId) throws IOException, APIException {

private static String logError(Scenario scenario) {
    try {
        Class klass = ClassUtils.getClass("$ScenarioAdaptor" );
        Field fieldScenario = FieldUtils.getField(klass, "scenario", true);

        if (fieldScenario != null) {
            Object objectScenario = fieldScenario.get(scenario);

            Field fieldStepResults = objectScenario.getClass().getDeclaredField("stepResults" );

            ArrayList<Result> results = (ArrayList<Result>) fieldStepResults.get(objectScenario);
            for (Result result : results) {
                if (result.getError() != null) {
                    System.out.println(result.getError() + "\n\n" + result.getErrorMessage());
                    if(result.getErrorMessage().length() > 3100) {
                        return result.getErrorMessage().substring(0, 3100);
                    } else {
                        return result.getErrorMessage();
        return "Fetching error logs from the scenario ran into some issue, please check jenkins logs";
    } catch (IllegalAccessException | NoSuchFieldException | ClassNotFoundException e) {
        return e.getMessage();


And My Page config:

public class PageConfig {
public ChromeDriver browser;

public PageConfig(ChromeDriver browser){
    this.browser = browser;

//method: Get instance method can be called on any class, it helps to avoid to add a line every time a new PO is added to the project.
//@parameter: ClassName.class
//@example:  PageConfig.GetInstance(LoginPage.class).onLoginPage(); where onLoginPage is an method of 
public <TPage extends BasePage> TPage GetInstance (Class<TPage> pageClass){
    try {
        return initElements(browser, pageClass);
    }catch(Exception e){
        throw e;


Read more here:

Content Attribution

This content was originally published by user9686029 at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: