0

i tried to run selenium tests created on windows machine. I change driver to linux version. Added it to PATH. But every time i got

org.selenium.NoSUchSessionException

i use latest browser with latest driver

I define driver it like that :

public class AuthTestSteps {
private static WebDriver driver;
private static WebDriverWait wait;
@Given("^blah_blah$")
public void method() throws MalformedURLException{

    driver = new ChromeDriver();
    wait = new WebDriverWait(driver, 30);
    System.setProperty("webdriver.chrome.driver","chromedriver");
}

Solution:

im my case solution was adding driver manager and options to chrome like "--no-sandbox", because it was run from root user.

Anton
  • 209
  • 2
  • 6
  • 15
  • 1
    Rather than edit the question to add the solution, post it as answer! [Answering your own question is not forbidden](https://meta.stackoverflow.com/a/250208/4733879), but [officially encouraged](https://stackoverflow.com/help/self-answer). (there is even an option to answer the question directly at the [Ask a Question](https://stackoverflow.com/questions/ask) page) – Filnor Mar 07 '18 at 09:21

2 Answers2

1

While executing Selenium Tests you need to pass the absolute path of the WebDriver binary first through System.setProperty() line then initialize the Web Browser as follows :

public class AuthTestSteps 
{
    private static WebDriver driver;

    @Given("^blah_blah$")
    public void method() throws MalformedURLException
    {

        System.setProperty("webdriver.chrome.driver","/path/to/chromedriver");
        driver = new ChromeDriver();
    }
}
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
0

Use absolute path of chrome driver. change your code like this.

public class AuthTestSteps {
private static WebDriver driver;
private static WebDriverWait wait;
@Given("^blah_blah$")
public void method() throws MalformedURLException{

    // assuming that your chrome driver is located inside
    // your project(src/main/resources/browser_driver/chromedriver)
    // take absolute path for chrome driver
    File file = new File("src/main/resources/browser_driver/chromedriver");
    String absolutePath = file.getAbsolutePath();

    driver = new ChromeDriver();
    wait = new WebDriverWait(driver, 30);
    System.setProperty("webdriver.chrome.driver", absolutePath);
}
jithinkmatthew
  • 890
  • 8
  • 17