Exception : Session ID is null. Using WebDriver after calling quit()?

67 Views Asked by At

I'm running my 6 scripts from local to sauce and partially my scripts are passing only .

Scenario 1 :- Passed
Scenario 2 :- Failed with Exception
Scenario 3 :- Passed
Scenario 4 :- Failed with Exception
Scenario 5 :- Passed
Scenario 6 :- Failed with Exception   

Though , running on my local machine , all scripts are getting passed . Using Cucumber Runner file to execute my scripts . I have seen multiple answers of this type of question where its asking to quit the driver in AFTER method . I did the same thing but still getting error .

**Code :-**
Before :-
                               ` try {
                    driver = new RemoteWebDriver(new URL(SAUCE_URL), options);
                } catch (MalformedURLException e) {
                    // TODO Auto-generated catch block
                    System.out.println("Exceptionnnnnnnnnnnnnnnnn"+e);
                    e.printStackTrace();
                }
                System.out.println("Remote Driver "+driver);
                driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
                if (System.getenv("JOB_NAME") != null) {
                    printSessionId(System.getenv("JOB_NAME"));
                } else {
                    printSessionId(jobName);
                }
                                String jobId = (((RemoteWebDriver) driver).getSessionId()).toString();
                PublicUrl = getPublicJobLink(jobId);
                System.out.println("Public Sauce URL >> " + PublicUrl);

....................................................................................................................................................................................................................................

@After
public void takescreenshot(Scenario scenario) throws Throwable {
    if (!Execution_mode.equalsIgnoreCase("API")) {
        tearDown(scenario);
        scenario.write("");
        // scenario.write(PublicUrl);
        String a = "";
        scenario.write(a);
    //  driver.close();
        driver.quit();
    }

}

Error with exception :-

org.openqa.selenium.NoSuchSessionException: Session ID is null. Using WebDriver after calling quit()?
Build info: version: '4.0.0-alpha-5', revision: 'b3a0d621cc'
System info: host: 'LHTU0GY36234T7Y', ip: '10.190.230.183', 
0

There are 0 best solutions below