0

I am trying to create a simple test, just open the page and verify its title. I thought it could not be simpler, but... my test opens a new tab in a currently opened Chrome browser and fails on driver.get(myUrl); with the org.openqa.selenium.NoSuchSessionException

I tried upgrading and downgrading chromedriver and upgrading downgrading selenium, but no luck so far. Currently I'm on selenium-java 3.3.1, chromedriver 2.28 and chrome 57.0.2987.98. Any help appreciated.

Bonus question, last time I used chromedriver it opened a new browser window, any way to get back to that? I'd prefer my tests in a new window instead of a new tab.

public class MyExampleTest {
    private String baseUrl;
    private WebDriver driver;

    @Before
    public void openBrowser() {
        baseUrl = "http://myurl/";
        System.setProperty("webdriver.chrome.driver", "C:\\Projects\\chromedriver.exe");
        driver = new ChromeDriver();
        driver.get(baseUrl);
    }

    @Test
    public void pageTitleAfterSearchShouldBeThere() throws IOException {
        assertEquals("The page title should be this at the start of the test.", "my title", driver.getTitle());
    }
}

Stacktrace:

org.openqa.selenium.NoSuchSessionException: no such session
  (Driver info: chromedriver=2.28.455520 (cc17746adff54984afff480136733114c6b3704b),platform=Windows NT 6.1.7601 SP1 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 13 milliseconds
Build info: version: '3.3.1', revision: '5234b325d5', time: '2017-03-10 09:10:29 +0000'
System info: host: 'XXXXXXXXXXXXXXX', ip: 'xxx.xxx.xxx.xx', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_121'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{message=unknown error: Chrome failed to start: crashed
  (Driver info: chromedriver=2.28.455520 (cc17746adff54984afff480136733114c6b3704b),platform=Windows NT 6.1.7601 SP1 x86_64), platform=ANY}]
Session ID: 359ce80c1b82e53fffae055451228404
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:216)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:168)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:638)
    at org.openqa.selenium.remote.RemoteWebDriver.get(RemoteWebDriver.java:325)
    at ec_selenium.CapExampleTest.openBrowser(CapExampleTest.java:58)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
tom
  • 1,223
  • 6
  • 16
  • 26

3 Answers3

0

Its because of the mismatch in chromedriver version and compatible webdriver version. Either change any one of it or take both latest. This worked for me!

0

You need to check the chrome driver download page https://chromedriver.chromium.org/downloads

which says it's compatibility... also, have a look here which has a list of compatible driver n browser https://stackoverflow.com/a/55266105/6305768

Dharman
  • 30,962
  • 25
  • 85
  • 135
  • 1
    When you are answering a question, First try to explain what is the problem they are facing. Just giving the download link to a 5 year old question is not good. This question already has an answer that says it is compatibility issue. You should have explained that the chromedriver is not compatible with the chrome version used on the first line. Then you should provide the link to download the appropriate version and compatibility link. There are many questions that need answer. Please answer to those and not to the old questions that already has a better explanation that yours. – S Ahmed Mar 11 '22 at 06:37
-1

You might have messed up with imports. Try the code below , working fine for me.

import static org.junit.Assert.assertEquals;

import java.io.IOException;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class MyExampleTest {
    private String baseUrl;
    private WebDriver driver;

    @Before
    public void openBrowser() {
        baseUrl = "http://facebook.com/";
        System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir")+"\\chromedriver.exe");
        driver = new ChromeDriver();
        driver.get(baseUrl);
        driver.manage().window().maximize();
    }

    @Test
    public void pageTitleAfterSearchShouldBeThere() throws IOException {
        System.out.println(driver.getTitle());
        assertEquals("The page title should be this at the start of the test.", "Facebook - Log In or Sign Up", driver.getTitle());
    }

    @After
    public void closeBrowser(){
        try{
        driver.quit();
        }catch(Exception e){
            System.out.println(e.getMessage());
        }
    }
}

This will open a new window everytime not a new tab in already opened chrome browser.

Anuj Teotia
  • 1,303
  • 1
  • 15
  • 21
  • Are you on the same version of selenium / chrome / chromedriver? For me your code throws NoSuchSession exception, also opens a new tab and not a new browser window. Same as mine above. – tom Apr 05 '17 at 10:15
  • Yes I have tried this on the versions you have mentioned in your question. – Anuj Teotia Apr 05 '17 at 10:55