org.openqa.selenium.remote.SessionNotFoundException: session null does not exist

5.9k Views Asked by At

I'm trying integrate selenium with spring. The code below works perfect if no spring dependencies added in pom.xml. but if I add spring boot dependency like below(I didn't add cucumber spring here and I removed all springcontext xml, cusumber xml from eclipse workspace) and run same test without modifying anything, It opens a IE test window http://localhost:36359/ then error out in console like below "org.openqa.selenium.remote.SessionNotFoundException: session null does not exist (WARNING: The server did not provide any stacktrace information)".

I even tried adding all spring annotation replacing @Before method by initizing webdriver in springcontext; but still the same behavior. can someone help me to fix this issue. I'm using selenium 3.4.0 version

<parent>
    <artifactId>spring-boot-starter-parent</artifactId>
    <groupId>org.springframework.boot</groupId>
    <version>1.4.3.RELEASE</version>
    <relativePath />
</parent>

public class ScenarioOutlineStepDef {
WebDriver driver;
@Before() 
public void setUp() {
    System.setProperty("webdriver.ie.driver", "C:/IEDriverServer-64.exe");
    DesiredCapabilities dc = new DesiredCapabilities();
    dc.setCapability(InternetExplorerDriver.ENABLE_PERSISTENT_HOVERING, false);
    dc.setCapability(InternetExplorerDriver.IE_ENSURE_CLEAN_SESSION, true);
    dc.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
    dc.setCapability(InternetExplorerDriver.NATIVE_EVENTS, false);
    dc.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);    
    dc.setJavascriptEnabled(true);
    dc.setBrowserName("internet explorer");
    driver = new InternetExplorerDriver(dc);
}

@Given("^user navigates to Pricing Portal$")
public void goToPricingPortal() {
    driver.navigate().to(
            "xyz.com;
}

@When("^I enter Username as \"([^\"]*)\" and Password as \"([^\"]*)\"$")
public void I_enter_Username_as_and_Password_as(String arg1, String arg2) {
    driver.findElement(By.id("txtUserDefault")).sendKeys(arg1);
    driver.findElement(By.id("txtPassDefault")).sendKeys(arg2);
    driver.findElement(By.cssSelector("input[type=\"submit\"]")).click();
}

@Then("^login should be unsuccessful$")
public void validateRelogin() {
    if (driver.getCurrentUrl().equalsIgnoreCase(
            "xyz.com")) {
        System.out.println("Test Pass");
    } else {
        System.out.println("Test Failed");
    }
    // driver.close();
}
1

There are 1 best solutions below

1
On

Do it manually

Set same Security level for all zones. Try this steps

  1. Open Internet Explorer Browser
  2. Go to menu and open Tools -> Internet Options -> Security
  3. Set all values of zones (Internet, Local intranet, Trusted sites, Restricted sites) to the same protected mode, enabled or disabled should not matter
  4. click on OK.

OR use DesiredCapabilities like this

DesiredCapabilities IEcaps = DesiredCapabilities.internetExplorer();
IEcaps .setCapability(
InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,
true);
File SrcFile= new File("E:\\Sankalp\\IE\\IEDriverServer.exe");
System.setProperty("webdriver.ie.driver", SrcFile.getAbsolutePath());
WebDriver driver = new InternetExplorerDriver(IEcaps );
driver.get("Your URL");
driver.quit();